File: encrypted_part.rb

package info (click to toggle)
ruby-mail-gpg 0.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 328 kB
  • sloc: ruby: 2,289; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 1,415 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Mail
  module Gpg
    class EncryptedPart < Mail::Part

      CONTENT_TYPE = 'application/octet-stream'

      # options are:
      #
      # :signers : sign using this key (give the corresponding email address)
      # :password: passphrase for the signing key
      # :recipients : array of receiver addresses
      # :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. If this option is given, strictly
      # only the key material from this hash is used, ignoring any keys for
      # recipients that might have been added to the local key chain but are
      # not mentioned here.
      # :always_trust : send encrypted mail to untrusted receivers, true by default
      # :filename : define a custom name for the encrypted file attachment
      def initialize(cleartext_mail, options = {})
        options = { always_trust: true }.merge options

        encrypted = GpgmeHelper.encrypt(cleartext_mail.encoded, options)
        super() do
          body encrypted.to_s
          filename = options[:filename] || 'encrypted.asc'
          content_type "#{CONTENT_TYPE}; name=\"#{filename}\""
          content_disposition "inline; filename=\"#{filename}\""
          content_description 'OpenPGP encrypted message'
        end
      end
    end
  end
end