mail-gpg 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  .ruby-version
2
- test/gpghome
3
2
  *.gem
4
3
  *.rbc
5
4
  .bundle
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ gemfile:
6
+ - gemfiles/rails3.gemfile
7
+ - gemfiles/rails4.gemfile
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.0.3 2013-08-20
2
+
3
+ * better ActionMailer integration
4
+ * 'gpg encrypt: true' instead of 'gpg true'
5
+ * test coverage
6
+
1
7
  == 0.0.2 2013-08-19
2
8
 
3
9
  * ActionMailer integration
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Mail::Gpg
1
+ # Mail::Gpg [![Build Status](https://travis-ci.org/jkraemer/mail-gpg.png?branch=master)](https://travis-ci.org/jkraemer/mail-gpg)
2
2
 
3
3
  This gem adds GPG/MIME encryption capabilities to the [Ruby Mail
4
4
  Library](https://github.com/mikel/mail)
@@ -32,19 +32,19 @@ with the gpg method:
32
32
  add_file "some_attachment.zip"
33
33
 
34
34
  # encrypt message, no signing
35
- gpg true
35
+ gpg encrypt: true
36
36
 
37
37
  # encrypt and sign message with sender's private key, using the given
38
38
  # passphrase to decrypt the key
39
- gpg sign: true, password: 'secret'
39
+ gpg encrypt: true, sign: true, password: 'secret'
40
40
 
41
41
  # encrypt and sign message using a different key
42
- gpg sign_as: 'joe@otherdomain.com', password: 'secret'
42
+ gpg encrypt: true, sign_as: 'joe@otherdomain.com', password: 'secret'
43
43
 
44
44
 
45
45
  # encrypt and sign message and use a callback function to provide the
46
46
  # passphrase.
47
- gpg sign_as: 'joe@otherdomain.com',
47
+ gpg encrypt: true, sign_as: 'joe@otherdomain.com',
48
48
  passphrase_callback: ->(obj, uid_hint, passphrase_info, prev_was_bad, fd){puts "Enter passphrase for #{passphrase_info}: "; (IO.for_fd(fd, 'w') << readline.chomp).flush }
49
49
  end.deliver
50
50
 
@@ -64,11 +64,11 @@ armored key data for recipients using the `:keys` option like this:
64
64
 
65
65
  Mail.new do
66
66
  to 'john@foo.bar'
67
- gpg keys: { 'john@foo.bar' => johns_key }
67
+ gpg encrypt: true, keys: { 'john@foo.bar' => johns_key }
68
68
  end
69
69
 
70
70
  The key will then be imported before actually trying to encrypt/send the mail.
71
- SoiIn theory you only need to specify the key once like that, however doing it
71
+ In theory you only need to specify the key once like that, however doing it
72
72
  every time does not hurt as gpg is clever enough to recognize known keys, only
73
73
  updating it's db when necessary.
74
74
 
@@ -85,7 +85,7 @@ This is not implemented yet
85
85
  class MyMailer < ActionMailer::Base
86
86
  default from: 'baz@bar.com'
87
87
  def some_mail
88
- mail to: 'foo@bar.com', subject: 'subject!', gpg: true
88
+ mail to: 'foo@bar.com', subject: 'subject!', gpg: { encrypt: true }
89
89
  end
90
90
  end
91
91
 
@@ -96,19 +96,19 @@ Mail::Message#gpg method.
96
96
 
97
97
  bundle exec rake
98
98
 
99
- The first run will take a while since it sets up a mock gpg home directory in
100
- `test/gpghome` containing two different identities used in the test cases.
101
- Following test runs will use that directory if it still exists and will
102
- therefore be substantially faster.
99
+ Test cases use a mock gpghome located in `test/gpghome` in order to not mess
100
+ around with your personal gpg keychain.
101
+
103
102
 
104
103
  ## Todo
105
104
 
106
105
  * Signing of unencrypted mails
107
- * Decryption
108
- * Signature verification
109
- * Add optional on the fly import of recipients' keys from public key servers based on email address
110
- * Send encrypted mails to recipients when possible, fall back to unencrypted
111
- mail otherwise
106
+ * Decryption and signature verification for received mails
107
+ * on the fly import of recipients' keys from public key servers based on email address or key id
108
+ * handle encryption errors due to missing keys - maybe return a list of failed
109
+ recipients
110
+ * add some setup code to help initialize a basic keychain directory with
111
+ public/private keypair.
112
112
 
113
113
 
114
114
  ## Contributing
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ gem 'mail', '~> 2.5.3'
6
+ gem 'gpgme', '~> 2.0.2'
7
+ gem 'actionmailer', '~> 3.2.14'
8
+
9
+ gem 'shoulda-context', '~> 1.1.5'
10
+
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ gem 'mail', '~> 2.5.3'
6
+ gem 'gpgme', '~> 2.0.2'
7
+ gem 'actionmailer', '~> 4.0.0'
8
+
9
+ gem 'shoulda-context', '~> 1.1.5'
10
+
11
+
@@ -6,12 +6,26 @@ module Mail
6
6
  if mail.gpg
7
7
  encrypted_mail = nil
8
8
  begin
9
- options = TrueClass === mail.gpg ? {} : mail.gpg
10
- encrypted_mail = Mail::Gpg.encrypt(mail, options)
9
+ options = TrueClass === mail.gpg ? { encrypt: true } : mail.gpg
10
+ if options.delete(:encrypt)
11
+ encrypted_mail = Mail::Gpg.encrypt(mail, options)
12
+ elsif options[:sign] || options[:sign_as]
13
+ raise "signing without encryption is not supported yet"
14
+ else
15
+ # encrypt and sign are off -> do not encrypt or sign
16
+ yield
17
+ end
11
18
  rescue Exception
12
19
  raise $! if mail.raise_encryption_errors
13
20
  end
14
- encrypted_mail.deliver if encrypted_mail
21
+ if encrypted_mail
22
+ if dm = mail.delivery_method
23
+ encrypted_mail.instance_variable_set :@delivery_method, dm
24
+ end
25
+ encrypted_mail.perform_deliveries = mail.perform_deliveries
26
+ encrypted_mail.raise_delivery_errors = mail.raise_delivery_errors
27
+ encrypted_mail.deliver
28
+ end
15
29
  else
16
30
  yield
17
31
  end
@@ -21,7 +21,11 @@ module Mail
21
21
  # See Mail::Gpg methods encrypt and sign for more
22
22
  # possible options
23
23
  #
24
- # mail.gpg true
24
+ # mail.gpg encrypt: true
25
+ # mail.gpg encrypt: true, sign: true
26
+ # mail.gpg encrypt: true, sign_as: "other_address@host.com"
27
+ #
28
+ # future versions will also support sign-only mode:
25
29
  # mail.gpg sign_as: 'jane@doe.com', encrypt: false
26
30
  #
27
31
  # To turn off gpg encryption use:
@@ -1,5 +1,5 @@
1
1
  module Mail
2
2
  module Gpg
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -5,7 +5,7 @@ module Mail
5
5
  class VersionPart < Mail::Part
6
6
  def initialize(*args)
7
7
  super
8
- body 'Version 1.0'
8
+ body 'Version: 1'
9
9
  content_type 'application/pgp-encrypted'
10
10
  content_description 'PGP/MIME Versions Identification'
11
11
  end
@@ -8,7 +8,7 @@ class MyMailer < ActionMailer::Base
8
8
  end
9
9
 
10
10
  def encrypted
11
- mail subject: 'encrypted', body: 'encrypted mail', gpg: true
11
+ mail subject: 'encrypted', body: 'encrypted mail', gpg: {encrypt: true}
12
12
  end
13
13
 
14
14
 
@@ -30,7 +30,7 @@ class ActionMailerTest < Test::Unit::TestCase
30
30
 
31
31
  should "send encrypted mail" do
32
32
  assert m = MyMailer.encrypted
33
- assert true == m.gpg
33
+ assert true == m.gpg[:encrypt]
34
34
  m.deliver
35
35
  assert_equal 1, @emails.size
36
36
  assert m = @emails.first
data/test/gpg_test.rb CHANGED
@@ -13,7 +13,7 @@ class GpgTest < Test::Unit::TestCase
13
13
  assert_equal 2, encrypted.parts.size
14
14
  v_part, enc_part = encrypted.parts
15
15
 
16
- assert_match /Version 1/, v_part.to_s
16
+ assert_match /Version: 1/, v_part.to_s
17
17
  assert_equal 'application/pgp-encrypted; charset=UTF-8', v_part.content_type
18
18
 
19
19
  assert_equal 'application/octet-stream; name=encrypted.asc',
Binary file
Binary file
Binary file
Binary file
Binary file
data/test/message_test.rb CHANGED
@@ -29,7 +29,7 @@ class MessageTest < Test::Unit::TestCase
29
29
 
30
30
  context "with gpg turned on" do
31
31
  setup do
32
- @mail.gpg true
32
+ @mail.gpg encrypt: true
33
33
  end
34
34
 
35
35
  context "with missing key" do
@@ -77,7 +77,7 @@ class MessageTest < Test::Unit::TestCase
77
77
 
78
78
  should "set and unset delivery_handler" do
79
79
  m = Mail.new do
80
- gpg true
80
+ gpg encrypt: true
81
81
  end
82
82
  assert m.gpg
83
83
  assert dh = m.delivery_handler
data/test/test_helper.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  require 'test/unit'
2
2
  require 'shoulda/context'
3
3
  require 'mail-gpg'
4
- require 'pry-nav'
5
4
  require 'action_mailer'
6
5
 
6
+ begin
7
+ require 'pry-nav'
8
+ rescue LoadError
9
+ end
10
+
7
11
  Mail.defaults do
8
12
  delivery_method :test
9
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail-gpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-19 00:00:00.000000000 Z
12
+ date: 2013-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mail
@@ -134,11 +134,14 @@ extensions: []
134
134
  extra_rdoc_files: []
135
135
  files:
136
136
  - .gitignore
137
+ - .travis.yml
137
138
  - Gemfile
138
139
  - History.txt
139
140
  - LICENSE.txt
140
141
  - README.md
141
142
  - Rakefile
143
+ - gemfiles/rails3.gemfile
144
+ - gemfiles/rails4.gemfile
142
145
  - lib/hkp.rb
143
146
  - lib/mail-gpg.rb
144
147
  - lib/mail/gpg.rb
@@ -152,6 +155,11 @@ files:
152
155
  - mail-gpg.gemspec
153
156
  - test/action_mailer_test.rb
154
157
  - test/gpg_test.rb
158
+ - test/gpghome/pubring.gpg
159
+ - test/gpghome/pubring.gpg~
160
+ - test/gpghome/random_seed
161
+ - test/gpghome/secring.gpg
162
+ - test/gpghome/trustdb.gpg
155
163
  - test/message_test.rb
156
164
  - test/test_helper.rb
157
165
  homepage: https://github.com/jkraemer/mail-gpg
@@ -182,5 +190,10 @@ summary: GPG/MIME encryption plugin for the Ruby Mail Library
182
190
  test_files:
183
191
  - test/action_mailer_test.rb
184
192
  - test/gpg_test.rb
193
+ - test/gpghome/pubring.gpg
194
+ - test/gpghome/pubring.gpg~
195
+ - test/gpghome/random_seed
196
+ - test/gpghome/secring.gpg
197
+ - test/gpghome/trustdb.gpg
185
198
  - test/message_test.rb
186
199
  - test/test_helper.rb