Edgewall Software

Opened 17 years ago

Last modified 17 years ago

#4835 closed enhancement

fix for bad contrib/emailfilter.py encoding behaviour — at Version 2

Reported by: jodok@… Owned by: Jonas Borgström
Priority: normal Milestone:
Component: general Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Emmanuel Blot)

when submitting tickets via e-mail using the emailfilter.py, it caused trac to crash. the reason was that it inserted non-utf8 content into the database. the attached diff should fix that:

@@ -53,7 +53,10 @@
         tkt['summary'] = msg['subject']
         for part in msg.walk():
             if part.get_content_type() == 'text/plain':
-                tkt['description'] = part.get_payload(decode=1).strip()
+                ch = part.get_content_charset()
+                payload = part.get_payload(decode=True).strip()
+                plain = unicode(payload, ch).encode('utf-8')
+                tkt['description'] = plain
 
         if tkt.values.get('description'):
             tkt.insert()

Change History (2)

comment:1 by jodok@…, 17 years ago

sorry, we can use WikiFormatting :)

@@ -53,7 +53,10 @@
         tkt['summary'] = msg['subject']
         for part in msg.walk():
             if part.get_content_type() == 'text/plain':
-                tkt['description'] = part.get_payload(decode=1).strip()
+                ch = part.get_content_charset()
+                payload = part.get_payload(decode=True).strip()
+                plain = unicode(payload, ch).encode('utf-8')
+                tkt['description'] = plain
 
         if tkt.values.get('description'):
             tkt.insert()

comment:2 by Emmanuel Blot, 17 years ago

Description: modified (diff)

This web site is for the development of Trac itself.

Please report any plugin/extension issue to their respective author: th:wiki:EmailtoTracScript

Thanks in advance.

Note: See TracTickets for help on using tickets.