From: Benoît Pin Date: Thu, 1 Aug 2013 14:06:23 +0000 (+0200) Subject: Ajout fonction utilitaire pour encoder de manière sécurisé les en-tête des mails. X-Git-Url: https://scm.cri.ensmp.fr/git/Plinn.git/commitdiff_plain/4f6cc7ed9e24196383be02e8bbc38e02795b08ab?ds=inline;hp=dab819e75a82aea184b6651523f9be4ad10f71ff Ajout fonction utilitaire pour encoder de manière sécurisé les en-tête des mails. --- diff --git a/utils.py b/utils.py index 7c5ceb7..8f6bd3d 100755 --- a/utils.py +++ b/utils.py @@ -261,6 +261,29 @@ def encodeQuopriEmail(name, email) : qpName = encodestring(name).replace('=\n', '') return '''"=?utf-8?q?%s?=" <%s>''' % (qpName, email) +def encodeMailHeader(content) : + s = encodestring(content).replace('=\n', '') + s = s.replace('_', '=5F') + s = s.replace(' ', '_') + + lines = [] + STEP = 50 + start = 0 + stop = STEP + part = s[start:stop] + lines.append(part) + + while len(part) == STEP: + start = start + STEP + stop = stop + STEP + part = s[start:stop] + lines.append(part) + + lines = [' =?utf-8?Q?%s?=' % part for part in lines] + s = '\n'.join(lines) + s = s.strip() + return s + def _sudo(func, userid=None) : """