mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Fix: wrong decoding of subjects (headers) not encoded like the python function 'decode_header' understands rfc2047. Added file u2u_decode.py which corrects this problem, taken from here: http://bugs.python.org/issue1079.
This commit is contained in:
@@ -16,7 +16,7 @@ from django.utils.translation import ugettext as _
|
||||
from django.conf import settings
|
||||
from modoboa.lib import decode, tables, imap_utf7, Singleton
|
||||
from modoboa.lib.email_listing import MBconnector, EmailListing, Email
|
||||
from modoboa.lib import tables, imap_utf7, parameters, static_url
|
||||
from modoboa.lib import tables, imap_utf7, parameters, static_url, u2u_decode
|
||||
|
||||
|
||||
class WMtable(tables.Table):
|
||||
@@ -118,13 +118,7 @@ class IMAPheader(object):
|
||||
|
||||
@staticmethod
|
||||
def parse_subject(value, **kwargs):
|
||||
res = ""
|
||||
dcd = decode_header(re.sub("[\\r\\n]+", "", value))
|
||||
for part in dcd:
|
||||
if res != "":
|
||||
res += " "
|
||||
res += part[0].strip(" ")
|
||||
return decode(res)
|
||||
return u2u_decode.u2u_decode(value)
|
||||
|
||||
class ConnectionsManager(type):
|
||||
def __init__(cls, name, bases, dict):
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
# u2u_decode.py
|
||||
# unstructured rfc2047 header to unicode
|
||||
#
|
||||
import re
|
||||
from email.header import decode_header, make_header
|
||||
|
||||
# check spaces between encoded_words (and strip them)
|
||||
sre = re.compile(r'\?=[ \t]+=\?')
|
||||
# re pat for MIME encoded_word (without trailing spaces)
|
||||
mre = re.compile(r'=\?[^?]*?\?[bq]\?[^? \t]*?\?=', re.I)
|
||||
|
||||
def decode_mime(m):
|
||||
# substitute matching encoded_word with unicode equiv.
|
||||
h = decode_header(m.group(0))
|
||||
u = unicode(make_header(h))
|
||||
return u
|
||||
|
||||
def u2u_decode(s):
|
||||
# utility function for (final) decoding of mime header
|
||||
# note: resulting string is in one line (no \n within)
|
||||
# note2: spaces between enc_words are stripped (see RFC2047)
|
||||
s = ''.join(s.splitlines())
|
||||
s = sre.sub('?==?', s)
|
||||
u = mre.sub(decode_mime, s)
|
||||
return u
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
if len(sys.argv) > 1:
|
||||
s = sys.argv[1]
|
||||
else:
|
||||
s = """[Apache-Users 7784] ServerAlias =?ISO-2022-JP?B?GyRAGyRCJEsbKEI=?=:(
|
||||
=?ISO-2022-JP?B?GyRCJTMlbSVzGyhC?=)=?ISO-2022-JP?B?GyRCJHI7SBsoQg==?=
|
||||
=?ISO-2022-JP?B?GyRAGyRCTVEkOSRrJEg1c0YwJCwkKiQrJDckJBsoQg==?="""
|
||||
s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord'
|
||||
u = u2u_decode(s)
|
||||
print u
|
||||
|
||||
Reference in New Issue
Block a user