bounce_email 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/HISTORY.md +17 -0
- data/Manifest.txt +11 -0
- data/PostInstall.txt +35 -0
- data/README.md +71 -0
- data/Rakefile +9 -0
- data/VERSION +1 -0
- data/bounce_email.gemspec +23 -0
- data/lib/bounce_email.rb +218 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/bounce_email_test.rb +113 -0
- data/test/bounces/malformed_bounce_01.txt +75 -0
- data/test/bounces/tt_1234175799.txt +73 -0
- data/test/bounces/tt_1234177688.txt +75 -0
- data/test/bounces/tt_1234210655.txt +105 -0
- data/test/bounces/tt_1234211357.txt +82 -0
- data/test/bounces/tt_1234211929.txt +89 -0
- data/test/bounces/tt_1234211931.txt +87 -0
- data/test/bounces/tt_1234211932.txt +77 -0
- data/test/bounces/tt_1234241665.txt +78 -0
- data/test/bounces/tt_1234285532.txt +80 -0
- data/test/bounces/tt_1234285668.txt +78 -0
- data/test/bounces/tt_bounce_01.txt +49 -0
- data/test/bounces/tt_bounce_02.txt +49 -0
- data/test/bounces/tt_bounce_03.txt +91 -0
- data/test/bounces/tt_bounce_04.txt +93 -0
- data/test/bounces/tt_bounce_05.txt +78 -0
- data/test/bounces/tt_bounce_06.txt +48 -0
- data/test/bounces/tt_bounce_07.txt +91 -0
- data/test/bounces/tt_bounce_08.txt +51 -0
- data/test/bounces/tt_bounce_09.txt +51 -0
- data/test/bounces/tt_bounce_10.txt +139 -0
- data/test/bounces/tt_bounce_11.txt +535 -0
- data/test/bounces/tt_bounce_12_soft.txt +46 -0
- data/test/bounces/tt_bounce_13.txt +648 -0
- data/test/bounces/tt_bounce_14.txt +596 -0
- data/test/bounces/tt_bounce_15.txt +137 -0
- data/test/bounces/tt_bounce_16.txt +99 -0
- data/test/bounces/tt_bounce_17.txt +61 -0
- data/test/bounces/tt_bounce_18.txt +99 -0
- data/test/bounces/tt_bounce_19.txt +45 -0
- data/test/bounces/tt_bounce_20.txt +43 -0
- data/test/bounces/tt_bounce_21.txt +65 -0
- data/test/bounces/tt_bounce_22.txt +49 -0
- data/test/bounces/tt_bounce_23.txt +133 -0
- data/test/bounces/tt_bounce_24.txt +297 -0
- data/test/bounces/tt_bounce_25.txt +67 -0
- data/test/bounces/unknown_code_bounce_01.txt +64 -0
- data/test/non_bounces/tt_1234210666.txt +40 -0
- data/test/non_bounces/tt_1234211024.txt +42 -0
- data/test/non_bounces/tt_1234241664.txt +22 -0
- data/test/test_helper.rb +7 -0
- metadata +178 -0
data/Gemfile
ADDED
data/HISTORY.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
## 0.1.1 2011-09-01
|
2
|
+
* extended #bounced? to consider error_status and diagnostic_code as well
|
3
|
+
* updated external gems
|
4
|
+
|
5
|
+
## 0.1.0 2011-05-27
|
6
|
+
|
7
|
+
* make use of bounce parsing in Mail gem
|
8
|
+
* renamed method to be compatible with Mail Gem
|
9
|
+
* more tests and cleanup
|
10
|
+
* forward message call to mail object if method is missing
|
11
|
+
* updated doc
|
12
|
+
* gemspec cleanup
|
13
|
+
|
14
|
+
## 0.0.1 2009-02-15
|
15
|
+
|
16
|
+
* 1 major enhancement:
|
17
|
+
* Initial release
|
data/Manifest.txt
ADDED
data/PostInstall.txt
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
For more information on bounce_email, see http://bounce-email.rubyforge.org
|
3
|
+
|
4
|
+
You can easily use this plugin with e.g. Rails application.
|
5
|
+
Configure rails, so it send email using postfix and it adds VERP.
|
6
|
+
#- in environment.rb file add lines -#
|
7
|
+
config.action_mailer.delivery_method = :sendmail
|
8
|
+
config.action_mailer.sendmail_settings = {
|
9
|
+
:location => '/usr/sbin/sendmail',
|
10
|
+
:arguments => '-XV -f bounces-main@amerimail.lv -i -t'
|
11
|
+
}
|
12
|
+
#- end -#
|
13
|
+
Change amerimail.lv to email server that will handle bounce emails.
|
14
|
+
|
15
|
+
Follow this tutorial to handle bounce-emails: http://keakaj.com/wisdom/2007/08/08/verp-on-rails/
|
16
|
+
|
17
|
+
You can make Ruby file like this:
|
18
|
+
require "rubygems"
|
19
|
+
require "mail"
|
20
|
+
require "bounce_email"
|
21
|
+
|
22
|
+
mail = Mail.new(STDIN.read)
|
23
|
+
bounce = BounceEmail::Mail.new(mail)
|
24
|
+
|
25
|
+
# Do something with bounce info
|
26
|
+
# bounce.isbounce -> true/false
|
27
|
+
# bounce.code -> e.g. "5.1.1"
|
28
|
+
# bounce.reason -> e.g. "Something about the address specified in the message caused this DSN."
|
29
|
+
# bounce.type -> e.g. "Permanent Failure"
|
30
|
+
|
31
|
+
# Permanent Failure means that it is hard bounce
|
32
|
+
# Persistent Transient Failure means that it is soft bounce
|
33
|
+
|
34
|
+
# If reason is "Vacation auto-reply" then email could be vacation email (but it is rearly cought).
|
35
|
+
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# bounce-email
|
2
|
+
|
3
|
+
This Ruby library is for determining the bounce type of an email message. It determines whether the bounce is hard or soft, if is an "out of office mail", etc.
|
4
|
+
|
5
|
+
## SYNOPSIS:
|
6
|
+
|
7
|
+
Follow this tutorial to handle bounce-emails: [http://keakaj.com/wisdom/2007/08/08/verp-on-rails](http://keakaj.com/wisdom/2007/08/08/verp-on-rails/)
|
8
|
+
|
9
|
+
Basic usage:
|
10
|
+
|
11
|
+
require "bounce_email"
|
12
|
+
|
13
|
+
bounce = BounceEmail::Mail.new(STDIN.read)
|
14
|
+
|
15
|
+
# Do something with bounce info
|
16
|
+
bounce.bounced? # true/false
|
17
|
+
bounce.code # e.g. "5.1.1"
|
18
|
+
bounce.reason # e.g. "Something about the address specified in the message caused this DSN."
|
19
|
+
bounce.type # "Permanent Failure", "Persistent Transient Failure", "Success" -- BounceEmail::TYPE_HARD_FAIL, TYPE_SOFT_FAIL, TYPE_SUCCESS
|
20
|
+
|
21
|
+
|
22
|
+
## REQUIREMENTS:
|
23
|
+
|
24
|
+
Ruby 1.9 & Ruby Gem Mail is required. The gem is used for primary bounce handling, which catches about 50% of all bounces.
|
25
|
+
For most other bounces, this gem comes in. See discussion here: [https://github.com/mikel/mail/issues/103](https://github.com/mikel/mail/issues/103)
|
26
|
+
|
27
|
+
## Other implementations:
|
28
|
+
|
29
|
+
* (PERL) [https://github.com/rjbs/mail-deliverystatus-bounceparser](https://github.com/rjbs/mail-deliverystatus-bounceparser)
|
30
|
+
|
31
|
+
|
32
|
+
## TODO:
|
33
|
+
|
34
|
+
* code cleanup!!! Oh yes!
|
35
|
+
* don't hardcode comparison strings, move to external file which can be extended easily
|
36
|
+
* more test: extend for more bounces
|
37
|
+
* is OUT of office type needed? if yes implement as optional part
|
38
|
+
* merge into Mail Gem??
|
39
|
+
|
40
|
+
## CONTRIBUTIONS:
|
41
|
+
|
42
|
+
Please fork on github & add new conditions under "get_status_from_text" if you discover creative new mailserver responses.
|
43
|
+
|
44
|
+
Updated by Pedro Visintin 2010
|
45
|
+
Updated by Tobias Bielohlawek 2011
|
46
|
+
|
47
|
+
|
48
|
+
## LICENSE:
|
49
|
+
|
50
|
+
(The MIT License)
|
51
|
+
|
52
|
+
Copyright (c) 2011 Tobias Bielohlawek, Agris Ameriks
|
53
|
+
|
54
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
55
|
+
a copy of this software and associated documentation files (the
|
56
|
+
'Software'), to deal in the Software without restriction, including
|
57
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
58
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
59
|
+
permit persons to whom the Software is furnished to do so, subject to
|
60
|
+
the following conditions:
|
61
|
+
|
62
|
+
The above copyright notice and this permission notice shall be
|
63
|
+
included in all copies or substantial portions of the Software.
|
64
|
+
|
65
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
66
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
67
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
68
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
69
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
70
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
71
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = %q{bounce_email}
|
6
|
+
s.version = File.read("VERSION").to_s
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Tobias Bielohlawek", "Agris Ameriks", "Pedro Visintin", "Dimitar Dimitrov"]
|
9
|
+
s.email = %q{tobi@rngtng.com}
|
10
|
+
s.homepage = %q{http://github.com/mitio/bounce_email}
|
11
|
+
s.summary = %q{Detect kind of bounced email}
|
12
|
+
s.description = %q{fork of whatcould/bounce-email incl. patches from wakiki, peterpunk, agowan & rngtng}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
["mail"].each do |gem|
|
20
|
+
s.add_dependency *gem.split(' ')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/lib/bounce_email.rb
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module BounceEmail
|
5
|
+
TYPE_HARD_FAIL = 'Permanent Failure'
|
6
|
+
TYPE_SOFT_FAIL = 'Persistent Transient Failure'
|
7
|
+
TYPE_SUCCESS = 'Success'
|
8
|
+
|
9
|
+
#qmail
|
10
|
+
# Status codes are defined in rfc3463, http://www.ietf.org/rfc/rfc3463.txt
|
11
|
+
# For code formatting, see http://www.ietf.org/rfc/rfc3463.txt
|
12
|
+
# Some Exchange servers format codes as "[...] #0.0.0>", see http://support.microsoft.com/kb/284204
|
13
|
+
|
14
|
+
# I used quite much from http://www.phpclasses.org/browse/package/2691.html
|
15
|
+
class Mail
|
16
|
+
def self.read(filename)
|
17
|
+
Mail.new( ::Mail.read(filename) )
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(mail)
|
21
|
+
@mail = mail.is_a?(String) ? ::Mail.new(mail) : mail
|
22
|
+
begin
|
23
|
+
if mail.bounced? #fall back to bounce handling in Mail gem
|
24
|
+
@bounced = true
|
25
|
+
@diagnostic_code = mail.diagnostic_code
|
26
|
+
@error_status = mail.error_status
|
27
|
+
end
|
28
|
+
rescue
|
29
|
+
@bounced = @diagnostic_code = @error_status = nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def bounced?
|
35
|
+
@bounced ||= check_if_bounce(@mail) || (diagnostic_code != "unknown") || (error_status != "unknown")
|
36
|
+
end
|
37
|
+
alias_method :is_bounce?, :bounced? #to stay backwards compatible
|
38
|
+
|
39
|
+
def diagnostic_code
|
40
|
+
@diagnostic_code ||= get_reason_from_status_code(code)
|
41
|
+
end
|
42
|
+
alias_method :reason, :diagnostic_code #to stay backwards compatible
|
43
|
+
|
44
|
+
def error_status
|
45
|
+
@error_status ||= get_code(@mail)
|
46
|
+
end
|
47
|
+
alias_method :code, :error_status #to stay backwards compatible
|
48
|
+
|
49
|
+
=begin #Streamline with Mail Gem methods - IMPLEMENT ME!
|
50
|
+
def final_recipien?
|
51
|
+
end
|
52
|
+
|
53
|
+
def action
|
54
|
+
end
|
55
|
+
|
56
|
+
def retryable?
|
57
|
+
end
|
58
|
+
=end
|
59
|
+
|
60
|
+
def type
|
61
|
+
@type ||= get_type_from_status_code(code)
|
62
|
+
end
|
63
|
+
|
64
|
+
def original_mail
|
65
|
+
@original_mail ||= get_original_mail(@mail)
|
66
|
+
end
|
67
|
+
|
68
|
+
def method_missing(m, *args)
|
69
|
+
@mail.send(m, *args)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def get_code(mail)
|
74
|
+
return '97' if mail.subject.match(/delayed/i)
|
75
|
+
return '98' if mail.subject.encode('utf-8').match(/(unzulässiger|unerlaubter) anhang/i)
|
76
|
+
return '99' if mail.subject.encode('utf-8').match(/auto.*reply|vacation|vocation|(out|away).*office|on holiday|abwesenheits|autorespond|Automatische|eingangsbestätigung/i)
|
77
|
+
|
78
|
+
if mail.parts[1]
|
79
|
+
match_parts = mail.parts[1].body.match(/(Status:.|550 |#)([245]\.[0-9]{1,3}\.[0-9]{1,3})/)
|
80
|
+
code = match_parts[2] if match_parts
|
81
|
+
return code if code
|
82
|
+
end
|
83
|
+
|
84
|
+
# Now try getting it from correct part of tmail
|
85
|
+
code = get_status_from_text(mail.body)
|
86
|
+
return code if code
|
87
|
+
|
88
|
+
# OK getting desperate so try getting code from entire email
|
89
|
+
code = get_status_from_text(mail.to_s)
|
90
|
+
code || 'unknown'
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_status_from_text(email)
|
94
|
+
#=begin
|
95
|
+
# This function is taken from PHP Bounce Handler class (http://www.phpclasses.org/browse/package/2691.html)
|
96
|
+
# Author: Chris Fortune
|
97
|
+
# Big thanks goes to him
|
98
|
+
# I transled them to Ruby and added some my parts
|
99
|
+
#=end
|
100
|
+
return "5.1.1" if email.match(/no such (address|user)|Recipient address rejected|User unknown|does not like recipient|The recipient was unavailable to take delivery of the message|Sorry, no mailbox here by that name|invalid address|unknown user|unknown local part|user not found|invalid recipient|failed after I sent the message|did not reach the following recipient|nicht zugestellt werden/i)
|
101
|
+
return "5.1.2" if email.match(/unrouteable mail domain|Esta casilla ha expirado por falta de uso|I couldn't find any host named/i)
|
102
|
+
if email.match(/mailbox is full|Mailbox quota (usage|disk) exceeded|quota exceeded|Over quota|User mailbox exceeds allowed size|Message rejected\. Not enough storage space|user has exhausted allowed storage space|too many messages on the server|mailbox is over quota|mailbox exceeds allowed size/i) # AA added 4th or
|
103
|
+
return "5.2.2" if email.match(/This is a permanent error/i) # AA added this
|
104
|
+
return "4.2.2"
|
105
|
+
end
|
106
|
+
return "5.1.0" if email.match(/Address rejected/)
|
107
|
+
return "4.1.2" if email.match(/I couldn't find any host by that name/)
|
108
|
+
return "4.2.0" if email.match(/not yet been delivered/i)
|
109
|
+
return "5.2.0" if email.match(/mailbox unavailable|No such mailbox/i)
|
110
|
+
return "5.4.4" if email.match(/Unrouteable address/i)
|
111
|
+
return "4.4.7" if email.match(/retry timeout exceeded/i)
|
112
|
+
return "5.2.0" if email.match(/The account or domain may not exist, they may be blacklisted, or missing the proper dns entries./i)
|
113
|
+
return "5.5.4" if email.match(/554 TRANSACTION FAILED/i)
|
114
|
+
return "4.4.1" if email.match(/Status: 4.4.1|delivery temporarily suspended|wasn't able to establish an SMTP connection/i)
|
115
|
+
return "5.5.0" if email.match(/550 OU\-002|Mail rejected by Windows Live Hotmail for policy reasons/i)
|
116
|
+
return "5.1.2" if email.match(/PERM_FAILURE: DNS Error: Domain name not found/i)
|
117
|
+
return "4.2.0" if email.match(/Delivery attempts will continue to be made for/i)
|
118
|
+
return "5.5.4" if email.match(/554 delivery error:/i)
|
119
|
+
return "5.1.1" if email.match(/550-5.1.1|This Gmail user does not exist/i)
|
120
|
+
return "5.7.1" if email.match(/5.7.1 Your message.*?was blocked by ROTA DNSBL/i) # AA added
|
121
|
+
return "5.3.2" if email.match(/Technical details of permanent failure|Too many bad recipients/i) && (email.match(/The recipient server did not accept our requests to connect/i) || email.match(/Connection was dropped by remote host/i) || email.match(/Could not initiate SMTP conversation/i)) # AA added
|
122
|
+
return "4.3.2" if email.match(/Technical details of temporary failure/i) && (email.match(/The recipient server did not accept our requests to connect/i) || email.match(/Connection was dropped by remote host/i) || email.match(/Could not initiate SMTP conversation/i)) # AA added
|
123
|
+
return "5.0.0" if email.match(/Delivery to the following recipient failed permanently/i) # AA added
|
124
|
+
return '5.2.3' if email.match(/account closed|account has been disabled or discontinued|mailbox not found|prohibited by administrator|access denied|account does not exist/i)
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_reason_from_status_code(code)
|
128
|
+
return 'unknown' if code.nil? or code == 'unknown'
|
129
|
+
array = {}
|
130
|
+
array['00'] = "Other undefined status is the only undefined error code. It should be used for all errors for which only the class of the error is known."
|
131
|
+
array['10'] = "Something about the address specified in the message caused this DSN."
|
132
|
+
array['11'] = "The mailbox specified in the address does not exist. For Internet mail names, this means the address portion to the left of the '@' sign is invalid. This code is only useful for permanent failures."
|
133
|
+
array['12'] = "The destination system specified in the address does not exist or is incapable of accepting mail. For Internet mail names, this means the address portion to the right of the @ is invalid for mail. This codes is only useful for permanent failures."
|
134
|
+
array['13'] = "The destination address was syntactically invalid. This can apply to any field in the address. This code is only useful for permanent failures."
|
135
|
+
array['14'] = "The mailbox address as specified matches one or more recipients on the destination system. This may result if a heuristic address mapping algorithm is used to map the specified address to a local mailbox name."
|
136
|
+
array['15'] = "This mailbox address as specified was valid. This status code should be used for positive delivery reports."
|
137
|
+
array['16'] = "The mailbox address provided was at one time valid, but mail is no longer being accepted for that address. This code is only useful for permanent failures."
|
138
|
+
array['17'] = "The sender's address was syntactically invalid. This can apply to any field in the address."
|
139
|
+
array['18'] = "The sender's system specified in the address does not exist or is incapable of accepting return mail. For domain names, this means the address portion to the right of the @ is invalid for mail. "
|
140
|
+
array['20'] = "The mailbox exists, but something about the destination mailbox has caused the sending of this DSN."
|
141
|
+
array['21'] = "The mailbox exists, but is not accepting messages. This may be a permanent error if the mailbox will never be re-enabled or a transient error if the mailbox is only temporarily disabled."
|
142
|
+
array['22'] = "The mailbox is full because the user has exceeded a per-mailbox administrative quota or physical capacity. The general semantics implies that the recipient can delete messages to make more space available. This code should be used as a persistent transient failure."
|
143
|
+
array['23'] = "A per-mailbox administrative message length limit has been exceeded. This status code should be used when the per-mailbox message length limit is less than the general system limit. This code should be used as a permanent failure."
|
144
|
+
array['24'] = "The mailbox is a mailing list address and the mailing list was unable to be expanded. This code may represent a permanent failure or a persistent transient failure. "
|
145
|
+
array['30'] = "The destination system exists and normally accepts mail, but something about the system has caused the generation of this DSN."
|
146
|
+
array['31'] = "Mail system storage has been exceeded. The general semantics imply that the individual recipient may not be able to delete material to make room for additional messages. This is useful only as a persistent transient error."
|
147
|
+
array['32'] = "The host on which the mailbox is resident is not accepting messages. Examples of such conditions include an immanent shutdown, excessive load, or system maintenance. This is useful for both permanent and permanent transient errors. "
|
148
|
+
array['33'] = "Selected features specified for the message are not supported by the destination system. This can occur in gateways when features from one domain cannot be mapped onto the supported feature in another."
|
149
|
+
array['34'] = "The message is larger than per-message size limit. This limit may either be for physical or administrative reasons. This is useful only as a permanent error."
|
150
|
+
array['35'] = "The system is not configured in a manner which will permit it to accept this message."
|
151
|
+
array['40'] = "Something went wrong with the networking, but it is not clear what the problem is, or the problem cannot be well expressed with any of the other provided detail codes."
|
152
|
+
array['41'] = "The outbound connection attempt was not answered, either because the remote system was busy, or otherwise unable to take a call. This is useful only as a persistent transient error."
|
153
|
+
array['42'] = "The outbound connection was established, but was otherwise unable to complete the message transaction, either because of time-out, or inadequate connection quality. This is useful only as a persistent transient error."
|
154
|
+
array['43'] = "The network system was unable to forward the message, because a directory server was unavailable. This is useful only as a persistent transient error. The inability to connect to an Internet DNS server is one example of the directory server failure error. "
|
155
|
+
array['44'] = "The mail system was unable to determine the next hop for the message because the necessary routing information was unavailable from the directory server. This is useful for both permanent and persistent transient errors. A DNS lookup returning only an SOA (Start of Administration) record for a domain name is one example of the unable to route error."
|
156
|
+
array['45'] = "The mail system was unable to deliver the message because the mail system was congested. This is useful only as a persistent transient error."
|
157
|
+
array['46'] = "A routing loop caused the message to be forwarded too many times, either because of incorrect routing tables or a user forwarding loop. This is useful only as a persistent transient error."
|
158
|
+
array['47'] = "The message was considered too old by the rejecting system, either because it remained on that host too long or because the time-to-live value specified by the sender of the message was exceeded. If possible, the code for the actual problem found when delivery was attempted should be returned rather than this code. This is useful only as a persistent transient error."
|
159
|
+
array['50'] = "Something was wrong with the protocol necessary to deliver the message to the next hop and the problem cannot be well expressed with any of the other provided detail codes."
|
160
|
+
array['51'] = "A mail transaction protocol command was issued which was either out of sequence or unsupported. This is useful only as a permanent error."
|
161
|
+
array['52'] = "A mail transaction protocol command was issued which could not be interpreted, either because the syntax was wrong or the command is unrecognized. This is useful only as a permanent error."
|
162
|
+
array['53'] = "More recipients were specified for the message than could have been delivered by the protocol. This error should normally result in the segmentation of the message into two, the remainder of the recipients to be delivered on a subsequent delivery attempt. It is included in this list in the event that such segmentation is not possible."
|
163
|
+
array['54'] = "A valid mail transaction protocol command was issued with invalid arguments, either because the arguments were out of range or represented unrecognized features. This is useful only as a permanent error. "
|
164
|
+
array['55'] = "A protocol version mis-match existed which could not be automatically resolved by the communicating parties."
|
165
|
+
array['60'] = "Something about the content of a message caused it to be considered undeliverable and the problem cannot be well expressed with any of the other provided detail codes. "
|
166
|
+
array['61'] = "The media of the message is not supported by either the delivery protocol or the next system in the forwarding path. This is useful only as a permanent error."
|
167
|
+
array['62'] = "The content of the message must be converted before it can be delivered and such conversion is not permitted. Such prohibitions may be the expression of the sender in the message itself or the policy of the sending host."
|
168
|
+
array['63'] = "The message content must be converted to be forwarded but such conversion is not possible or is not practical by a host in the forwarding path. This condition may result when an ESMTP gateway supports 8bit transport but is not able to downgrade the message to 7 bit as required for the next hop."
|
169
|
+
array['64'] = "This is a warning sent to the sender when message delivery was successfully but when the delivery required a conversion in which some data was lost. This may also be a permanant error if the sender has indicated that conversion with loss is prohibited for the message."
|
170
|
+
array['65'] = "A conversion was required but was unsuccessful. This may be useful as a permanent or persistent temporary notification."
|
171
|
+
array['70'] = "Something related to security caused the message to be returned, and the problem cannot be well expressed with any of the other provided detail codes. This status code may also be used when the condition cannot be further described because of security policies in force."
|
172
|
+
array['71'] = "The sender is not authorized to send to the destination. This can be the result of per-host or per-recipient filtering. This memo does not discuss the merits of any such filtering, but provides a mechanism to report such. This is useful only as a permanent error."
|
173
|
+
array['72'] = "The sender is not authorized to send a message to the intended mailing list. This is useful only as a permanent error."
|
174
|
+
array['73'] = "A conversion from one secure messaging protocol to another was required for delivery and such conversion was not possible. This is useful only as a permanent error. "
|
175
|
+
array['74'] = "A message contained security features such as secure authentication which could not be supported on the delivery protocol. This is useful only as a permanent error."
|
176
|
+
array['75'] = "A transport system otherwise authorized to validate or decrypt a message in transport was unable to do so because necessary information such as key was not available or such information was invalid."
|
177
|
+
array['76'] = "A transport system otherwise authorized to validate or decrypt a message was unable to do so because the necessary algorithm was not supported. "
|
178
|
+
array['77'] = "A transport system otherwise authorized to validate a message was unable to do so because the message was corrupted or altered. This may be useful as a permanent, transient persistent, or successful delivery code."
|
179
|
+
#custom codes
|
180
|
+
array['97'] = "Delayed"
|
181
|
+
array['98'] = "Not allowed Attachment"
|
182
|
+
array['99'] = "Vacation auto-reply"
|
183
|
+
code = code.gsub(/\./,'')[1..2]
|
184
|
+
array[code] || "unknown"
|
185
|
+
end
|
186
|
+
|
187
|
+
def get_type_from_status_code(code)
|
188
|
+
return TYPE_HARD_FAIL if code.nil? or code == 'unknown'
|
189
|
+
pre_code = code[0].chr.to_i
|
190
|
+
array = {}
|
191
|
+
array[5] = TYPE_HARD_FAIL
|
192
|
+
array[4] = TYPE_SOFT_FAIL
|
193
|
+
array[2] = TYPE_SUCCESS
|
194
|
+
return array[pre_code]
|
195
|
+
"Error"
|
196
|
+
end
|
197
|
+
|
198
|
+
def check_if_bounce(mail)
|
199
|
+
return true if mail.subject.match(/(returned|undelivered) mail|mail delivery( failed)?|(delivery )(status notification|failure)|failure notice|undeliver(able|ed)( mail)?|return(ing message|ed) to sender/i)
|
200
|
+
return true if mail.subject.match(/auto.*reply|vacation|vocation|(out|away).*office|on holiday|abwesenheits|autorespond|Automatische|eingangsbestätigung/i)
|
201
|
+
return true if mail['precedence'].to_s.match(/auto.*(reply|responder|antwort)/i)
|
202
|
+
return true if mail.from.to_s.match(/^(MAILER-DAEMON|POSTMASTER)\@/i)
|
203
|
+
false
|
204
|
+
end
|
205
|
+
|
206
|
+
def get_original_mail(mail) #worked alright for me, for sure this as to be extended
|
207
|
+
parts = mail.body.to_s.split(/--- Below this line is a copy of the message.(\r\n\r\n|\n\n)/)
|
208
|
+
if parts.size > 1
|
209
|
+
::Mail.new(parts.last)
|
210
|
+
elsif mail.parts
|
211
|
+
::Mail.new(mail.parts[2].body)
|
212
|
+
end
|
213
|
+
rescue => e
|
214
|
+
nil
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/bounce_email.rb'}"
|
9
|
+
puts "Loading bounce-email gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class BounceEmailTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_bounce_type_hard_fail
|
6
|
+
bounce = test_bounce('tt_bounce_01')
|
7
|
+
assert_equal '5.1.2', bounce.code, "Code should return 5.1.2, returns #{bounce.code}"
|
8
|
+
assert_equal BounceEmail::TYPE_HARD_FAIL, bounce.type
|
9
|
+
end
|
10
|
+
|
11
|
+
# Specific tests
|
12
|
+
def test_unrouteable_mail_domain
|
13
|
+
bounce = test_bounce('tt_bounce_01')
|
14
|
+
assert_equal '5.1.2', bounce.code, "Code should return 5.1.2, returns #{bounce.code}"
|
15
|
+
|
16
|
+
bounce = test_bounce('tt_bounce_02')
|
17
|
+
assert_equal '5.1.2', bounce.code, "Code should return 5.1.2, returns #{bounce.code}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_set_5_0_status
|
21
|
+
bounce = test_bounce('tt_bounce_03')
|
22
|
+
assert_equal '5.0.0', bounce.code, "Code should return 5.0.0, returns #{bounce.code}"
|
23
|
+
|
24
|
+
bounce = test_bounce('tt_bounce_04')
|
25
|
+
assert_equal '5.0.0', bounce.code, "Code should return 5.0.0, returns #{bounce.code}"
|
26
|
+
|
27
|
+
bounce = test_bounce('tt_bounce_05')
|
28
|
+
assert_equal '5.0.0', bounce.code, "Code should return 5.0.0, returns #{bounce.code}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_rota_dnsbl # TODO make this more general (match DNSBL only?)
|
32
|
+
bounce = test_bounce('tt_bounce_06')
|
33
|
+
assert_equal '5.7.1', bounce.code, "Code should return 5.7.1, returns #{bounce.code}"
|
34
|
+
end
|
35
|
+
|
36
|
+
# this test email suggests the library fails on this email;
|
37
|
+
# mail.part[0] includes a specific status code (5.1.1 User unknown)
|
38
|
+
# but the library tests mail.part[1], which returns the general code (5.0.0)
|
39
|
+
# either the test email is not a good example, or the parsing could be improved
|
40
|
+
def test_user_unknown
|
41
|
+
bounce = test_bounce('tt_bounce_07')
|
42
|
+
assert_equal '5.0.0', bounce.code
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_permanent_failure
|
46
|
+
bounce = test_bounce('tt_bounce_08')
|
47
|
+
assert_equal '5.3.2', bounce.code
|
48
|
+
|
49
|
+
bounce = test_bounce('tt_bounce_09')
|
50
|
+
assert_equal '5.3.2', bounce.code
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_bounce_type_soft_fail
|
54
|
+
bounce = test_bounce('tt_bounce_10')
|
55
|
+
assert_equal '4.0.0', bounce.code, "Code should return 4.0.0, returns #{bounce.code}"
|
56
|
+
assert_equal BounceEmail::TYPE_SOFT_FAIL, bounce.type
|
57
|
+
end
|
58
|
+
|
59
|
+
# Added because kept getting errors with malformed bounce messages
|
60
|
+
def test_malformed_bounce
|
61
|
+
bounce = test_bounce('malformed_bounce_01')
|
62
|
+
assert_equal '5.1.1', bounce.code
|
63
|
+
end
|
64
|
+
|
65
|
+
# Added because kept getting errors with unknown code messages
|
66
|
+
def test_unknown_code
|
67
|
+
bounce = test_bounce('unknown_code_bounce_01')
|
68
|
+
assert bounce.bounced?
|
69
|
+
assert_equal 'unknown', bounce.code
|
70
|
+
assert_equal BounceEmail::TYPE_HARD_FAIL, bounce.type
|
71
|
+
assert_equal 'unknown', bounce.reason
|
72
|
+
end
|
73
|
+
|
74
|
+
# test all other files
|
75
|
+
def test_all_bounces
|
76
|
+
path = File.join(File.dirname(__FILE__), 'bounces')
|
77
|
+
Dir[path + "/*.txt"].map do |file|
|
78
|
+
bounce = BounceEmail::Mail.new Mail.read(file)
|
79
|
+
assert bounce.bounced?, "#{file} failed"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_all_non_bounces
|
84
|
+
path = File.join(File.dirname(__FILE__), 'non_bounces')
|
85
|
+
Dir[path + "/*.txt"].map do |file|
|
86
|
+
non_bounce = BounceEmail::Mail.new Mail.read(file)
|
87
|
+
assert !non_bounce.bounced?, "#{file} failed"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def test_mail_methods_fallback
|
93
|
+
bounce = test_bounce('tt_bounce_10')
|
94
|
+
assert bounce.body
|
95
|
+
assert bounce.date
|
96
|
+
end
|
97
|
+
|
98
|
+
#Test mutlipart message from exchange
|
99
|
+
def test_multipart
|
100
|
+
bounce = test_bounce('tt_bounce_24')
|
101
|
+
assert bounce.bounced?
|
102
|
+
assert_equal BounceEmail::TYPE_HARD_FAIL, bounce.type
|
103
|
+
assert_not_nil bounce.original_mail
|
104
|
+
end
|
105
|
+
|
106
|
+
#Test regexp in when parsing the original email
|
107
|
+
def test_multipart
|
108
|
+
bounce = test_bounce('tt_bounce_25')
|
109
|
+
assert bounce.bounced?
|
110
|
+
assert_not_nil bounce.original_mail
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
Return-Path: <>
|
2
|
+
Received: by 10.216.28.198 with SMTP id g48cs228780wea; Wed, 16 Dec 2009 02:45:14 +0000
|
3
|
+
Received: ; Wed, 16 Dec 2009 02:41:20 +0000
|
4
|
+
Date: Wed, 16 Dec 2009 02:41:20 +0000
|
5
|
+
From: bounce@rediffmail.com
|
6
|
+
To: support@myswom.com
|
7
|
+
Message-Id: <4b2849b9.a813f30a.6c53.6801SMTPIN_ADDED@mx.google.com>
|
8
|
+
Subject: failure notice
|
9
|
+
Mime-Version: 1.0
|
10
|
+
Content-Type: multipart/mixed; boundary=mimepart_4b2849cc52ad8_16153fb6b5e769bc586b3
|
11
|
+
Authentication-Results: mx.google.com; spf=pass (google.com: domain of rediffmail.com designates 119.252.147.126 as permitted sender) smtp.mail=
|
12
|
+
Delivered-To: support@myswom.com
|
13
|
+
Received-Spf: pass (google.com: domain of rediffmail.com designates 119.252.147.126 as permitted sender) client-ip=119.252.147.126;
|
14
|
+
|
15
|
+
|
16
|
+
--mimepart_4b2849cc52ad8_16153fb6b5e769bc586b3
|
17
|
+
|
18
|
+
Hi. This is the qmail-send program at rediffmail.com.
|
19
|
+
I'm afraid I wasn't able to deliver your message to the following addresses.
|
20
|
+
This is a permanent error; I've given up. Sorry it didn't work out.
|
21
|
+
|
22
|
+
<mithlesh_pm@rediffmail.com>:
|
23
|
+
- Sorry, no mailbox here by that name. (#5.1.1)Z
|
24
|
+
|
25
|
+
--- Enclosed is a copy of the message.
|
26
|
+
|
27
|
+
|
28
|
+
--mimepart_4b2849cc52ad8_16153fb6b5e769bc586b3
|
29
|
+
Content-Type: message/rfc822
|
30
|
+
|
31
|
+
Return-Path: <support@myswom.com>
|
32
|
+
Received: (qmail 43430 invoked from network); 16 Dec 2009 02:41:20 -0000
|
33
|
+
X-CNFS-Analysis: score=0 v=1.0 c=1 a=UP0woeyT68oA:10 a=8sBYAydLBaTw9O9PPbvJRQ==:17 a=nOXXgcrqAAAA:8 a=hpnyz_ZHDEhns6bXdMYA:9 a=lOoBsn5VqPa6SSdm1A8A:7 a=n6XhW81lUO9q5u5E7SHj76VjDTMA:4 a=abhB7gKK_5kA:10 a=4phKvQ69a4IA:10
|
34
|
+
X-REDIFF-SENDER-VERIFY: D=-2, P=D
|
35
|
+
Received: from mail.swom.com (HELO xenon.swom.com) (188.40.35.30)
|
36
|
+
by 0 with SMTP; 16 Dec 2009 02:41:20 -0000
|
37
|
+
Received: from myswom.com (xenon.swom.com [188.40.35.28])
|
38
|
+
(Authenticated sender: support@myswom.com)
|
39
|
+
by xenon.swom.com (Postfix) with ESMTPSA id 64B392C60B
|
40
|
+
for <mithlesh_pm@rediffmail.com>; Wed, 16 Dec 2009 02:43:55 +0000 (GMT)
|
41
|
+
Date: Wed, 16 Dec 2009 02:43:55 +0000
|
42
|
+
From: Cash Culture <support@myswom.com>
|
43
|
+
To: mithlesh_pm@rediffmail.com
|
44
|
+
Message-Id: <4b28496b5a963_3adb3fc543c451b0910ee@xenon.swom.com.tmail>
|
45
|
+
Subject: Cash Culture added you as a friend on Swom...
|
46
|
+
Mime-Version: 1.0
|
47
|
+
Content-Type: text/plain; charset=utf-8
|
48
|
+
X-Swom-Uuid: 5c18dfcdfee13aa969f4c0c805e5ed0402b8f49b
|
49
|
+
|
50
|
+
Cash has joined Swom.com and indicated you are a Friend:
|
51
|
+
|
52
|
+
I'd like to add you to my wealth network on Swom.
|
53
|
+
|
54
|
+
We know each other from CashCulture a while ago.
|
55
|
+
|
56
|
+
- CashCulture
|
57
|
+
|
58
|
+
To accept or view this invitation from Cash Culture:
|
59
|
+
http://swom.com/c/7113/p/cdf64ba2/r/34007
|
60
|
+
|
61
|
+
|
62
|
+
What is Swom.com?
|
63
|
+
-------------------
|
64
|
+
|
65
|
+
Swom.com is the new social networking site for professionals and business owners.
|
66
|
+
|
67
|
+
It helps you make more money by rapidly expanding your wealth network and increasing your income.
|
68
|
+
|
69
|
+
It's free to join and it's growing fast.
|
70
|
+
|
71
|
+
|
72
|
+
The Swom.com Team
|
73
|
+
|
74
|
+
|
75
|
+
--mimepart_4b2849cc52ad8_16153fb6b5e769bc586b3--
|