Revision 960c259e
Added by Marc Dequènes over 15 years ago
- ID 960c259e23a88e40cbcfd210fbc8cc052eb7bb5a
lib/cyborghood/mail.rb | ||
---|---|---|
end
|
||
|
||
def parse
|
||
return parse_signed() if is_pgp_signed?
|
||
return parse_encrypted() if is_pgp_encrypted?
|
||
{:ok => false, :msg => "mail not RFC3156 compliant"}.to_ostruct
|
||
end
|
||
|
||
def parse_signed
|
||
order = {:ok => false, :msg => "mail not formatted correctly"}
|
||
|
||
sig_check = verify_pgp_signature()
|
||
... | ... | |
order.to_ostruct
|
||
end
|
||
|
||
def parse_encrypted
|
||
order = {:ok => false, :msg => "mail not formatted correctly"}
|
||
|
||
catch :notforme do
|
||
begin
|
||
# block is not passed to delegate (limitation ?)
|
||
clear_message = @mail.decrypt do |uid_hint, passphrase_info, prev_was_bad|
|
||
logger.info "Mail crypted for #{uid_hint}"
|
||
|
||
# check if requesting passphrase for the expected key
|
||
key_id = passphrase_info.split(" ")[1]
|
||
throw :notforme if key_id != @config.mail.key_id[-(key_id.size)..-1]
|
||
|
||
# sending key
|
||
@config.mail.key_passphrase
|
||
end
|
||
|
||
# create a fake mail and chain parsing operations
|
||
clear_mail = self.class.new(clear_message)
|
||
return clear_mail.parse
|
||
rescue GPGME::Error, NotImplementedError => e
|
||
raise CyberError.new(:unrecoverable, "protocol/mail", e.message)
|
||
end
|
||
end
|
||
|
||
order.to_ostruct
|
||
end
|
||
|
||
def create_reply
|
||
tmail_reply = @mail.create_reply
|
||
tmail_reply.from_addrs = TMail::Address.parse(@config.mail.from_address || self.to.first)
|
Also available in: Unified diff
[evol] handle incoming encrypted messages