Project

General

Profile

« Previous | Next » 

Revision d5a19360

Added by Marc Dequènes about 15 years ago

  • ID d5a1936012f558d396acd3cff82b7c9ba393dd53

[evol] improved IMAP message handling, and properly delete ignored or processed messages

View differences:

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
postman
break
end
mail = Mail.new(msg)
mail = Mail.new(msg.content)
logger.info "Received mail with ID '#{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..."
msg.delete
next
end
......
end
if order.nil?
logger.info "Mail is invalid, ignoring..."
msg.delete
next
elsif not order.ok
mail_reply = mail.create_reply
mail_reply.quoted_printable_body = "A message (ID: #{mail.message_id}) apparently from you was rejected for the following reason:\n #{order.msg}"
mail_reply.deliver
msg.delete
next
end
result_list = CommandParser.run(order)
# create reply
mail_reply = mail.create_reply
reply_txt = "Hello #{order.user.cn},\n\nFollows the transcript of your commands:\n"
reply_attachments = []
......
end
mail_reply.crypt(order.user.keyFingerPrint)
mail_reply.deliver
msg.delete
end
end

Also available in: Unified diff