~paulegan/flufl.bounce/caiwireless-bug-917720

« back to all changes in this revision

Viewing changes to flufl/bounce/docs/using.rst

  • Committer: Barry Warsaw
  • Date: 2012-01-04 16:39:36 UTC
  • Revision ID: barry@python.org-20120104163936-qrrd7ipqrprpxwvp
 * Port to Python 3 is mostly complete, however the test suite current fails
   because of <https://bugs.launchpad.net/zope.interface/+bug/911851>.  Once
   that bug is fixed in `zope.interface`, `flufl.bounce` should be Python 3.2
   compatible without the need for `2to3`.
 * All returned addresses are bytes objects in Python 3 and 8-bit strings in
   Python 2 (no change there).

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
In the most basic form of use, you can just pass an email message to the
16
16
top-level function, and get back a set of email addresses detected as
17
 
bouncing.  Here for example, is a simple DSN-like bounce message:
18
 
 
19
 
    >>> from email import message_from_string as parse
 
17
bouncing.
 
18
 
 
19
In Python 3, you should parse the message in binary (i.e. bytes) mode using
 
20
say `email.message_from_bytes()`.  You will get back a set of byte addresses.
 
21
In Python 2, both are 8-bit strings and you would use
 
22
`email.message_from_string()` to parse the message.
 
23
 
 
24
Here for example, is a simple DSN-like bounce message.  `parse()` is the
 
25
appropriate email parsing function described above.
 
26
 
20
27
    >>> msg = parse(b"""\
21
28
    ... From: Mail Delivery Subsystem <mailer-daemon@example.com>
22
29
    ... To: list-bounces@example.com
40
47
..
41
48
    >>> def print_emails(recipients):
42
49
    ...     if recipients is None:
43
 
    ...         print 'None'
 
50
    ...         print('None')
44
51
    ...         return
 
52
    ...     if len(recipients) == 0:
 
53
    ...         print('No addresses')
45
54
    ...     for email in sorted(recipients):
46
 
    ...         print email
 
55
    ...         print(email)
47
56
 
48
57
You can scan the bounce message object to get a set of all the email addresses
49
58
that have permanent failures.