Changeset in
- Timestamp:
- 05/02/09 16:44:28 (16 months ago)
- Children:
- 4e17a72f98bff34332fbca7853ac4aa7b854d997
- Parents:
- 4bceacf6b979775083c8623c2906a66e95eefe48
- git-committer:
- John Hampton <pacopablo@pacopablo.com> / 2009-05-02T16:44:28Z-0700
- Location:
- resourcetotrac/resourcetotrac
- Files:
-
- 6 added
- 5 edited
-
api.py (modified) (5 diffs)
-
email/__init__.py (modified) (1 diff)
-
email/api.py (modified) (2 diffs)
-
email/imap.py (modified) (2 diffs)
-
email/parsers/__init__.py (added)
-
email/parsers/milestone.py (added)
-
email/parsers/ticket.py (added)
-
email/parsers/wiki.py (added)
-
email/util.py (modified) (2 diffs)
-
submitters/__init__.py (added)
-
submitters/ticket.py (added)
Legend:
- Unmodified
- Added
- Removed
-
resourcetotrac/resourcetotrac/api.py
ref235ae rc8845e4 57 57 """ 58 58 59 59 60 class IResourceSubmitter(Interface): 60 61 """ Interface for submitting Resources to Trac """ … … 65 66 def submit_resource(self, obj): 66 67 """ Submits the resource to Trac """ 68 67 69 68 70 class IResourceParser(Interface): … … 80 82 """ 81 83 84 82 85 class ITypeParser(Interface): 83 86 """ Extracts the resource type from the message … … 92 95 93 96 class BaseParsedMessage(object): 94 """ Base class for parsed messages. 97 """ Base class for parsed messages. """ 95 98 96 At a bare minimum, get_id() and get_type() need to be overridden97 """99 def __init__(self, message=None): 100 self.raw_message = message 98 101 99 102 def get_author(self): … … 107 110 def get_id(self): 108 111 """ Return the id of the resource """ 112 return '' 109 113 110 114 def get_type(self): 111 115 """ Return the type of resource """ 116 return 'unknown' 112 117 113 118 def get_data(self): -
resourcetotrac/resourcetotrac/email/__init__.py
ref235ae rc8845e4 1 # -*- coding: utf-8 -*- 2 # 3 # Copyright (C) 2009 John Hampton <pacopablo@pacopablo.com> 4 # All rights reserved. 5 # 6 # This software is licensed as described in the file COPYING, which 7 # you should have received as part of this distribution. 8 # 9 # Author: John Hampton <pacopablo@pacopablo.com> 10 11 # Standard Library Imports 12 13 # Third Party imports 14 15 # Local imports -
resourcetotrac/resourcetotrac/email/api.py
ref235ae rc8845e4 15 15 16 16 # Local imports 17 from resourcetotrac.api import IResourceParser 17 from resourcetotrac.api import IResourceParser, ITypeParser 18 18 19 19 __all__ = [ … … 28 28 """ Parse an email message """ 29 29 30 class IEmailTypeParser(TypeParser): 30 class IEmailTypeParser(ITypeParser): 31 """ Parse the resource type from the message """ -
resourcetotrac/resourcetotrac/email/imap.py
ref235ae rc8845e4 68 68 self.log.debug('Unable to select messages from server') 69 69 for x in int(response[DATA]): 70 msg = self._parse_message( msg = email.message_from_string(self.cnx.fetch(x, r'(UID RFC822)')[DATA][CONTAINER][MSG]) 71 yield (x, parsed_msg) 70 msg = self._parse_message( 71 email.message_from_string( 72 self.cnx.fetch(x, 73 r'(UID RFC822)')[DATA][CONTAINER][MSG] 74 ) 75 ) 76 yield (x, msg) 72 77 73 78 … … 78 83 """ 79 84 80 archive = 'INBOX._archive.%d' % ticket 85 msg = self._parse_message( 86 email.message_from_string( 87 self.cnx.fetch(x, 88 r'(UID RFC822)')[DATA][CONTAINER][MSG] 89 ) 90 ) 91 msg_info = {'type' : msg.get_type(), 'id' : str(msg.get_id()),} 92 archive = 'INBOX._archive.%(type)s.%(id)s' % msg_info 81 93 response = self.cnx.list(archive) 82 94 if response[RESPONSE] == OK and response[DATA][0] == 'None': -
resourcetotrac/resourcetotrac/email/util.py
ref235ae rc8845e4 20 20 __all__ = [ 21 21 'strip_re', 22 'get_resource_type', 23 'get_author', 22 'get_author_email', 24 23 'get_cc', 25 24 ] … … 33 32 return subject 34 33 35 def get_ resource_type(msg):36 """ Return s the resource type of the message.34 def get_author(env, msg): 35 """ Return the username of the author based on the From: address 37 36 38 For emails, the resource type is contained in the subject. 39 ticket: 40 [project name] #42: Summary 37 env is a Trac environment. 38 msg is an email object 39 """ 40 address = get_author_email(msg) 41 cnx = env.get_db_cnx() 42 cur = cnx.cursor() 43 cur.execute("SELECT sid FROM session_attribute WHERE name = 'email' AND value = %s", (address,)) 44 cnx.close() 45 cnx = None 41 46 42 wiki: 43 wiki:Path/Of/WikiPage 47 def get_author_email(msg): 48 """ Returns the email of the author """ 49 return parseadr(msg['From'])[1] 44 50 45 milestone: 46 milestone:Milestone Name 51 def get_cc(msg): 52 """ Returns a list of email addresses pulled from the CC list """ 53 return [e[1] for e in getaddresses(msg.get_all('cc', []))] 47 54 48 """
Note: See TracChangeset
for help on using the changeset viewer.
