Class: ImapFeeder

Inherits:
Object
  • Object
show all
Defined in:
lib/imap-feeder/version.rb,
lib/imap-feeder.rb

Overview

:nodoc:

Defined Under Namespace

Modules: VERSION

Instance Method Summary collapse

Constructor Details

#initialize(server, store, config) ⇒ ImapFeeder

Returns a new instance of ImapFeeder.



12
13
14
15
16
# File 'lib/imap-feeder.rb', line 12

def initialize(server, store, config)
  @server = server
  @store = store
  @config = config
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/imap-feeder.rb', line 18

def run
  $log.info "Started"
  feeds = YAML.load(@config)

  feeds.each do |feed|
    path = feed['feed']['path']
    $log.info "Processing #{path}"

    create_folder(path) unless check_folder_exists(path)

    begin
      url = feed['feed']['url']
      reader = FeedReader.new(url)
    rescue OpenURI::HTTPError => e
      $log.warn "Error retrieving #{url}: #{e.message}"
      next
    rescue Exception => e
      $log.error "Unexpected error while retrieving #{path}: #{e.message}"
      next
    end

    archive = get_archived(path)
    messages = reader.get_new(archive)

    unless messages.empty?
      $log.debug "already processed messages: '#{archive.join("', '")}'"
      send_messages(messages, path, reader.number_of_entries)
    end
  end

  $log.info "Finished"
end