bounce_email 0.2.3 → 0.2.4

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: 9fe2e41f68b363d56e006effeefda2677e50efc2
4
- data.tar.gz: e49e1d1201f050555dd8698f501e24bb1e5d0c9f
3
+ metadata.gz: 55954008bef2210a6460404c920ccce94fdc4ae1
4
+ data.tar.gz: 1bd0ac6c90c0996cb20e10e32fa76f644cc6d01e
5
5
  SHA512:
6
- metadata.gz: dac46158c4ec4666b8a94a2c3cde4ae426e5865e52d8e9117356f04103fe569d551a363c912f21df6fd2358867892dd9b7d20725cc27acb7424d13e752b0bd1f
7
- data.tar.gz: 0fbffdd4385603a275a871f5e77471c7454364b5cc8e949869cc4300ae1aced6a0703637249c6d308db90eb2de6a8534cc93d7376e87c7958152103e004317cf
6
+ metadata.gz: afd0999f0c9f8f2fdf0685cc37492f5fa7c9655959fe81f9206f63ff3c06256860515203182bdbe0329dd774fd82e01f72f97568170b6d5c58a35b51710ab493
7
+ data.tar.gz: 8512ba0070b9110e4b4c16e977be338479ec63ef62ade88431dbf299fd3432262df9fc3f74aa69a3323dd4f6bd2b2749921f882ed858b9a1ea7743b9cf433786
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2.4
2
+
3
+ * Parse and reassign message-ID, to, from, and subject from original mail
4
+ (@saghaulor, livebg/bounce_email#5)
5
+
1
6
  ## 0.2.3
2
7
 
3
8
  * add support for Gmail bounces (@saghaulor, livebg/bounce_email#4)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/bounce_email.gemspec CHANGED
@@ -16,12 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- ["mail"].each do |gem|
20
- s.add_dependency *gem.split(' ')
21
- end
19
+ s.add_dependency 'mail'
22
20
 
23
- ["rake"].each do |gem|
24
- s.add_development_dependency *gem.split(' ')
25
- end
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'test-unit'if RUBY_VERSION >= '2.2.0'
26
23
  end
27
24
 
data/lib/bounce_email.rb CHANGED
@@ -219,11 +219,13 @@ module BounceEmail
219
219
  end
220
220
 
221
221
  def get_original_mail(mail) #worked alright for me, for sure this has to be extended
222
- if mail.multipart?
223
- ::Mail.new(mail.parts.last)
224
- elsif i = index_of_original_message_delimiter(mail)
225
- ::Mail.new(extract_original_message_after_delimiter(mail, i))
226
- end
222
+ original =
223
+ if mail.multipart?
224
+ ::Mail.new(mail.parts.last)
225
+ elsif i = index_of_original_message_delimiter(mail)
226
+ ::Mail.new(extract_original_message_after_delimiter(mail, i))
227
+ end
228
+ return extract_and_assign_fields_from_original_mail(original) if original
227
229
  rescue => e
228
230
  nil
229
231
  end
@@ -237,5 +239,27 @@ module BounceEmail
237
239
  message = mail.body.to_s.split(delimiter).last
238
240
  message.split(INLINE_MESSAGE_END_DELIMITER).first.strip if message.match(INLINE_MESSAGE_END_DELIMITER)
239
241
  end
242
+
243
+ def extract_and_assign_fields_from_original_mail(mail)
244
+ if mail.message_id.nil?
245
+ mail.add_message_id extract_field_from(mail, 'Message-ID:')
246
+ end
247
+
248
+ mail.from ||= extract_field_from(mail, 'From:')
249
+ mail.to ||= extract_field_from(mail, 'To:')
250
+ mail.subject ||= extract_field_from(mail, 'Subject:')
251
+
252
+ mail
253
+ end
254
+
255
+ def extract_field_from(mail, field_name)
256
+ lines = original_mail_body_lines(mail)
257
+ field = lines.detect { |line| line.match field_name }
258
+ field.split(':', 2).last.strip if field
259
+ end
260
+
261
+ def original_mail_body_lines(mail)
262
+ @original_mail_body_lines ||= mail.body.to_s.split(/(?:\r\n|\n)+/)
263
+ end
240
264
  end
241
265
  end
@@ -113,6 +113,9 @@ class BounceEmailTest < Test::Unit::TestCase
113
113
  mail = File.join(File.dirname(__FILE__), 'bounces', "tt_bounce_#{file}.txt")
114
114
  bounce = BounceEmail::Mail.new Mail.read(mail)
115
115
  assert_not_nil bounce.original_mail
116
+ assert_not_nil bounce.original_mail.message_id
117
+ assert_not_nil bounce.original_mail.to
118
+ assert_not_nil bounce.original_mail.from
116
119
  end
117
120
  end
118
121
 
@@ -127,9 +130,17 @@ class BounceEmailTest < Test::Unit::TestCase
127
130
  mail = File.join(File.dirname(__FILE__), 'bounces', "tt_bounce_#{file}.txt")
128
131
  bounce = BounceEmail::Mail.new Mail.read(mail)
129
132
  assert_not_nil bounce.original_mail
133
+ assert_not_nil bounce.original_mail.message_id
134
+ assert_not_nil bounce.original_mail.to
135
+ assert_not_nil bounce.original_mail.from
130
136
  end
131
137
  end
132
138
 
139
+ def test_original_message_with_subject
140
+ bounce = test_bounce('tt_bounce_04')
141
+ assert_not_nil bounce.original_mail.subject
142
+ end
143
+
133
144
  private
134
145
 
135
146
  def load_email(name, prefix = 'fixtures')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bounce_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Bielohlawek
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-04-01 00:00:00.000000000 Z
14
+ date: 2015-04-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: mail