from types import StringType
from random import randrange
from Acquisition import aq_base
+from quopri import encodestring
+from zope.globalrequest import getRequest
from AccessControl.PermissionRole import rolesForPermissionOn
from AccessControl import ModuleSecurityInfo
from AccessControl import getSecurityManager
Message = MessageFactory('plinn')
security.declarePublic('translate')
-def translate(message, context):
+def translate(message, context=None):
""" Translate i18n message.
"""
if isinstance(message, Exception):
message = message[0]
except (TypeError, IndexError):
pass
- return i18ntranslate(message, domain='plinn', context=context.REQUEST)
+ if not context :
+ request = getRequest()
+ else :
+ request = context.REQUEST
+ return i18ntranslate(message, domain='plinn', context=request)
security.declarePublic('desacc')
desacc = Utf8Utils.desacc
else :
return default
+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) :
"""
execute func or any callable object