Project

General

Profile

« Previous | Next » 

Revision 7193ea94

Added by Marc Dequènes almost 16 years ago

  • ID 7193ea94c804402239cc4e2ccc87113313b59733

[evol] send reply for properly signed message with bad content + ensure setting custom headers in all cases

View differences:

lib/cyborghood/mail.rb
if msg.nil?
@mail = TMail::Mail.new
set_custom_headers
else
# unquote headers and transform into TMail object
@mail = TMail::Mail.parse(TMail::Unquoter.unquote_and_convert_to(msg, "UTF-8"))
......
end
def parse
order = {:ok => false, :msg => "mail not formatted correctly"}
sig_check = verify_pgp_signature()
if sig_check.status == 0
logger.info "Mail content was properly signed by key #{sig_check.fingerprint}"
user = Person.find_by_fingerprint(sig_check.fingerprint)
if user.nil?
logger.info "Mail is from an unknown person"
order[:msg] = "unknown user"
else
logger.info "Mail is from user #{user.uid} (#{user.cn})"
......
commands << sline
end
return {:user => user, :commands => commands, :refs => refs}.to_ostruct
order = {:ok => true, :user => user, :commands => commands, :refs => refs}
else
logger.info "Mail does not contain a proper MIME part for commands"
end
end
else
logger.info "Mail content tampered or badly signed: " + sig_check.to_s
return nil
end
nil
order.to_ostruct
end
def create_reply
mail_reply = @mail.create_reply
mail_reply.from_addrs = TMail::Address.parse(@config.mail.from_address || self.to.first)
mail_reply['Organization'] = @config.mail.organization
self.class.new(mail_reply.to_s)
tmail_reply = @mail.create_reply
tmail_reply.from_addrs = TMail::Address.parse(@config.mail.from_address || self.to.first)
reply = self.class.new(tmail_reply.to_s)
reply.set_custom_headers
reply
end
def set_custom_headers
@mail['Organization'] = @config.mail.organization
end
def check_headers
......
# (modify original mail parts)
@mail.set_content_type("multipart", "encrypted", {'boundary' => TMail.new_boundary, "protocol" => "application/pgp-encrypted"})
@mail.transfer_encoding = nil
@mail.body = "This mail is a RFC3156 crypted message."
@mail.body = "This mail is a RFC3156 encrypted message."
@mail.parts.clear
p_pgp = TMail::Mail.new
p_pgp.set_content_type("application", "pgp-encrypted")
postman
next
end
logger.debug "Proper signed content detected"
logger.debug "Signed content detected"
begin
order = mail.parse
rescue CyberError => e
......
if order.nil?
logger.info "Mail is invalid, ignoring..."
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
next
end
result_list = CommandParser.run(order)

Also available in: Unified diff