Module: Mail::Gpg::MessagePatch

Defined in:
lib/mail/gpg/message_patch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
# File 'lib/mail/gpg/message_patch.rb', line 8

def self.included(base)
  base.class_eval do
    attr_accessor :raise_encryption_errors
    include VerifyResultAttribute
  end
end

Instance Method Details

#decrypt(options = {}) ⇒ Object

returns the decrypted mail object.

pass verify: true to verify signatures as well. The gpgme verification result will be available via decrypted_mail.verify_result



65
66
67
# File 'lib/mail/gpg/message_patch.rb', line 65

def decrypt(options = {})
  Mail::Gpg.decrypt(self, options)
end

#encrypted?Boolean

true if this mail is encrypted

Returns:

  • (Boolean)


57
58
59
# File 'lib/mail/gpg/message_patch.rb', line 57

def encrypted?
  Mail::Gpg.encrypted?(self)
end

#gpg(options = nil) ⇒ Object

turn on gpg encryption / set gpg options.

options are:

encrypt: encrypt the message. defaults to true sign: also sign the message. false by default sign_as: UIDs to sign the message with

See Mail::Gpg methods encrypt and sign for more possible options

mail.gpg encrypt: true mail.gpg encrypt: true, sign: true mail.gpg encrypt: true, sign_as: “[email protected]

future versions will also support sign-only mode: mail.gpg sign_as: ‘[email protected]’, encrypt: false

To turn off gpg encryption use: mail.gpg false



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mail/gpg/message_patch.rb', line 36

def gpg(options = nil)
  case options
  when nil
    @gpg
  when false
    @gpg = nil
    if Mail::Gpg::DeliveryHandler == delivery_handler
      self.delivery_handler = nil
    end
    nil
  end
  if options
    self.raise_encryption_errors = true if raise_encryption_errors.nil?
    @gpg = options
    self.delivery_handler ||= Mail::Gpg::DeliveryHandler
  else
    @gpg
  end
end

#signed?Boolean

true if this mail is signed (but not encrypted)

Returns:

  • (Boolean)


70
71
72
# File 'lib/mail/gpg/message_patch.rb', line 70

def signed?
  Mail::Gpg.signed?(self)
end

#verify(options = {}) ⇒ Object

verify signatures. returns a new mail object with signatures removed and populated verify_result.

verified = signed_mail.verify() verified.signature_valid? signers = mail.signatures.map{|sig| sig.from}



80
81
82
# File 'lib/mail/gpg/message_patch.rb', line 80

def verify(options = {})
  Mail::Gpg.verify(self, options)
end