malone 1.0.5 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 801ac23610ff25c73bfee7491db4e6dd3579bb9d
4
- data.tar.gz: dee85dd144618ce9d31c6a68f3d1bd030cc7c950
3
+ metadata.gz: f4b3229ea37426d098ec276c2dd39d4ae51c4d82
4
+ data.tar.gz: 431a420d9f22ff479644b25ea934a680b96db326
5
5
  SHA512:
6
- metadata.gz: c4ffbd9bd6a2313c5955eef2af732b4af75b98d858e4ba1b282785c2fa8e7a2b98a98324519f39d2aea21ed3dcd853eae020342b2e8ce090ef95964de36ce6a8
7
- data.tar.gz: e3180d5b36efcd71c50550356ea0c7c5b56401b64a14e94887faef1b123046db20688de3da6c1a52f11c7da5988341e2fd4a1199fc92c9fee98c663efcb141a7
6
+ metadata.gz: 5d4f178cc9c09b5eaabbc99afb8450a7b7e8648dc0df33c2ad10adb6e4671f07b96ed597115b6d832de3b067ad2861a6ed4cc514d97a37edb910f20159cef028
7
+ data.tar.gz: 172b40dda19aebe92679fa3b961242dee49b66da5d33a056f79505130d595ba4f99e7fe9f57c092e22ccf876ca45e0dbf60d96305150ada58e996d1e7a311cb3
data/.gems ADDED
@@ -0,0 +1,2 @@
1
+ cutest -v 1.2.2
2
+ kuvert -v 0.0.1
@@ -0,0 +1 @@
1
+ /pkg
@@ -0,0 +1,4 @@
1
+ test: .PHONY
2
+ cutest test/*.rb
3
+
4
+ .PHONY:
@@ -1,5 +1,5 @@
1
1
  require "cgi"
2
- require "mailfactory"
2
+ require "kuvert"
3
3
  require "net/smtp"
4
4
  require "uri"
5
5
 
@@ -30,39 +30,37 @@ class Malone
30
30
 
31
31
  def deliver(dict)
32
32
  mail = envelope(dict)
33
+ yield mail if block_given?
33
34
 
34
35
  smtp = Net::SMTP.new(config.host, config.port)
35
- smtp.enable_starttls_auto if config.tls
36
+
37
+ if config.force_tls
38
+ smtp.enable_starttls
39
+ elsif config.tls
40
+ smtp.enable_starttls_auto
41
+ end
36
42
 
37
43
  begin
38
44
  smtp.start(config.domain, config.user, config.password, config.auth)
39
- smtp.send_message(mail.to_s, mail.from.first, *recipients(mail))
45
+ smtp.send_message(mail.to_s, mail.from.first, *mail.recipients)
40
46
  ensure
41
47
  smtp.finish if smtp.started?
42
48
  end
43
49
  end
44
50
 
45
- def recipients(mail)
46
- [].tap do |ret|
47
- ret.push(*mail.to)
48
- ret.push(*mail.cc)
49
- ret.push(*mail.bcc)
50
- end
51
- end
52
-
53
51
  def envelope(dict)
54
- envelope = Envelope.new
52
+ envelope = Kuvert.new
55
53
  envelope.from = dict[:from]
56
54
  envelope.to = dict[:to]
55
+ envelope.replyto = dict[:replyto]
57
56
  envelope.cc = dict[:cc] if dict[:cc]
58
57
  envelope.bcc = dict[:bcc] if dict[:bcc]
59
58
  envelope.text = dict[:text]
60
59
  envelope.rawhtml = dict[:html] if dict[:html]
61
60
  envelope.subject = dict[:subject]
62
61
 
63
- Array(dict[:attach]).each do |file|
64
- envelope.attach(file)
65
- end
62
+ envelope.attach(dict[:attach]) if dict[:attach]
63
+ envelope.add_attachment_as(*dict[:attach_as]) if dict[:attach_as]
66
64
 
67
65
  return envelope
68
66
  end
@@ -73,8 +71,9 @@ class Malone
73
71
  attr_accessor :user
74
72
  attr_accessor :password
75
73
  attr_accessor :domain
76
- attr_accessor :auth
77
74
  attr_accessor :tls
75
+ attr_accessor :force_tls
76
+ attr :auth
78
77
 
79
78
  def initialize(options)
80
79
  opts = options.dup
@@ -90,6 +89,14 @@ class Malone
90
89
  opts[:port] ||= uri.port.to_i
91
90
  opts[:user] ||= unescaped(uri.user)
92
91
  opts[:password] ||= unescaped(uri.password)
92
+
93
+ additional_opts = Hash[uri.query.to_s.split('&').map { |e| e.split('=')}]
94
+
95
+ if additional_opts.has_key?('force_tls')
96
+ @force_tls = true
97
+ elsif additional_opts.has_key?('tls')
98
+ @tls = true
99
+ end
93
100
  end
94
101
 
95
102
  opts.each do |key, val|
@@ -98,8 +105,7 @@ class Malone
98
105
  end
99
106
 
100
107
  def auth=(val)
101
- @auth = val
102
- @auth = @auth.to_sym if @auth
108
+ @auth = val && val.to_sym
103
109
  end
104
110
 
105
111
  private
@@ -109,18 +115,4 @@ class Malone
109
115
  CGI.unescape(val)
110
116
  end
111
117
  end
112
-
113
- class Envelope < MailFactory
114
- attr :bcc
115
-
116
- def initialize
117
- super
118
-
119
- @bcc = []
120
- end
121
-
122
- def bcc=(bcc)
123
- @bcc.push(bcc)
124
- end
125
- end
126
118
  end
@@ -5,6 +5,10 @@ class Malone
5
5
  @deliveries ||= []
6
6
  end
7
7
 
8
+ def self.reset_deliveries
9
+ @deliveries = nil
10
+ end
11
+
8
12
  def deliver(*args)
9
13
  self.class.deliveries << OpenStruct.new(*args)
10
14
  end
@@ -1,23 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'malone'
3
- s.version = "1.0.5"
4
- s.summary = %{Dead-simple Ruby mailing solution which always delivers.}
3
+ s.version = "1.2.1"
4
+ s.summary = %{The Mailman}
5
+ s.description = %{Dead-simple Ruby mailing solution which always delivers.}
5
6
  s.date = "2011-01-10"
6
7
  s.author = "Cyril David"
7
8
  s.email = "cyx@cyx.is"
8
9
  s.homepage = "http://github.com/cyx/malone"
9
-
10
- s.files = Dir[
11
- "CHANGELOG",
12
- "LICENSE",
13
- "README.md",
14
- "lib/**/*.rb",
15
- "test/*.*",
16
- "*.gemspec"
17
- ]
18
-
10
+ s.files = `git ls-files`.split("\n")
19
11
  s.require_paths = ["lib"]
20
12
 
21
- s.add_dependency "mailfactory", "~> 1.4"
22
- s.add_development_dependency "cutest"
13
+ s.add_dependency "kuvert", "~> 0.0"
14
+ s.add_development_dependency "cutest", "~> 1.2"
15
+ s.license = "MIT"
23
16
  end
@@ -89,13 +89,15 @@ test "#envelope" do
89
89
 
90
90
  mail = m.envelope(to: "recipient@me.com", from: "no-reply@mydomain.com",
91
91
  subject: "SUB", text: "TEXT", html: "<h1>TEXT</h1>",
92
- cc: "cc@me.com", bcc: "bcc@me.com")
92
+ cc: "cc@me.com", bcc: "bcc@me.com",
93
+ replyto: "other@me.com")
93
94
 
94
95
  assert_equal ["recipient@me.com"], mail.to
95
96
  assert_equal ["cc@me.com"], mail.cc
96
97
  assert_equal ["bcc@me.com"], mail.bcc
97
98
  assert_equal ["no-reply@mydomain.com"], mail.from
98
99
  assert_equal ["=?utf-8?Q?SUB?="], mail.subject
100
+ assert_equal "other@me.com", mail.replyto
99
101
 
100
102
  assert_equal "TEXT", mail.instance_variable_get(:@text)
101
103
  assert_equal "<h1>TEXT</h1>", mail.instance_variable_get(:@html)
@@ -184,6 +186,15 @@ scope do
184
186
  assert $smtp[:finish]
185
187
  end
186
188
 
189
+ test "adding custom headers" do |m|
190
+ m.deliver(to: "recipient@me.com", from: "no-reply@mydomain.com",
191
+ subject: "Happy new year!", text: "TEXT") do |mail|
192
+ mail.add_header("X-MC-SendAt", "2016-01-01 00:00:00")
193
+ end
194
+
195
+ assert $smtp[:blob].include?("X-MC-SendAt: 2016-01-01 00:00:00")
196
+ end
197
+
187
198
  test "calls #finish even when it fails during send_message" do |m|
188
199
  class FakeSMTP
189
200
  def send_message(*args)
@@ -219,3 +230,18 @@ test "sandbox" do
219
230
  assert_equal "TEXT", mail.text
220
231
  assert_equal "<h1>TEXT</h1>", mail.html
221
232
  end
233
+
234
+ test "resetting the test sandbox" do
235
+ require "malone/test"
236
+
237
+ m = Malone.connect
238
+
239
+ 2.times do
240
+ m.deliver(to: "recipient@me.com", from: "no-reply@mydomain.com",
241
+ subject: "SUB", text: "test")
242
+ end
243
+
244
+ assert 1 < Malone.deliveries.size
245
+ Malone.reset_deliveries
246
+ assert_equal 0, Malone.deliveries.size
247
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril David
@@ -11,49 +11,53 @@ cert_chain: []
11
11
  date: 2011-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: mailfactory
14
+ name: kuvert
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: '0.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
26
+ version: '0.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cutest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
41
- description:
40
+ version: '1.2'
41
+ description: Dead-simple Ruby mailing solution which always delivers.
42
42
  email: cyx@cyx.is
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - ".gems"
48
+ - ".gitignore"
47
49
  - CHANGELOG
48
50
  - LICENSE
51
+ - Makefile
49
52
  - README.md
50
- - lib/malone/test.rb
51
53
  - lib/malone.rb
54
+ - lib/malone/test.rb
55
+ - malone.gemspec
52
56
  - test/helper.rb
53
57
  - test/malone.rb
54
- - malone.gemspec
55
58
  homepage: http://github.com/cyx/malone
56
- licenses: []
59
+ licenses:
60
+ - MIT
57
61
  metadata: {}
58
62
  post_install_message:
59
63
  rdoc_options: []
@@ -61,18 +65,18 @@ require_paths:
61
65
  - lib
62
66
  required_ruby_version: !ruby/object:Gem::Requirement
63
67
  requirements:
64
- - - '>='
68
+ - - ">="
65
69
  - !ruby/object:Gem::Version
66
70
  version: '0'
67
71
  required_rubygems_version: !ruby/object:Gem::Requirement
68
72
  requirements:
69
- - - '>='
73
+ - - ">="
70
74
  - !ruby/object:Gem::Version
71
75
  version: '0'
72
76
  requirements: []
73
77
  rubyforge_project:
74
- rubygems_version: 2.0.3
78
+ rubygems_version: 2.5.2.3
75
79
  signing_key:
76
80
  specification_version: 4
77
- summary: Dead-simple Ruby mailing solution which always delivers.
81
+ summary: The Mailman
78
82
  test_files: []