astrotrain 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'astrotrain'
16
- s.version = '0.6.1'
17
- s.date = '2012-04-13'
16
+ s.version = '0.6.2'
17
+ s.date = '2012-04-18'
18
18
  s.rubyforge_project = 'astrotrain'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -65,6 +65,7 @@ Gem::Specification.new do |s|
65
65
  test/fixtures/bad_email_format.txt
66
66
  test/fixtures/basic.txt
67
67
  test/fixtures/custom.txt
68
+ test/fixtures/email_in_body.txt
68
69
  test/fixtures/fwd.txt
69
70
  test/fixtures/gb2312_encoding.txt
70
71
  test/fixtures/gb2312_encoding_invalid.txt
@@ -1,5 +1,5 @@
1
1
  module Astrotrain
2
- VERSION = '0.6.1'
2
+ VERSION = '0.6.2'
3
3
 
4
4
  require 'utf8'
5
5
  require 'charlock_holmes'
@@ -21,7 +21,7 @@ module Astrotrain
21
21
  def self.deliver(message, destination, options = {})
22
22
  uri = Addressable::URI.parse(destination.to_s)
23
23
  klass = Transports.load(uri.scheme)
24
- klass.deliver(message, destination,
24
+ klass.deliver(message, destination,
25
25
  :recipient => options[:recipient],
26
26
  :extra => options[:payload])
27
27
  end
@@ -6,7 +6,7 @@ require 'set'
6
6
  module Astrotrain
7
7
  # Wrapper around a TMail object
8
8
  class Message
9
- EMAIL_REGEX = /[\w\.\_\%\+\-]+[^\.]@[\w\-\_\.]+/
9
+ EMAIL_REGEX = /[\w\.\_\%\+\-]+[^\s\.]@[\w\-\_\.]+/
10
10
 
11
11
  # Reference to the internal Mail object that parsed the raw email.
12
12
  attr_reader :mail
@@ -23,7 +23,8 @@ module Astrotrain
23
23
  x-original-to received)
24
24
 
25
25
  # This is the default order that Astrotrain will search for a matching
26
- # recipient.
26
+ # recipient. Set this to a different order. Add "body" to the list if
27
+ # you want to scan the body for email addresses with EMAIL_REGEX.
27
28
  self.recipient_header_order = %w(original_to delivered_to to)
28
29
 
29
30
  # Public: Parses the raw email headers into a Astrotrain::Message instance.
@@ -63,7 +64,6 @@ module Astrotrain
63
64
  def recipients(order = nil)
64
65
  if !@recipients.key?(order)
65
66
  order = self.class.recipient_header_order if order.blank?
66
- order.push :body
67
67
  recipients = []
68
68
 
69
69
  emails = order.inject([]) do |memo, key|
@@ -183,7 +183,9 @@ module Astrotrain
183
183
  def recipients_from_body
184
184
  @recipients_from_body ||= begin
185
185
  emails_from_body = body.scan(EMAIL_REGEX)
186
- address_list_for(emails_from_body)
186
+ address_list_for(emails_from_body, true)
187
+ rescue Mail::Field::ParseError
188
+ []
187
189
  end
188
190
  end
189
191
 
@@ -224,17 +226,22 @@ module Astrotrain
224
226
 
225
227
  # Uses Mail::AddressList to parse the given comma separated emails.
226
228
  #
227
- # emails - Array of String emails (foo@example.com, Bar <bar@example.com...)
229
+ # emails - Array of String email headers.
230
+ # Example: ["foo@example.com, Bar <bar@example.com>", ...]
228
231
  #
229
232
  # Returns Array of Mail::Address objects
230
- def address_list_for(emails)
233
+ def address_list_for(emails, retried = false)
231
234
  emails = emails * ", "
232
235
  list = Mail::AddressList.new(self.class.unescape(emails))
233
236
  addrs = list.addresses.each { |a| a.decoded }
234
237
  addrs.uniq!
235
238
  addrs
236
239
  rescue Mail::Field::ParseError
237
- address_list_for(emails.scan(EMAIL_REGEX))
240
+ if retried
241
+ raise
242
+ else
243
+ address_list_for(emails.scan(EMAIL_REGEX), true)
244
+ end
238
245
  end
239
246
 
240
247
  # Stolen from Rack/Camping, remove the "+" => " " translation
@@ -0,0 +1,19 @@
1
+ Delivered-To: "Processor" <processor@astrotrain.com>
2
+ Message-ID: <a16be7390810161014n52b603e9k1aa6bb803c6735aa@mail.gmail.com>
3
+ Received: by 10.231.149.194 with SMTP id u2mr924086ibv.32.1298067999839; Fri, 18 Feb 2011 14:26:39 -0800
4
+ Received: by 10.231.153.2 with HTTP; Fri, 18 Feb 2011 14:26:39 -0800
5
+ Date: Thu, 16 Oct 2008 10:14:18 -0700
6
+ From: Bob <user@example.com>
7
+ To: Processor <processor@astrotrain.com>
8
+ Cc: Fred <fred@example.com>
9
+ Subject: Fwd: blah blah
10
+ MIME-Version: 1.0
11
+ X-Custom: reply
12
+ Content-Type: text/plain; charset=ISO-8859-1
13
+ Content-Transfer-Encoding: 7bit
14
+ Content-Disposition: inline
15
+
16
+ ---------- Forwarded message ----------
17
+ booya. @technoweenie
18
+ foo@bar.com
19
+
@@ -124,7 +124,7 @@ class MessageParsingTest < Test::Unit::TestCase
124
124
  msg = astrotrain(:multiple_with_body_recipients)
125
125
 
126
126
  assert_equal %w(processor@astrotrain.com other@example.com processor+foobar@astrotrain.com processor+blah@astrotrain.com),
127
- msg.recipients
127
+ msg.recipients(Astrotrain::Message.recipient_header_order + %w(body))
128
128
  end
129
129
 
130
130
  test "with only HTML body in a multipart message" do
@@ -173,6 +173,11 @@ class MessageParsingTest < Test::Unit::TestCase
173
173
  assert_equal([], msg.recipients_from_to)
174
174
  end
175
175
 
176
+ test "parsing emails from body" do
177
+ msg = astrotrain :email_in_body
178
+ assert_equal %w(foo@bar.com), msg.recipients_from_body.map(&:address)
179
+ end
180
+
176
181
  test "saves path of parsed email" do
177
182
  path = mail(:basic)
178
183
  msg = Astrotrain::Message.read(path)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astrotrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-13 00:00:00.000000000 Z
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: utf8
16
- requirement: &70182998287440 !ruby/object:Gem::Requirement
16
+ requirement: &70356752937340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.1.8
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70182998287440
24
+ version_requirements: *70356752937340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mail
27
- requirement: &70182998286960 !ruby/object:Gem::Requirement
27
+ requirement: &70356752936700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.4.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70182998286960
35
+ version_requirements: *70356752936700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &70182998286480 !ruby/object:Gem::Requirement
38
+ requirement: &70356752936160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.6.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70182998286480
46
+ version_requirements: *70356752936160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday
49
- requirement: &70182998286000 !ruby/object:Gem::Requirement
49
+ requirement: &70356752935300 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.5.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70182998286000
57
+ version_requirements: *70356752935300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: addressable
60
- requirement: &70182998285520 !ruby/object:Gem::Requirement
60
+ requirement: &70356752934040 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.2.4
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70182998285520
68
+ version_requirements: *70356752934040
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: charlock_holmes
71
- requirement: &70182998285040 !ruby/object:Gem::Requirement
71
+ requirement: &70356752922600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.6.8
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70182998285040
79
+ version_requirements: *70356752922600
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: resque
82
- requirement: &70182998284660 !ruby/object:Gem::Requirement
82
+ requirement: &70356752919900 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70182998284660
90
+ version_requirements: *70356752919900
91
91
  description: email => http post
92
92
  email: technoweenie@gmail.com
93
93
  executables: []
@@ -108,6 +108,7 @@ files:
108
108
  - test/fixtures/bad_email_format.txt
109
109
  - test/fixtures/basic.txt
110
110
  - test/fixtures/custom.txt
111
+ - test/fixtures/email_in_body.txt
111
112
  - test/fixtures/fwd.txt
112
113
  - test/fixtures/gb2312_encoding.txt
113
114
  - test/fixtures/gb2312_encoding_invalid.txt
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  version: '0'
147
148
  requirements: []
148
149
  rubyforge_project: astrotrain
149
- rubygems_version: 1.8.11
150
+ rubygems_version: 1.8.10
150
151
  signing_key:
151
152
  specification_version: 2
152
153
  summary: email => http post