Changeset in

Show
Ignore:
Timestamp:
05/02/09 16:44:28 (16 months ago)
Author:
John Hampton <pacopablo@…>
Children:
4e17a72f98bff34332fbca7853ac4aa7b854d997
Parents:
4bceacf6b979775083c8623c2906a66e95eefe48
git-committer:
John Hampton <pacopablo@pacopablo.com> / 2009-05-02T16:44:28Z-0700
Message:

Fleshed out framework. Begun implementation of IMAP email data source

Location:
resourcetotrac/resourcetotrac
Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • resourcetotrac/resourcetotrac/api.py

    ref235ae rc8845e4  
    5757        """ 
    5858 
     59 
    5960class IResourceSubmitter(Interface): 
    6061    """ Interface for submitting Resources to Trac """ 
     
    6566    def submit_resource(self, obj): 
    6667        """ Submits the resource to Trac """  
     68 
    6769 
    6870class IResourceParser(Interface): 
     
    8082        """ 
    8183 
     84 
    8285class ITypeParser(Interface): 
    8386    """ Extracts the resource type from the message 
     
    9295 
    9396class BaseParsedMessage(object): 
    94     """ Base class for parsed messages. 
     97    """ Base class for parsed messages. """ 
    9598 
    96     At a bare minimum, get_id() and get_type() need to be overridden 
    97     """ 
     99    def __init__(self, message=None): 
     100        self.raw_message = message 
    98101 
    99102    def get_author(self): 
     
    107110    def get_id(self): 
    108111        """ Return the id of the resource """ 
     112        return '' 
    109113     
    110114    def get_type(self): 
    111115        """ Return the type of resource """ 
     116        return 'unknown' 
    112117 
    113118    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  
    1515 
    1616# Local imports 
    17 from resourcetotrac.api import IResourceParser 
     17from resourcetotrac.api import IResourceParser, ITypeParser 
    1818 
    1919__all__ = [ 
     
    2828    """ Parse an email message """ 
    2929 
    30 class IEmailTypeParser(TypeParser): 
     30class IEmailTypeParser(ITypeParser): 
     31    """ Parse the resource type from the message """ 
  • resourcetotrac/resourcetotrac/email/imap.py

    ref235ae rc8845e4  
    6868            self.log.debug('Unable to select messages from server') 
    6969        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) 
    7277         
    7378 
     
    7883        """ 
    7984         
    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 
    8193        response = self.cnx.list(archive) 
    8294        if response[RESPONSE] == OK and response[DATA][0] == 'None': 
  • resourcetotrac/resourcetotrac/email/util.py

    ref235ae rc8845e4  
    2020__all__ = [ 
    2121    'strip_re',  
    22     'get_resource_type', 
    23     'get_author', 
     22    'get_author_email', 
    2423    'get_cc', 
    2524] 
     
    3332    return subject 
    3433 
    35 def get_resource_type(msg): 
    36     """ Returns the resource type of the message. 
     34def get_author(env, msg): 
     35    """ Return the username of the author based on the From: address  
    3736 
    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 
    4146 
    42     wiki: 
    43         wiki:Path/Of/WikiPage 
     47def get_author_email(msg): 
     48    """ Returns the email of the author """ 
     49    return parseadr(msg['From'])[1] 
    4450 
    45     milestone: 
    46         milestone:Milestone Name  
     51def 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', []))] 
    4754 
    48     """  
Note: See TracChangeset for help on using the changeset viewer.