Package lamson :: Module bounce
[hide private]
[frames] | no frames]

Module bounce

source code

Bounce analysis module for Lamson. It uses an algorithm that tries to simply collect the headers that are most likely found in a bounce message, and then determine a probability based on what it finds.

Classes [hide private]
  BounceAnalyzer
BounceAnalyzer collects up the score and the headers and gives more meaningful interaction with them.
  bounce_to
Used to route bounce messages to a handler for either soft or hard bounces.
Functions [hide private]
 
match_bounce_headers(msg)
Goes through the headers in a potential bounce message recursively and collects all the answers for the usual bounce headers.
source code
 
detect(msg)
Given a message, this will calculate a probability score based on possible bounce headers it finds and return a lamson.bounce.BounceAnalyzer object for further analysis.
source code
Variables [hide private]
  BOUNCE_MATCHERS = {'Action': re.compile(r'(?is)(failed|delayed...
  BOUNCE_MAX = 16.0
  PRIMARY_STATUS_CODES = {u'1': u'Unknown Status Code 1', u'2': ...
  SECONDARY_STATUS_CODES = {u'0': u'Other or Undefined Status', ...
  COMBINED_STATUS_CODES = {u'00': u'Not Applicable', u'10': u'Ot...
  __package__ = 'lamson'
Function Details [hide private]

match_bounce_headers(msg)

source code 

Goes through the headers in a potential bounce message recursively and collects all the answers for the usual bounce headers.

detect(msg)

source code 

Given a message, this will calculate a probability score based on possible bounce headers it finds and return a lamson.bounce.BounceAnalyzer object for further analysis.

The detection algorithm is very simple but still accurate. For each header it finds it adds a point to the score. It then uses the regex in BOUNCE_MATCHERS to see if the value of that header is parseable, and if it is it adds another point to the score. The final probability is based on how many headers and matchers were found out of the total possible.

Finally, a header will be included in the score if it doesn't match in value, but it WILL NOT be included in the headers used by BounceAnalyzer to give you meanings like remote_mta and such.

Because this algorithm is very dumb, you are free to add to BOUNCE_MATCHERS in your boot files if there's special headers you need to detect in your own code.


Variables Details [hide private]

BOUNCE_MATCHERS

Value:
{'Action': re.compile(r'(?is)(failed|delayed|delivered|relayed|expande\
d)'),
 'Content-Description': re.compile(r'(?is)(Notification|Undelivered Me\
ssage|Delivery Report)'),
 'Diagnostic-Code': re.compile(r'(?is)(.+);\s*([0-9-\.]+)?\s*(.*)'),
 'Final-Recipient': re.compile(r'(?is)(.+);\s*(.*)'),
 'Received': re.compile(r'(?is)(.+)'),
 'Remote-Mta': re.compile(r'(?is)(.+);\s*(.*)'),
...

BOUNCE_MAX

Value:
16.0

PRIMARY_STATUS_CODES

Value:
{u'1': u'Unknown Status Code 1',
 u'2': u'Success',
 u'3': u'Temporary Failure',
 u'4': u'Persistent Transient Failure',
 u'5': u'Permanent Failure'}

SECONDARY_STATUS_CODES

Value:
{u'0': u'Other or Undefined Status',
 u'1': u'Addressing Status',
 u'2': u'Mailbox Status',
 u'3': u'Mail System Status',
 u'4': u'Network and Routing Status',
 u'5': u'Mail Delivery Protocol Status',
 u'6': u'Message Content or Media Status',
 u'7': u'Security or Policy Status'}

COMBINED_STATUS_CODES

Value:
{u'00': u'Not Applicable',
 u'10': u'Other address status',
 u'11': u'Bad destination mailbox address',
 u'12': u'Bad destination system address',
 u'13': u'Bad destination mailbox address syntax',
 u'14': u'Destination mailbox address ambiguous',
 u'15': u'Destination mailbox address valid',
 u'16': u'Mailbox has moved',
...

__package__

Value:
'lamson'