Changeset 4e17a72f98bff34332fbca7853ac4aa7b854d997 in for resourcetotrac/resourcetotrac/email/parsers/ticket.py
- Timestamp:
- 05/05/09 12:57:54 (3 years ago)
- Children:
- 5e94bfb2a2639853b058404f7fd21601d0d9872d
- Parents:
- c8845e4129ccc08b18467b5028c93885c1aba213
- git-committer:
- John Hampton <pacopablo@pacopablo.com> / 2009-05-05T12:57:54Z-0700
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
resourcetotrac/resourcetotrac/email/parsers/ticket.py
rc8845e4 r4e17a72 18 18 from resourcetotrac.api import BaseParsedMessage 19 19 from resourcetotrac.email.api import IEmailTypeParser, IEmailResourceParser 20 from resourcetotrac.email.util import strip_re, get_author_email, get_cc 20 from resourcetotrac.email.util import strip_re, get_author_email, get_cc, get_author 21 21 22 22 __all__ = [ … … 26 26 27 27 pattern = r'^(((?P<update>(re|RE|Re|rE)(:?[ ]*?))?\[(?P<project>.*?)] #(?P<id>\d+?): (?P<summary>.*))|([Tt][Ii][Cc][Kk][Ee][Tt]:?[ ]?(?P<newsummary>.*)))$' 28 ip_pattern = r'^from .*? \(.*?\[(?P<serverip>.*?)]\)$' 28 29 TICKET_SUBJECT_RE = re.compile(pattern) 30 TICKET_SERVER_IP_RE = re.compile(ip_pattern) 29 31 30 32 class EmailTicketParser(Component) … … 51 53 return resource_type.lower() == 'ticket' 52 54 53 def parse_message(self, resource_type, msg ):55 def parse_message(self, resource_type, msg, options={}): 54 56 """ Return an EmailTicketParsedMessage object """ 55 57 if resource_type.lower() != 'ticket': 56 58 return BaseParsedMessage() 57 return EmailTicketParsedMessaage(msg )59 return EmailTicketParsedMessaage(msg, options) 58 60 59 61 class EmailTicketParsedMessage(BaseParsedMessage): 60 62 """ Parse a ticket email """ 61 63 62 def __init__(self, msg ):64 def __init__(self, msg, options): 63 65 BaseParsedMessage.__init__(self, msg) 64 66 match_groups = TICKET_SUBJECT_RE.match(msg['Subject']).groupdict() … … 68 70 self.new = (not self.id) and match_groups['newsummary'] and True 69 71 self.project_name = match_groups['project'] 72 self.server_hops = options['server_hops'] 70 73 71 74 def get_author(self): … … 75 78 def get_ip(self): 76 79 """ 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' 78 91 79 92 def get_id(self): 80 93 """ Return the id of the resource """ 81 return ''94 return self.id 82 95 83 96 def get_type(self): 84 97 """ Return the type of resource """ 85 return ' unknown'98 return 'ticket' 86 99 87 100 def get_data(self): … … 91 104 def get_fields(self): 92 105 """ 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)) 93 111 return {} 94 112 … … 98 116 The options dictionary is specific to each resource type 99 117 """ 100 return {} 118 options = { 119 'update': self.update 120 } 121 return options 101 122 102 123 def get_attachments(self): 103 """ Return a list of (filename, attachment) tuples """ A124 """ Return a list of (filename, attachment) tuples """ 104 125 return [] 105 126
Note: See TracChangeset
for help on using the changeset viewer.
