Show
Ignore:
Timestamp:
09/04/09 21:32:10 (3 years ago)
Author:
John Hampton <pacopablo@…>
Parents:
4e17a72f98bff34332fbca7853ac4aa7b854d997
git-committer:
John Hampton <pacopablo@pacopablo.com> / 2009-09-04T21:32:10Z-0700
Message:

More work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • resourcetotrac/resourcetotrac/email/util.py

    r4e17a72 r5e94bfb  
    1111 
    1212# Standard Library Imports 
     13import re 
    1314import email 
    1415from email.utils import parseaddr, getaddresses 
     
    2324    'get_cc', 
    2425] 
     26 
     27field_boundaray_pattern(r'^-+$') 
     28FIELD_BOUNDRY_RE = re.compile(field_boundary_pattern) 
    2529 
    2630def strip_re(msg): 
     
    5963    return [e[1] for e in getaddresses(msg.get_all('cc', []))] 
    6064 
     65def 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 
     84def 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.