Show
Ignore:
Timestamp:
05/05/09 12:57:54 (3 years ago)
Author:
John Hampton <pacopablo@…>
Children:
5e94bfb2a2639853b058404f7fd21601d0d9872d
Parents:
c8845e4129ccc08b18467b5028c93885c1aba213
git-committer:
John Hampton <pacopablo@pacopablo.com> / 2009-05-05T12:57:54Z-0700
Message:

Flushing out imap ticket submission

File:
1 edited

Legend:

Unmodified
Added
Removed
  • resourcetotrac/resourcetotrac/email/parsers/ticket.py

    rc8845e4 r4e17a72  
    1818from resourcetotrac.api import BaseParsedMessage 
    1919from resourcetotrac.email.api import IEmailTypeParser, IEmailResourceParser 
    20 from resourcetotrac.email.util import strip_re, get_author_email, get_cc 
     20from resourcetotrac.email.util import strip_re, get_author_email, get_cc, get_author 
    2121 
    2222__all__ = [ 
     
    2626 
    2727pattern = r'^(((?P<update>(re|RE|Re|rE)(:?[ ]*?))?\[(?P<project>.*?)] #(?P<id>\d+?): (?P<summary>.*))|([Tt][Ii][Cc][Kk][Ee][Tt]:?[ ]?(?P<newsummary>.*)))$' 
     28ip_pattern = r'^from .*? \(.*?\[(?P<serverip>.*?)]\)$' 
    2829TICKET_SUBJECT_RE = re.compile(pattern) 
     30TICKET_SERVER_IP_RE = re.compile(ip_pattern) 
    2931 
    3032class EmailTicketParser(Component) 
     
    5153        return resource_type.lower() == 'ticket' 
    5254 
    53     def parse_message(self, resource_type, msg): 
     55    def parse_message(self, resource_type, msg, options={}): 
    5456       """ Return an EmailTicketParsedMessage object """  
    5557        if resource_type.lower() != 'ticket': 
    5658            return BaseParsedMessage() 
    57         return EmailTicketParsedMessaage(msg) 
     59        return EmailTicketParsedMessaage(msg, options) 
    5860 
    5961class EmailTicketParsedMessage(BaseParsedMessage): 
    6062    """ Parse a ticket email """ 
    6163 
    62     def __init__(self, msg): 
     64    def __init__(self, msg, options): 
    6365        BaseParsedMessage.__init__(self, msg) 
    6466        match_groups = TICKET_SUBJECT_RE.match(msg['Subject']).groupdict() 
     
    6870        self.new = (not self.id) and match_groups['newsummary'] and True 
    6971        self.project_name = match_groups['project'] 
     72        self.server_hops = options['server_hops'] 
    7073 
    7174    def get_author(self): 
     
    7578    def get_ip(self): 
    7679        """ return the IP of the author. """ 
    77         return '0.0.0.0' 
     80        ips = [] 
     81        for l in msg.get_all('received', []): 
     82            l = l.split('\r\n')[0] 
     83            g = re.match(s, l) 
     84            ips.append(g and g.groupdict()['serverip'] or 'None') 
     85            continue 
     86        if self.server_hops > len(ips): 
     87            hops = -1 
     88        else: 
     89            hops = self.server_hops - 1 
     90        return ips[hops][0].isdigit() and ips[hops] or '0.0.0.0' 
    7891 
    7992    def get_id(self): 
    8093        """ Return the id of the resource """ 
    81         return '' 
     94        return self.id 
    8295 
    8396    def get_type(self): 
    8497        """ Return the type of resource """ 
    85         return 'unknown' 
     98        return 'ticket' 
    8699 
    87100    def get_data(self): 
     
    91104    def get_fields(self): 
    92105        """ Return a dictionary of {field: value} pairs for the resource """ 
     106        fields = { 
     107            'summary': self.summary, 
     108            'cc': get_cc(self.raw_message), 
     109        } 
     110        fields.update(get_field_changes(self.raw_message)) 
    93111        return {} 
    94112 
     
    98116        The options dictionary is specific to each resource type 
    99117        """ 
    100         return {} 
     118        options = { 
     119            'update': self.update 
     120        } 
     121        return options 
    101122 
    102123    def get_attachments(self): 
    103         """ Return a list of (filename, attachment) tuples """A 
     124        """ Return a list of (filename, attachment) tuples """ 
    104125        return [] 
    105126 
Note: See TracChangeset for help on using the changeset viewer.