Class: Mailman::Receiver::IMAP
- Inherits:
-
Object
- Object
- Mailman::Receiver::IMAP
- Defined in:
- lib/mailman/receiver/imap.rb
Overview
Receives messages using IMAP, and passes them to a MessageProcessor.
Instance Attribute Summary (collapse)
-
- (Net::IMAP) connection
readonly
The IMAP connection.
Instance Method Summary (collapse)
-
- (Object) connect
Connects to the IMAP server.
-
- (Object) disconnect
Disconnects from the IMAP server.
-
- (Object) get_messages
Iterates through new messages, passing them to the processor, and flagging them as done.
-
- (IMAP) initialize(options)
constructor
A new instance of IMAP.
Constructor Details
- (IMAP) initialize(options)
A new instance of IMAP
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mailman/receiver/imap.rb', line 24 def initialize() @processor = [:processor] @server = [:server] @username = [:username] @password = [:password] @filter = [:filter] || 'UNSEEN' @done_flags = [:done_flags] || [Net::IMAP::SEEN] @port = [:port] || 143 @ssl = [:ssl] || false @folder = [:folder] || "INBOX" end |
Instance Attribute Details
- (Net::IMAP) connection (readonly)
The IMAP connection
9 10 11 |
# File 'lib/mailman/receiver/imap.rb', line 9 def connection @connection end |
Instance Method Details
- (Object) connect
Connects to the IMAP server.
37 38 39 40 41 42 43 |
# File 'lib/mailman/receiver/imap.rb', line 37 def connect if @connection.nil? or @connection.disconnected? @connection = Net::IMAP.new(@server, @port, @ssl) @connection.login(@username, @password) end @connection.select(@folder) end |
- (Object) disconnect
Disconnects from the IMAP server.
46 47 48 49 |
# File 'lib/mailman/receiver/imap.rb', line 46 def disconnect @connection.logout @connection.disconnected? ? true : @connection.disconnect rescue nil end |
- (Object) get_messages
Iterates through new messages, passing them to the processor, and flagging them as done.
53 54 55 56 57 58 59 60 61 |
# File 'lib/mailman/receiver/imap.rb', line 53 def @connection.search(@filter).each do || body = @connection.fetch(, "RFC822")[0].attr["RFC822"] @processor.process(body) @connection.store(, "+FLAGS", @done_flags) end # Clears messages that have the Deleted flag set @connection.expunge end |