File: signed_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 (47 lines) | stat: -rw-r--r-- 1,198 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'mail/part'
require 'mail/gpg/sign_part'

module Mail
  module Gpg

    class SignedPart < Mail::Part

      def self.build(cleartext_mail)
        new do
          if cleartext_mail.multipart?
            if cleartext_mail.content_type =~ /^(multipart[^;]+)/
              # preserve multipart/alternative etc
              content_type $1
            else
              content_type 'multipart/mixed'
            end
            cleartext_mail.body.parts.each do |p|
              add_part Mail::Gpg::SignedPart.build(p)
            end
          else
            content_type cleartext_mail.content_type
            if disposition = cleartext_mail.content_disposition
              content_disposition disposition
            end
            if id = cleartext_mail.header['Content-ID']
              content_id id
            end

            # brute force approach to avoid messed up line endings that break
            # signatures with Mail 2.7
            body Mail::Encodings::Base64.encode cleartext_mail.body.to_s
            body.encoding = 'base64'
          end
        end
      end

      def sign(options)
        SignPart.new(self, options)
      end


    end


  end
end