Module: Mail::Gpg
- Defined in:
- lib/mail/gpg.rb,
lib/mail/gpg/version.rb,
lib/mail/gpg/sign_part.rb,
lib/mail/gpg/gpgme_helper.rb,
lib/mail/gpg/version_part.rb,
lib/mail/gpg/message_patch.rb,
lib/mail/gpg/decrypted_part.rb,
lib/mail/gpg/encrypted_part.rb,
lib/mail/gpg/delivery_handler.rb,
lib/mail/gpg/inline_decrypted_message.rb,
lib/mail/gpg/rails/action_mailer_base_patch.rb
Defined Under Namespace
Modules: MessagePatch, Rails
Classes: DecryptedPart, DeliveryHandler, EncryptedPart, GpgmeHelper, InlineDecryptedMessage, SignPart, VersionPart
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.decrypt(encrypted_mail, options = {}) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/mail/gpg.rb', line 58
def self.decrypt(encrypted_mail, options = {})
if encrypted_mime?(encrypted_mail)
decrypt_pgp_mime(encrypted_mail, options)
elsif encrypted_inline?(encrypted_mail)
decrypt_pgp_inline(encrypted_mail, options)
else
raise EncodingError, "Unsupported encryption format '#{encrypted_mail.content_type}'"
end
end
|
.encrypt(cleartext_mail, options = {}) ⇒ Object
options are: :sign : sign message using the sender’s private key :sign_as : sign using this key (give the corresponding email address) :passphrase: passphrase for the signing key :keys : A hash mapping recipient email addresses to public keys or public key ids. Imports any keys given here that are not already part of the local keychain before sending the mail. :always_trust : send encrypted mail to untrusted receivers, true by default
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/mail/gpg.rb', line 25
def self.encrypt(cleartext_mail, options = {})
construct_mail(cleartext_mail, options) do
receivers = []
receivers += cleartext_mail.to if cleartext_mail.to
receivers += cleartext_mail.cc if cleartext_mail.cc
receivers += cleartext_mail.bcc if cleartext_mail.bcc
if options[:sign_as]
options[:sign] = true
options[:signers] = options.delete(:sign_as)
elsif options[:sign]
options[:signers] = cleartext_mail.from
end
add_part VersionPart.new
add_part EncryptedPart.new(cleartext_mail,
options.merge({recipients: receivers}))
content_type "multipart/encrypted; protocol=\"application/pgp-encrypted\"; boundary=#{boundary}"
body.preamble = options[:preamble] || "This is an OpenPGP/MIME encrypted message (RFC 2440 and 3156)"
end
end
|
.encrypted?(mail) ⇒ Boolean
68
69
70
71
72
|
# File 'lib/mail/gpg.rb', line 68
def self.encrypted?(mail)
return true if encrypted_mime?(mail)
return true if encrypted_inline?(mail)
false
end
|
.sign(cleartext_mail, options = {}) ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/mail/gpg.rb', line 47
def self.sign(cleartext_mail, options = {})
construct_mail(cleartext_mail, options) do
options[:sign_as] ||= cleartext_mail.from
add_part SignPart.new(cleartext_mail, options)
add_part Mail::Part.new(cleartext_mail)
content_type "multipart/signed; micalg=pgp-sha1; protocol=\"application/pgp-signature\"; boundary=#{boundary}"
body.preamble = options[:preamble] || "This is an OpenPGP/MIME signed message (RFC 4880 and 3156)"
end
end
|