Changeset 43 for emailtotracscript/trunk


Ignore:
Timestamp:
01/26/06 13:48:25 (18 years ago)
Author:
bas
Message:

EmailtoTracScript?:

email2trac.pyt.in, email2trac.conf:

  • Added reply_all option for ticket cc-field
Location:
emailtotracscript/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • emailtotracscript/trunk/email2trac.conf

    r42 r43  
    55spam_level: 4
    66reply_address: 1
     7reply_all : 1
    78mailto_link: 1
    89umask: 022
  • emailtotracscript/trunk/email2trac.py.in

    r42 r43  
    140140                else:
    141141                        self.notify_template = None
     142
     143                if parameters.has_key('reply_all'):
     144                        self.REPLY_ALL = int(parameters['reply_all'])
     145                else:
     146                        self.REPLY_ALL = 0
    142147
    143148
     
    232237                return str
    233238
     239        def set_owner(self, ticket):
     240                cursor = self.db.cursor()
     241                sql = "SELECT owner FROM component WHERE name='%s'" % ticket['component']
     242                cursor.execute(sql)
     243                ticket['owner'] = cursor.fetchone()[0]
     244
     245
     246        def set_reply_fields(self, ticket, message):
     247                author, email_addr  = email.Utils.parseaddr(message['from'])
     248                email_str = self.to_unicode(message['from'])
     249
     250                ticket['reporter'] = email_str
     251                ticket['cc'] = None
     252
     253                # Put all addresses in ticket CC field
     254                #
     255                if self.REPLY_ALL:
     256                        tos = message.get_all('to', [])
     257                        ccs = message.get_all('cc', [])
     258
     259                        addrs = email.Utils.getaddresses(tos + ccs)
     260
     261                        # Remove reporter email address if notification is
     262                        # on
     263                        #
     264                        if self.notification:
     265                                try:
     266                                        addrs.remove((author, email_addr))
     267                                except ValueError, detail:
     268                                        pass
     269
     270                        for a,m in addrs:
     271                                        if not ticket['cc']:
     272                                                ticket['cc'] = m
     273                                        else:
     274                                                ticket['cc'] = '%s,%s' %(ticket['cc'], m)
     275
     276                # Put authors email addess in CC field only if notification is off
     277                #
     278                elif self.CC and not self.notification:
     279                        ticket['cc'] = email_str
     280
     281                return author, email_addr
     282
    234283        def parse(self, fp):
    235284                msg = email.message_from_file(fp)
     
    252301                tkt['status'] = 'new'
    253302
     303                if self.get_config('notification', 'smtp_enabled') in ['true']:
     304                        self.notification = 1
     305
    254306                # Some defaults
    255307                #
     
    277329                #       sys.exit(1)
    278330
    279                 # Get default owner for component
    280                 #
    281                 cursor = self.db.cursor()
    282                 sql = "SELECT owner FROM component WHERE name='%s'" % tkt['component']
    283                 cursor.execute(sql)
    284                 tkt['owner'] = cursor.fetchone()[0]
    285 
    286                 author, email_addr  = email.Utils.parseaddr(msg['from'])
    287                 email_str = self.to_unicode(msg['from'])
    288                 if author:
    289                         tkt['reporter'] = email_str
    290                 else:
    291                         tkt['reporter'] = email_str
    292 
    293                 if self.CC:
    294                         tkt['cc'] = email_str
     331                # Set default owner for component
     332                #
     333                self.set_owner(tkt)
     334                author, email_addr = self.set_reply_fields(tkt, msg)
    295335
    296336# produce e-mail like header
     
    350390
    351391                self.attachments(msg, tkt, author)
    352                 if self.get_config('notification', 'smtp_enabled') in ['true']:
     392                if self.notification:
    353393                        self.notify(tkt)
    354394
  • emailtotracscript/trunk/test7.eml

    r5 r43  
    1616X-Accept-Language: en-us, en
    1717MIME-Version: 1.0
    18 To: "Walter de Jong" <walter@sara.nl>
     18To: "Walter de Jong" <walter@sara.nl>, basv@sara.nl
    1919Subject: test #7
    2020Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="------------ms030807040502080509050606"
Note: See TracChangeset for help on using the changeset viewer.