On Monday 23 January 2006 13:19, Bas van der Vlies wrote:
> We use the RSS feed for it, so if there is a new ticket it will show up.
>      The hdf variable is used for web content. I do not know how it
> works, i'll have to examine it. We can always send email with an url in it.

Please see my (working for me, YMMV) solution in the attached patch.

I also got an issue where the email address retrieved from the From: field 
(and used for the 'Cc' and 'reporter' ticket fields) contained 
'fancy-formatted' addresses. I mean some mailers use a "Full Name 
<[EMAIL PROTECTED]>" format, with spaces and even quotes. So I think it's a 
good 
idea to strip them before using the address. Fancy addresses cause errors in 
the notification system, even after the ticket has been added, when it's 
modified from the web interface. 

Best regards,

-- 
Kilian CAVALOTTI                      Administrateur réseaux et systèmes
UPMC / CNRS - LIP6 (C870)
8, rue du Capitaine Scott                          Tel. : 01 44 27 88 54
75015 Paris - France                               Fax. : 01 44 27 70 00
--- email2trac-0.4.4/email2trac.py	2006-01-24 15:47:06.000000000 +0100
+++ email2trac/bin/email2trac	2006-01-24 15:47:46.000000000 +0100
@@ -85,6 +85,11 @@
 from stat import *
 import mimetypes
 
+from trac.Notify import TicketNotifyEmail
+from trac.ticket import Ticket
+from trac.web.href import Href
+
+
 trac_default_version = 0.9
 
 class TicketEmailParser(object):
@@ -221,7 +226,7 @@
 #           head = "%s'''Date:''' %s [[BR]]" %(head, m['Date'])
 
         str = ''
-        if m['To'] and len(m['To']) > 0 and m['To'] != '[EMAIL PROTECTED]':
+        if m['To'] and len(m['To']) > 0:
             str = "'''To:''' %s [[BR]]" %(m['To'])
         if m['Cc'] and len(m['Cc']) > 0:
             str = "%s'''Cc:''' %s [[BR]]" % (str, m['Cc'])
@@ -245,7 +250,7 @@
                 pass
 
         self.db = self.env.get_db_cnx()
-        tkt = self.new_ticket(self.env)
+        tkt = Ticket(self.env)
         tkt['status'] = 'new'
 
         # Some defaults
@@ -277,6 +282,14 @@
         tkt['owner'] = cursor.fetchone()[0]
 
         from_str = self.to_unicode(msg['from'])
+        # if space in from_str, extract real mail address
+        if ' ' in from_str:
+            import re
+            email_re = re.compile(r"([\w\d_\.\-])+\@(([\w\d\-])+\.)+([\w\d]{2,4})+")
+            mo = email_re.search(from_str)
+            if mo:
+              from_str = mo.group(0)
+                        
         tkt['reporter'] = from_str
         if self.CC:
             tkt['cc'] = from_str
@@ -303,6 +316,10 @@
                 if not body_text:                   # decode failed
                     body_text = part.get_payload(decode=0)      # do not decode
 
+                
+                # Ugly hardcoded way to transform european messages to UTF8
+                body_text = unicode(body_text, 'iso-8859-15').encode('utf-8')   
+
                 tkt['description'] = '\n{{{\n\n%s\n}}}\n' % body_text
 
             elif part.get_content_type() == 'text/html':
@@ -338,6 +355,18 @@
         #
         self.attachments(msg, tkt, author)
 
+        # Notify
+        try: 
+            # create false {abs_}href properties, to trick Notify()
+            self.env.href = Href('/ticket')
+            self.env.abs_href = Href('/ticket')
+            tn = TicketNotifyEmail(self.env)
+            tn.notify(tkt, newticket=True)
+        except Exception, e:
+            print "TD: Failure sending notification on creation of ticket #%s: %s" % (tkt.id, e)
+
+                    
+
 
     def mail_line(self, str):
         return '%s %s' % (self.comment, str)
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac

Reply via email to