Revision d5a19360
Added by Marc Dequènes about 15 years ago
- ID d5a1936012f558d396acd3cff82b7c9ba393dd53
lib/cyborghood/imap.rb | ||
---|---|---|
@params = params
|
||
end
|
||
|
||
class Message
|
||
def initialize(imap, message_id)
|
||
@imap = imap
|
||
@message_id = message_id
|
||
|
||
@content = nil
|
||
end
|
||
|
||
def content
|
||
return @content unless @content.nil?
|
||
|
||
data = @imap.fetch(@message_id, ["RFC822"])[0]
|
||
@content = data.attr["RFC822"]
|
||
end
|
||
|
||
def delete
|
||
@imap.store(@message_id, "+FLAGS", [:Deleted])
|
||
end
|
||
end
|
||
|
||
def check_mail
|
||
# using SSL because TLS does not work in the NET::IMAP library
|
||
ssl = (not @params.ca_cert.nil?)
|
||
... | ... | |
logger.debug "Examining INBOX"
|
||
|
||
imap.search(["ALL"], "UTF-8").each do |message_id|
|
||
data = imap.fetch(message_id, ["UID", "RFC822"])[0]
|
||
uid = data.attr["UID"]
|
||
logger.debug "*** Fetched mail ##{uid}"
|
||
msg = data.attr["RFC822"]
|
||
yield msg
|
||
logger.debug "*** Fetched mail ##{message_id}"
|
||
yield Message.new(imap, message_id)
|
||
end
|
||
|
||
imap.expunge
|
||
imap.logout
|
||
logger.debug "Disconnected from IMAP server"
|
||
rescue SocketError, Net::IMAP::Error => e
|
Also available in: Unified diff
[evol] improved IMAP message handling, and properly delete ignored or processed messages