Changeset in
- 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
- Location:
- resourcetotrac/resourcetotrac
- Files:
-
- 4 edited
-
api.py (modified) (3 diffs)
-
email/imap.py (modified) (3 diffs)
-
email/parsers/ticket.py (modified) (7 diffs)
-
email/util.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
resourcetotrac/resourcetotrac/api.py
rc8845e4 r4e17a72 77 77 """ Return whether or not to parse the given resource type """ 78 78 79 def parse_message(self, resource_type, message ):79 def parse_message(self, resource_type, message, options): 80 80 """ Parses the message and returns a child instance of 81 81 BaseParsedMesssage … … 97 97 """ Base class for parsed messages. """ 98 98 99 def __init__(self, message=None ):99 def __init__(self, message=None, options={}): 100 100 self.raw_message = message 101 101 … … 132 132 133 133 def get_attachments(self): 134 """ Return a list of (filename, attachment) tuples """ A134 """ Return a list of (filename, attachment) tuples """ 135 135 return [] 136 136 -
resourcetotrac/resourcetotrac/email/imap.py
rc8845e4 r4e17a72 50 50 passwd = Option('resource2trac', 'imap.passwd', 51 51 doc="IMAP password") 52 server_hops = IntOption('resource2trac', 'imap.server.hops', default=2, 53 doc="Number of servers to back-track in order to " 54 "find the IP of the sender") 52 55 53 56 # IDataSource Methods … … 148 151 BaseParsedMessage subclass 149 152 """ 153 options = {'server_hops': self.server_hops} 150 154 for p in self.type_parsers: 151 155 resource_type = p.get_resource_type(msg) … … 155 159 for p in self.resource_parsers: 156 160 if p.match_resource_type(resource_type): 157 return p.parse_message(resource_type, msg )161 return p.parse_message(resource_type, msg, options) 158 162 continue 159 163 return None -
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 -
resourcetotrac/resourcetotrac/email/util.py
rc8845e4 r4e17a72 41 41 cnx = env.get_db_cnx() 42 42 cur = cnx.cursor() 43 cur.execute("SELECT sid FROM session_attribute WHERE name = 'email' AND value = %s", (address,)) 43 cur.execute("SELECT sid " 44 " FROM session_attribute " 45 " WHERE name = 'email' " 46 " AND value = %s", (address,)) 47 author = cur.fetchone()[0] 48 cur = None 44 49 cnx.close() 45 50 cnx = None 51 return author 46 52 47 53 def get_author_email(msg):
Note: See TracChangeset
for help on using the changeset viewer.
