Changeset 87 for emailtotracscript


Ignore:
Timestamp:
06/22/06 14:13:42 (18 years ago)
Author:
bas
Message:

EmailtoTracScript?:

email2trac.py.in:

  • added enable_syslog option
  • fixed an error in unicode converting
  • Fixed some layout code
Location:
emailtotracscript/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • emailtotracscript/trunk/ChangeLog

    r85 r87  
    33          the database connection.
    44          Fixed by: Walter de Jong en Bas van der Vlies
     5
     6        - Added enable_syslog option. If enabled log errors
     7          to syslog instead of stderr. If enabled no errors are
     8          send back to the user.
     9          Implemented by: Bas van der Vlies
     10
     11        - Fixed an error with updating tickets with attachments for trac
     12          versions 0.9 and 0.10. Field "id" is not known when a existing
     13          ticket is fetched (Error = KeyError: 'id')
     14          Fixed By: See tickets #258 and #449 on trac-hacks
    515
    6162006-06-02
  • emailtotracscript/trunk/INSTALL

    r82 r87  
    2222 email_header: 1            # OPTIONAL, if set then show TO/CC fields in description
    2323 trac_version: 0.8          # OPTIONAL, if set use this as trac version (D: 0.9)
     24 enable_syslog: 1           # OPTIONAL, if set log errors to syslog
    2425
    2526 [bas]                     # OPTIONAL project declaration, also set
  • emailtotracscript/trunk/debian/changelog

    r85 r87  
     1email2trac (0.7.3-1) stable; urgency=low
     2
     3  * Enabled syslog option
     4
     5 -- root <root@subtrac.sara.nl>  Thu, 22 Jun 2006 12:45:37 +0200
     6
     7email2trac (0.7.2-0) stable; urgency=low
     8
     9  * Added new try/except statement and fixed LookupError
     10
     11 -- root <root@subtrac.sara.nl>  Thu, 22 Jun 2006 09:59:02 +0200
     12
    113email2trac (0.7.1-3) stable; urgency=low
    214
  • emailtotracscript/trunk/email2trac.conf

    r43 r87  
    1111email_header: 1
    1212trac_version: 0.9
     13enable_syslog : 0
    1314alternate_notify_template :
     15
    1416
    1517[bas]
  • emailtotracscript/trunk/email2trac.py.in

    r86 r87  
    5454        spam_level   : 4               # OPTIONAL, if set check for SPAM mail
    5555        reply_address: 1               # OPTIONAL, if set then fill in ticket CC field
    56     umask        : 022             # OPTIONAL, if set then use this umask for creation of the attachments
     56        umask        : 022             # OPTIONAL, if set then use this umask for creation of the attachments
    5757        mailto_link  : 1               # OPTIONAL, if set then [mailto:<>] in description
    5858        mailto_cc    : basv@sara.nl    # OPTIONAL, use this address as CC in mailto line
     
    187187                                try:
    188188                                        temp = unicode(text, format)
    189                                 except UnicodeError:
     189                                except (UnicodeError,LookupError):
    190190                                        # This always works
    191191                                        #
    192192                                        temp = unicode(text, 'iso-8859-15')
     193                                       
    193194                                temp =  temp.encode('utf-8')
    194195                        else:
     
    495496                                # UTF-8 encode body_text
    496497                                #
    497                                 charset = msg.get_content_charset('iso-8859-15')
     498                                charset = part.get_content_charset('iso-8859-15')
    498499                                ubody_text = unicode(body_text, charset).encode('utf-8')
    499500
     
    696697        return project
    697698
     699
    698700if __name__ == '__main__':
    699701        # Default config file
     
    702704        project = ''
    703705        component = ''
    704        
     706        ENABLE_SYSLOG = 0
     707               
    705708        try:
    706709                opts, args = getopt.getopt(sys.argv[1:], 'chf:p:', ['component=','help', 'file=', 'project='])
     
    709712                print detail
    710713                sys.exit(1)
    711 
     714       
    712715        project_name = None
    713716        for opt,value in opts:
     
    721724                elif opt in ['-p', '--project']:
    722725                        project_name = value
    723 
     726       
    724727        settings = ReadConfig(configfile, project_name)
    725728        if not settings.has_key('project'):
     
    727730                print 'No Trac project is defined in the email2trac config file.'
    728731                sys.exit(1)
    729 
     732       
    730733        if component:
    731734                settings['component'] = component
    732 
     735       
    733736        if settings.has_key('trac_version'):
    734737                version = float(settings['trac_version'])
     
    736739                version = trac_default_version
    737740
     741        if settings.has_key('enable_syslog'):
     742                ENABLE_SYSLOG =  float(settings['enable_syslog'])
     743                       
    738744        #debug HvB
    739745        #print settings
    740 
    741         if version == 0.8:
    742                 from trac.Environment import Environment
    743                 from trac.Ticket import Ticket
    744                 from trac.Notify import TicketNotifyEmail
    745                 from trac.Href import Href
    746                 from trac import util
    747                 import sqlite
    748         elif version == 0.9:
    749                 from trac import attachment
    750                 from trac.env import Environment
    751                 from trac.ticket import Ticket
    752                 from trac.web.href import Href
    753                 from trac import util
    754                 from trac.Notify import TicketNotifyEmail
    755         elif version == 0.10:
    756                 from trac import attachment
    757                 from trac.env import Environment
    758                 from trac.ticket import Ticket
    759                 from trac.web.href import Href
    760                 from trac import util
    761                 # see http://projects.edgewall.com/trac/changeset/2799
    762                 from trac.ticket.notification import TicketNotifyEmail
    763 
    764         env = Environment(settings['project'], create=0)
    765         tktparser = TicketEmailParser(env, settings, version)
    766         tktparser.parse(sys.stdin)
     746       
     747        try:
     748                if version == 0.8:
     749                        from trac.Environment import Environment
     750                        from trac.Ticket import Ticket
     751                        from trac.Notify import TicketNotifyEmail
     752                        from trac.Href import Href
     753                        from trac import util
     754                        import sqlite
     755                elif version == 0.9:
     756                        from trac import attachment
     757                        from trac.env import Environment
     758                        from trac.ticket import Ticket
     759                        from trac.web.href import Href
     760                        from trac import util
     761                        from trac.Notify import TicketNotifyEmail
     762                elif version == 0.10:
     763                        from trac import attachment
     764                        from trac.env import Environment
     765                        from trac.ticket import Ticket
     766                        from trac.web.href import Href
     767                        from trac import util
     768                        # see http://projects.edgewall.com/trac/changeset/2799
     769                        from trac.ticket.notification import TicketNotifyEmail
     770       
     771                env = Environment(settings['project'], create=0)
     772                tktparser = TicketEmailParser(env, settings, version)
     773                tktparser.parse(sys.stdin)
     774
     775        # Catch all errors ans log to SYSLOG if we have enabled this
     776        # else stdout
     777        #
     778        except Exception, error:
     779                import syslog, traceback
     780
     781                if ENABLE_SYSLOG:
     782                        syslog.openlog('email2trac', syslog.LOG_NOWAIT)
     783                        etype, evalue, etb = sys.exc_info()
     784                        for e in traceback.format_exception(etype, evalue, etb):
     785                                syslog.syslog(e)
     786                        syslog.closelog()
     787                else:
     788                        traceback.print_exc()
    767789
    768790# EOB
Note: See TracChangeset for help on using the changeset viewer.