29 |
29 |
imap = Net::IMAP.new(host, port, ssl)
|
30 |
30 |
imap.login(imap_options[:username], imap_options[:password]) unless imap_options[:username].nil?
|
31 |
31 |
imap.select(folder)
|
32 |
|
imap.search(['NOT', 'SEEN']).each do |message_id|
|
33 |
|
msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
|
34 |
|
logger.debug "Receiving message #{message_id}" if logger && logger.debug?
|
|
32 |
imap.uid_search(['NOT', 'SEEN']).each do |uid|
|
|
33 |
msg = imap.uid_fetch(uid,'RFC822')[0].attr['RFC822']
|
|
34 |
logger.debug "Receiving message #{uid}" if logger && logger.debug?
|
35 |
35 |
if MailHandler.receive(msg, options)
|
36 |
|
logger.debug "Message #{message_id} successfully received" if logger && logger.debug?
|
|
36 |
logger.debug "Message #{uid} successfully received" if logger && logger.debug?
|
37 |
37 |
if imap_options[:move_on_success]
|
38 |
|
imap.copy(message_id, imap_options[:move_on_success])
|
|
38 |
imap.uid_copy(uid, imap_options[:move_on_success])
|
39 |
39 |
end
|
40 |
|
imap.store(message_id, "+FLAGS", [:Seen, :Deleted])
|
|
40 |
imap.uid_store(uid, "+FLAGS", [:Seen, :Deleted])
|
41 |
41 |
else
|
42 |
|
logger.debug "Message #{message_id} can not be processed" if logger && logger.debug?
|
43 |
|
imap.store(message_id, "+FLAGS", [:Seen])
|
|
42 |
logger.debug "Message #{uid} can not be processed" if logger && logger.debug?
|
|
43 |
imap.uid_store(uid, "+FLAGS", [:Seen])
|
44 |
44 |
if imap_options[:move_on_failure]
|
45 |
|
imap.copy(message_id, imap_options[:move_on_failure])
|
46 |
|
imap.store(message_id, "+FLAGS", [:Deleted])
|
|
45 |
imap.uid_copy(uid, imap_options[:move_on_failure])
|
|
46 |
imap.uid_store(uid, "+FLAGS", [:Deleted])
|
47 |
47 |
end
|
48 |
48 |
end
|
49 |
49 |
end
|