Changeset 5e94bfb2a2639853b058404f7fd21601d0d9872d in for resourcetotrac
- Timestamp:
- 09/04/09 21:32:10 (3 years ago)
- Parents:
- 4e17a72f98bff34332fbca7853ac4aa7b854d997
- git-committer:
- John Hampton <pacopablo@pacopablo.com> / 2009-09-04T21:32:10Z-0700
- File:
-
- 1 edited
-
resourcetotrac/resourcetotrac/email/util.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
resourcetotrac/resourcetotrac/email/util.py
r4e17a72 r5e94bfb 11 11 12 12 # Standard Library Imports 13 import re 13 14 import email 14 15 from email.utils import parseaddr, getaddresses … … 23 24 'get_cc', 24 25 ] 26 27 field_boundaray_pattern(r'^-+$') 28 FIELD_BOUNDRY_RE = re.compile(field_boundary_pattern) 25 29 26 30 def strip_re(msg): … … 59 63 return [e[1] for e in getaddresses(msg.get_all('cc', []))] 60 64 65 def get_message_body(msg): 66 """ Returns the first `text/plain` message container. 67 68 If no `text/plain` messages are found, then it will return a `text/html` 69 message if one exists. If not, None is returned 70 """ 71 plain = html = None 72 for part in msg.walk(): 73 if part.get_content_maintype() == 'multipart': 74 continue 75 if part.get_content_maintype() == 'text': 76 if part.get_content_type() == 'text/plain': 77 plain = part 78 break 79 elif part.get_content_type() == 'text/html': 80 html = part 81 continue 82 return plain and plain or html 83 84 def get_field_changes(msg): 85 body = get_message_body(msg).get_payload() 86 lines = body.strip('\r\n').split('\r\n') 87 start_fields = end_fields = False 88 for linenum, line in enumerate(lines): 89 if FIELD_BOUNDARY_RE.match(line): 90 if isinstance(start_fields, int): 91 end_fields = linenum 92 break 93 else: 94 start_fields = linenum 95 continue 96 97 98 99 if line[0].startswith('IANAL'): 100 101
Note: See TracChangeset
for help on using the changeset viewer.
