Class Fetcher::Imap
In: vendor/plugins/fetcher/lib/fetcher/imap.rb
Parent: Base

Methods

Public Class methods

Additional Options:

  • :authentication - authentication type to use, defaults to PLAIN

[Source]

    # File vendor/plugins/fetcher/lib/fetcher/imap.rb, line 10
10:     def initialize(options={})
11:       @authentication = options.delete(:authentication) || 'PLAIN'
12:       super(options)
13:     end

Protected Instance methods

Delete messages and log out

[Source]

    # File vendor/plugins/fetcher/lib/fetcher/imap.rb, line 42
42:     def close_connection
43:       @connection.expunge
44:       @connection.logout
45:       @connection.disconnect
46:     end

Open connection and login to server

[Source]

    # File vendor/plugins/fetcher/lib/fetcher/imap.rb, line 16
16:     def establish_connection
17:       @connection = Net::IMAP.new(@server)
18:       @connection.authenticate(@authentication, @username, @password)
19:     end

Retrieve messages from server

[Source]

    # File vendor/plugins/fetcher/lib/fetcher/imap.rb, line 22
22:     def get_messages
23:       @connection.select('INBOX')
24:       @connection.search(['ALL']).each do |message_id|
25:         msg = @connection.fetch(message_id,'RFC822')[0].attr['RFC822']
26:         begin
27:           process_message(msg)
28:         rescue
29:           handle_bogus_message(msg)
30:         end
31:         # Mark message as deleted 
32:         @connection.store(message_id, "+FLAGS", [:Deleted])
33:       end
34:     end

Store the message for inspection if the receiver errors

[Source]

    # File vendor/plugins/fetcher/lib/fetcher/imap.rb, line 37
37:     def handle_bogus_message(message)
38:       @connection.append('bogus', message)
39:     end

[Validate]