Revision 8551c132
Added by Marc Dequènes almost 16 years ago
- ID 8551c1322a8d174a7ffb2220e455673aa7dbfb89
lib/cyborghood/mail.rb | ||
---|---|---|
smtp_from = @mail.from_addrs.collect{|a| a.address}.join(", ")
|
||
smtp_to = @mail.to_addrs.collect{|a| a.address}
|
||
Net::SMTP.start(smtp_server, smtp_port) do |smtp|
|
||
#smtp.send_message(@mail.to_s, smtp_from, smtp_to)
|
||
p @mail.to_s
|
||
#p @mail.to_s
|
||
smtp.send_message(@mail.to_s, smtp_from, smtp_to)
|
||
end
|
||
end
|
||
|
||
... | ... | |
|
||
def crypt(fingerprint)
|
||
# build a fake mail to get the generated content to be crypted
|
||
# TODO: this is buggy yet
|
||
if @mail.multipart?
|
||
parts = @mail.parts
|
||
fake_mail = TMail::Mail.new
|
||
fake_mail.set_content_type("multipart", "mixed", {'boundary' => TMail.new_boundary})
|
||
@mail.each_part {|p| fake_mail.parts << p }
|
||
clear_data = fake_mail.to_s
|
||
else
|
||
# transform to multipart
|
||
single_part = TMail::Mail.new
|
||
single_part.content_type = @mail.content_type
|
||
single_part.body = @mail.body
|
||
single_part.transfer_encoding = @mail.transfer_encoding
|
||
parts = [single_part]
|
||
fake_mail = TMail::Mail.new
|
||
fake_mail.content_type = @mail.content_type
|
||
fake_mail.body = @mail.body
|
||
fake_mail.transfer_encoding = @mail.transfer_encoding if @mail.transfer_encoding
|
||
clear_data = fake_mail.to_s
|
||
end
|
||
fake_mail = TMail::Mail.new
|
||
fake_mail.set_content_type("multipart", "mixed", {'boundary' => TMail.new_boundary})
|
||
parts.each {|p| fake_mail.parts << p }
|
||
clear_data = fake_mail.to_s
|
||
# remove fake headers to get only generated parts
|
||
clear_data.sub!(/^.*\n\n/, "")
|
||
|
||
# retrieve key and encrypt
|
||
gpg = GPGME::Ctx.new
|
||
key = gpg.get_key(fingerprint)
|
||
p clear_data
|
||
encrypted_data = GPGME.encrypt([key], clear_data, {:armor => true, :always_trust => true})
|
||
|
||
# build properly encrypted mail
|
||
# (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.parts.clear
|
||
p_pgp = TMail::Mail.new
|
||
p_pgp.set_content_type("application", "pgp-encrypted")
|
||
p_pgp.body = "Version: 1"
|
||
@mail.parts << p_pgp
|
||
p_encrypted = TMail::Mail.new
|
||
p_encrypted.set_content_type("application", "octet-stream")
|
||
p_encrypted.body = encrypted_data
|
||
@mail.set_content_type("multipart", "encrypted", {'boundary' => TMail.new_boundary})
|
||
@mail.parts << p_pgp
|
||
@mail.parts << p_encrypted
|
||
end
|
||
end
|
Also available in: Unified diff
[evol] finished work on crypting mail response