Sha256: 2dd63ef7e77c8fcc894935adc7b0c81533234246689bff41f0ace3ca8df1fe57
Contents?: true
Size: 1.77 KB
Versions: 6
Compression:
Stored size: 1.77 KB
Contents
require 'net/imap' module MList module EmailServer class Imap < Base def initialize(settings) super(settings) end def deliver(tmail) raise "Mail delivery is not presently supported by the Imap server. Please use the '#{MList::EmailServer::Default.name}' type." end def execute begin connect process_folders ensure disconnect end end def archive_message_id(id) @imap.copy(id, settings[:archive_folder]) @imap.store(id, '+FLAGS', [:Deleted]) end def connect @imap = Net::IMAP.new( settings[:server], settings[:port], settings[:ssl] ) @imap.login(settings[:username], settings[:password]) end def disconnect @imap.disconnect if @imap && !@imap.disconnected? end def process_folders Array(settings[:source_folders]).each do |folder| process_folder(folder) end end def process_folder(folder) @imap.select(folder) @imap.search(['NOT','DELETED']).each do |message_id| process_message_id(message_id) archive_message_id(message_id) end @imap.close end def process_message_id(id) if rfc822 = @imap.fetch(id, 'RFC822') content = rfc822[0].attr['RFC822'] process_message(content) elsif settings[:failure_folder] begin @imap.move(id, settings[:failure_folder]) rescue Net::IMAP::NoResponseError @imap.create(settings[:failure_folder]) retry end end end def process_message(content) receive(TMail::Mail.parse(content)) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems