Module: EnMail::EnMailable

Included in:
Mail::Message
Defined in:
lib/enmail/enmailable.rb

Instance Method Summary collapse

Instance Method Details

#sign(passphrase: "", key: nil) ⇒ Object

Sign a message

This interface allow us to sign a message while using this gem, this also forecefully sets the ‘signable` status true, so it ensures that the specific message will be signed before sending out.

Parameters:

  • passphrase (String) (defaults to: "")

    the passphrase for the sign key

  • key (EnMail::Key) (defaults to: nil)

    the key model instance



12
13
14
15
16
17
18
# File 'lib/enmail/enmailable.rb', line 12

def sign(passphrase: "", key: nil)
  @key = key

  unless passphrase.empty?
    signing_key.passphrase = passphrase
  end
end

#signable?Boolean

Signing status

This returns the message signing status based on the user specified configuration and signing key. If the user enabled sign_message and provided a valid signing key then this will return true otherwise false, this can be used before trying to sing a message.

Returns:

  • (Boolean)


39
40
41
# File 'lib/enmail/enmailable.rb', line 39

def signable?
  signing_key.sign_key && EnMail.configuration.signable?
end

#signing_keyEnMail::Key

Signing key

This returns the signing key when applicable, the default signing key is configured through an initializer, but we are also allowing user to provide a custom key when they are invoking an interface.

Returns:



28
29
30
# File 'lib/enmail/enmailable.rb', line 28

def signing_key
  @key || EnMail.configuration.defualt_key
end