Module: EnMail::Helpers::RFC1847

Includes:
MessageManipulation
Included in:
Adapters::GPGME, Adapters::RNP, RFC3156
Defined in:
lib/enmail/helpers/rfc1847.rb

Overview

Common interface for building adapters conforming to RFC 1847 “Security Multiparts for MIME: Multipart/Signed and Multipart/Encrypted”. It provides sign and encrypt public methods.

Instance Method Summary collapse

Instance Method Details

#encrypt(message) ⇒ Object

Encrypts a message in a multipart/encrypted fashion as defined in RFC 1847.

Parameters:

  • message (Mail::Message)

    Message which is expected to be encrypted.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/enmail/helpers/rfc1847.rb', line 17

def encrypt(message)
  source_part = body_to_part(message)
  recipients = find_recipients_for(message)
  encrypted = encrypt_string(source_part.encoded, recipients).to_s
  encrypted_part = build_encrypted_part(encrypted)
  control_part = build_encryption_control_part

  rewrite_body(
    message,
    content_type: multipart_encrypted_content_type,
    parts: [control_part, encrypted_part],
  )
end

#sign(message) ⇒ Object

Signs a message in a multipart/signed fashion as defined in RFC 1847.

Parameters:

  • message (Mail::Message)

    Message which is expected to be signed.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/enmail/helpers/rfc1847.rb', line 35

def sign(message)
  source_part = body_to_part(message)
  restrict_encoding(source_part)
  signer = find_signer_for(message)
  micalg, signature = compute_signature(source_part.encoded, signer)
  signature_part = build_signature_part(signature)

  rewrite_body(
    message,
    content_type: multipart_signed_content_type(micalg: micalg),
    parts: [source_part, signature_part],
  )
end