Hi.

I've created a patch to allow tmda-inject to process X-TMDA in the subject-line even with UTF-8 encoding.

Now, I'm not 100% sure if this is the complete/ideal solution - I don't really know enough about what encodings are out there etc.

In particular, it's my understanding that Header.decode_header returns the data actually UTF-8 (or whatever) encoded - it's simply undone the encoding in the email that allows it to transport UTF-8 data. So, there may be many encodings of data returned. At present, my patch ensures that it only parses None/UTF-8 encoded data, because I don't know if/how it would work on other types... Are there other types that are likely? I'm in need of a good overview of I18N/UTF-8/unicode/etc.!

Anyway, here's the patch for people to comment on...

I'm beginning to like Python:-) I'm actually enjoying learning/using it, unlike Tcl, which the more I use it, the more I hate it!

--- tmda-inject 2003-07-11 16:02:59.000000000 -0700
+++ tmda-inject-hacked 2003-08-20 10:53:47.000000000 -0700
@@ -126,6 +126,7 @@
from TMDA import Util


from email.Utils import formataddr, getaddresses, parseaddr
+from email.Header import decode_header, make_header
import socket
import string


@@ -396,15 +397,36 @@
if (Defaults.X_TMDA_IN_SUBJECT and msgout.has_key('subject') and
x_tmda_over is None):
sub = msgout.get('subject')
- subsplit = sub.split(None, 2)
- if subsplit and subsplit[0].lower() == 'x-tmda':
+
+ dh = decode_header(sub)
+
+ #sys.stderr.write('x-tmda in subject "%s"\n' % sub)
+ #for hp in dh:
+ # sys.stderr.write('decoded: "%s" : "%s"\n' % (hp[0], hp[1]))
+
+ dhs = []
+ if len(dh) > 0:
+ dh0s = dh[0][0].split(None)
+ dhs.extend(map(lambda x: [x, dh[0][1]], dh0s))
+ if len(dh) > 1:
+ dh1s = dh[1][0].split(None)
+ dhs.extend(map(lambda x: [x, dh[1][1]], dh1s))
+ dhs.extend(dh[2:])
+
+ #for hp in dhs:
+ # sys.stderr.write('decoded split: "%s" : "%s"\n' % (hp[0], hp[1]))
+
+ if len(dhs) >= 2 \
+ and dhs[0][1] in (None, 'utf-8') \
+ and dhs[1][1] in (None, 'utf-8') \
+ and dhs[0][0].lower() == 'x-tmda':
x_tmda_over = 1
- actions = { 'from' : FilterParser.splitaction(subsplit[1]) }
- log_msg = '%s: %s' % ('X-TMDA', subsplit[1])
+ actions = { 'from' : FilterParser.splitaction(dhs[1][0]) }
+ log_msg = '%s: %s' % ('X-TMDA', dhs[1][0])
# Fixup Subject: before sending.
del msgout['Subject']
- if subsplit[2:]:
- msgout['Subject'] = subsplit[2:][0]
+ if dhs[2:]:
+ msgout['Subject'] = make_header(dhs[2:])
else:
msgout['Subject'] = ''


Feedback desired.

--
Stephen Warren, Software Engineer, Parama Networks, San Jose, CA
[EMAIL PROTECTED] http://www.wwwdotorg.org/


_________________________________________________
tmda-workers mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-workers

Reply via email to