X-Git-Url: https://scm.cri.mines-paristech.fr/git/Plinn.git/blobdiff_plain/b74a186d8da401c587c4154c6008ff5bcf85e9cf..891027fea0c1660c35b7d126dd207eb64facf93b:/utils.py diff --git a/utils.py b/utils.py index 7c5ceb7..6b3b697 100755 --- a/utils.py +++ b/utils.py @@ -94,12 +94,12 @@ def formatFullName(memberName, memberGivenName, memberId, nameBefore=1) : memberFullName = u'' if memberName and memberGivenName : if nameBefore : - memberFullName = memberName.upper() + ' ' + capitalizeCompoundGivenName(memberGivenName) + memberFullName = memberName.capitalize() + ' ' + capitalizeCompoundGivenName(memberGivenName) else : - memberFullName = capitalizeCompoundGivenName(memberGivenName) + ' ' + memberName.upper() + memberFullName = capitalizeCompoundGivenName(memberGivenName) + ' ' + memberName.capitalize() elif memberName and not memberGivenName : - memberFullName = memberName.upper() + memberFullName = memberName.capitalize() elif not memberName and memberGivenName : memberFullName = capitalizeCompoundGivenName(memberGivenName) @@ -165,7 +165,11 @@ def _checkMemberPermission(userid, permission, obj, StringType = type('')): return 0 def getCPInfo(self) : - try: cp = _cb_decode(self.REQUEST['__cp']) + if self.REQUEST.RESPONSE.cookies.has_key('__cp') : + cp = self.REQUEST.RESPONSE.cookies['__cp']['value'] + else : + cp = self.REQUEST.get('__cp') + try: cp = _cb_decode(cp) except: return None return cp @@ -226,7 +230,7 @@ def getPreferredLanguages(context): security.declarePublic('getBestTranslationLanguage') def getBestTranslationLanguage(langs, context): """ returns best translation language according - availables languages (param langs) + to available languages (param langs) and user preferences (retrieves by context) """ request = getattr(context, 'REQUEST', None) @@ -257,10 +261,35 @@ def getAdapterByInterface(ob, dotted_name, default=_marker) : else : return default +security.declarePublic('encodeQuopriEmail') def encodeQuopriEmail(name, email) : qpName = encodestring(name).replace('=\n', '') return '''"=?utf-8?q?%s?=" <%s>''' % (qpName, email) +security.declarePublic('encodeMailHeader') +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) : """