Module: Mail::Gpg
- Defined in:
- lib/mail/gpg.rb,
lib/mail/gpg/version.rb,
lib/mail/gpg/version_part.rb,
lib/mail/gpg/message_patch.rb,
lib/mail/gpg/encrypted_part.rb,
lib/mail/gpg/delivery_handler.rb,
lib/mail/gpg/rails/action_mailer_base_patch.rb
Defined Under Namespace
Modules: MessagePatch, Rails Classes: DeliveryHandler, EncryptedPart, VersionPart
Constant Summary collapse
- VERSION =
"0.0.6"
Class Method Summary collapse
- .decrypt(encrypted_mail, options = {}) ⇒ Object
-
.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.
Class Method Details
.decrypt(encrypted_mail, options = {}) ⇒ Object
50 51 52 |
# File 'lib/mail/gpg.rb', line 50 def self.decrypt(encrypted_mail, = {}) # TODO :) 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mail/gpg.rb', line 21 def self.encrypt(cleartext_mail, = {}) 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 [:sign_as] [:sign] = true [:signers] = .delete(:sign_as) elsif [:sign] [:signers] = cleartext_mail.from end Mail.new do self.perform_deliveries = cleartext_mail.perform_deliveries %w(from to cc bcc subject reply_to in_reply_to).each do |field| send field, cleartext_mail.send(field) end cleartext_mail.header.fields.each do |field| header[field.name] = field.value if field.name =~ /^X-/ end add_part VersionPart.new add_part EncryptedPart.new(cleartext_mail, .merge({recipients: receivers})) content_type "multipart/encrypted; protocol=\"application/pgp-encrypted\"; boundary=#{boundary}" body.preamble = [:preamble] || "This is an OpenPGP/MIME encrypted message (RFC 2440 and 3156)" end end |