Project

General

Profile

« Previous | Next » 

Revision 945de171

Added by Marc Dequènes almost 16 years ago

  • ID 945de1718898ba0630350fe9d1daf3b070b7f170

[evol] move IMAP code into a new class

View differences:

postman
#!/usr/bin/ruby -Ku
# http://www.ruby-doc.org/stdlib/libdoc/net/imap/rdoc/index.html
# http://tmail.rubyforge.org/reference/index.html
# http://tools.ietf.org/html/rfc3156
$: << "./lib"
......
end
def run
# using SSL because TLS does not work in the NET::IMAP library
#imap = Net::IMAP.new('imap.duckcorp.org', 993, true, "/etc/ssl/certs/duckcorp.crt", true)
imap = Net::IMAP.new('localhost')
logger.debug "Connected to IMAP server"
logger.debug "IMAP Capabilities: " + imap.capability.join(", ")
imap.authenticate('LOGIN', @config.imap.login, @config.imap.passwd)
logger.debug "Logged into IMAP account"
#p imap.getquotaroot("INBOX")
imap.select('INBOX')
imap.search(["ALL"], "UTF-8").each do |message_id|
msg = imap.fetch(message_id, "RFC822")[0].attr["RFC822"]
imap = IMAP.new(@config.imap)
imap.check_mail do |msg|
mail = Mail.new(msg)
logger.info "Mail #{mail.message_id}: #{mail.from_addrs} -> #{mail.to_addrs} (#{mail.subject})"
#logger.set_prefix()
logger.debug "######################################"
#logger.set_prefix("[#{mail.message_id}] ")
logger.info "New mail #{mail.message_id}: #{mail.from_addrs} -> #{mail.to_addrs} (#{mail.subject})"
# ignore mails not signed
unless mail.is_pgp_signed?
logger.info "Mail not signed or not RFC3156 compliant, ignoring..."
......
begin
order = mail.parse
rescue CyberError => e
logger.error "Internal processing error, skipping mail (#{e.message})"
next
case e.severity
when :dangerous
logger.fatal " (#{e.message})"
exit 2
when :unrecoverable
logger.error "Internal processing error, skipping mail (#{e.message})"
next
when :ignorable
end
end
if order.nil?
logger.info "Mail is invalid, ignoring..."
......
CommandParser.run(order)
end
imap.logout
end
def ask_to_stop

Also available in: Unified diff