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 +4 -4
- data/HISTORY.md +5 -0
- data/VERSION +1 -1
- data/bounce_email.gemspec +3 -6
- data/lib/bounce_email.rb +29 -5
- data/test/bounce_email_test.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55954008bef2210a6460404c920ccce94fdc4ae1
|
4
|
+
data.tar.gz: 1bd0ac6c90c0996cb20e10e32fa76f644cc6d01e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afd0999f0c9f8f2fdf0685cc37492f5fa7c9655959fe81f9206f63ff3c06256860515203182bdbe0329dd774fd82e01f72f97568170b6d5c58a35b51710ab493
|
7
|
+
data.tar.gz: 8512ba0070b9110e4b4c16e977be338479ec63ef62ade88431dbf299fd3432262df9fc3f74aa69a3323dd4f6bd2b2749921f882ed858b9a1ea7743b9cf433786
|
data/HISTORY.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
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
|
-
|
20
|
-
s.add_dependency *gem.split(' ')
|
21
|
-
end
|
19
|
+
s.add_dependency 'mail'
|
22
20
|
|
23
|
-
|
24
|
-
|
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
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
data/test/bounce_email_test.rb
CHANGED
@@ -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.
|
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-
|
14
|
+
date: 2015-04-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: mail
|