enmail 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +0,0 @@
1
- module Mail::Secure
2
- class Key
3
-
4
- end
5
- end
@@ -1,107 +0,0 @@
1
- module Mail::Secure
2
-
3
- # Include this in your mailer class
4
- module PGPMailable
5
-
6
- require 'active_support/concern'
7
- extend ActiveSupport::Concern
8
-
9
- module InstanceMethods
10
-
11
- # TODO: extract this out for use on a lower level - i.e. not specific to
12
- # Rails / ActionMailer.
13
- # Boolean: true iff we want to enable signing of emails, false iff we
14
- # want to disable it.
15
- def sign_emails?
16
- # TODO: fetch from config
17
- end
18
-
19
- # TODO: extract this out for use on a lower level - i.e. not specific to
20
- # Rails / ActionMailer.
21
- # Has the following properties:
22
- # - email
23
- # - fingerprint
24
- # - user ids
25
- # - key body
26
- def active_key
27
- # TODO: fetch from config
28
- end
29
-
30
- # TODO: extract this out for use on a lower level - i.e. not specific to
31
- # Rails / ActionMailer.
32
- # Implement this!
33
- def key_url
34
- 'IMPLEMENT THIS'
35
- end
36
-
37
- # TODO: extract this out for use on a lower level - i.e. not specific to
38
- # Rails / ActionMailer.
39
- def add_pgp_headers(headers)
40
- return headers unless sign_emails? && active_key
41
-
42
- key_fingerprint = active_key.fingerprint
43
-
44
- headers.merge(
45
- gpg: {
46
- sign: true,
47
- sign_as: active_key.email,
48
- },
49
-
50
- # https://www.ietf.org/archive/id/draft-josefsson-openpgp-mailnews-header-07.txt
51
- 'X-PGP-Key': key_url,
52
- OpenPGP: {
53
- url: key_url,
54
- id: key_fingerprint,
55
- }.map{|k, v| "#{k}=#{v};"}.join(" ")
56
- )
57
-
58
- rescue StandardError => e
59
- if Rails.env.test?
60
- raise e
61
- end
62
- Rails.logger.error "[PGPMailable] Error unable to sign emails: #{e.message} #{e.backtrace}"
63
- headers
64
- end
65
-
66
- # NOTE: This can remain in PGPMailable because it's specific to
67
- # ActionMailer.
68
- def mail headers={}, &block
69
- # puts "what are headers? #{add_pgp_headers(headers).pretty_inspect}"
70
- super(add_pgp_headers(headers), &block).tap do |m|
71
- # puts m.to_s
72
- end
73
- end
74
-
75
- end
76
-
77
- included do
78
-
79
- def self.apply(base=self)
80
-
81
- # You can't use .prepend on ActionMailer::Base, oh no you can't!
82
- add_to = case base
83
- when ActionMailer::Base
84
- :include
85
- else :prepend
86
- end
87
-
88
- unless base < InstanceMethods
89
- self.send add_to, Mail::Gpg::Rails::ActionMailerPatch::InstanceMethods
90
- self.send add_to, InstanceMethods
91
- # self.singleton_class.send add_to, Mail::Gpg::Rails::ActionMailerPatch::ClassMethods
92
- end
93
- end
94
-
95
- apply
96
-
97
- # This would override the original .extended
98
- # def self.extended(base)
99
- # puts " sooo #{self}.extended #{base}"
100
- # apply base
101
- # super
102
- # end
103
-
104
- end
105
-
106
- end
107
- end