def escape(self, value): # transforms accents into html entities (é) # TODO: find out which language is current (here: assumes iso-8859-1) value = Utils.uncanonstr(value) # add slashes before " and ' return MySQLdb.escape_string(value)
def html_quote(s, lang=None): repls = ( ('&', '&'), ("<", '<'), (">", '>'), ('"', '"')) for thing, repl in repls: s = s.replace(thing, repl) return Utils.uncanonstr(s, lang)
def html_quote(s, lang=None): """Exchange symbols used in Python for appropriate html code""" repls = ( ('&', '&'), ("<", '<'), (">", '>'), ('"', '"')) for thing, repl in repls: s = s.replace(thing, repl) return Utils.uncanonstr(s, lang)
def show_pending_subs(mlist, form): # Add the subscription request section pendingsubs = mlist.GetSubscriptionIds() if not pendingsubs: return 0 form.AddItem('<hr>') form.AddItem(Center(Header(2, _('Subscription Requests')))) table = Table(border=2) table.AddRow([Center(Bold(_('Address/name/time'))), Center(Bold(_('Your decision'))), Center(Bold(_('Reason for refusal'))) ]) # Alphabetical order by email address byaddrs = {} for id in pendingsubs: addr = mlist.GetRecord(id)[1] byaddrs.setdefault(addr, []).append(id) addrs = byaddrs.items() addrs.sort() num = 0 for addr, ids in addrs: # Eliminate duplicates. # The list ws returned sorted ascending. Keep the last. for id in ids[:-1]: mlist.HandleRequest(id, mm_cfg.DISCARD) id = ids[-1] stime, addr, fullname, passwd, digest, lang = mlist.GetRecord(id) fullname = Utils.uncanonstr(fullname, mlist.preferred_language) displaytime = time.ctime(stime) radio = RadioButtonArray(id, (_('Defer'), _('Approve'), _('Reject'), _('Discard')), values=(mm_cfg.DEFER, mm_cfg.SUBSCRIBE, mm_cfg.REJECT, mm_cfg.DISCARD), checked=0).Format() if addr not in mlist.ban_list: radio += ('<br>' + '<label>' + CheckBox('ban-%d' % id, 1).Format() + ' ' + _('Permanently ban from this list') + '</label>') # While the address may be a unicode, it must be ascii paddr = addr.encode('us-ascii', 'replace') table.AddRow(['%s<br><em>%s</em><br>%s' % (paddr, Utils.websafe(fullname), displaytime), radio, TextBox('comment-%d' % id, size=40) ]) num += 1 if num > 0: form.AddItem(table) return num
def show_pending_unsubs(mlist, form): # Add the pending unsubscription request section lang = mlist.preferred_language pendingunsubs = mlist.GetUnsubscriptionIds() if not pendingunsubs: return 0 table = Table(border=2) table.AddRow([Center(Bold(_('User address/name'))), Center(Bold(_('Your decision'))), Center(Bold(_('Reason for refusal'))) ]) # Alphabetical order by email address byaddrs = {} for id in pendingunsubs: addr = mlist.GetRecord(id) byaddrs.setdefault(addr, []).append(id) addrs = byaddrs.keys() addrs.sort() num = 0 for addr, ids in byaddrs.items(): # Eliminate duplicates for id in ids[1:]: mlist.HandleRequest(id, mm_cfg.DISCARD) id = ids[0] addr = mlist.GetRecord(id) try: fullname = Utils.uncanonstr(mlist.getMemberName(addr), lang) except Errors.NotAMemberError: # They must have been unsubscribed elsewhere, so we can just # discard this record. mlist.HandleRequest(id, mm_cfg.DISCARD) continue num += 1 # While the address may be a unicode, it must be ascii paddr = addr.encode('us-ascii', 'replace') table.AddRow(['%s<br><em>%s</em>' % (paddr, Utils.websafe(fullname)), RadioButtonArray(id, (_('Defer'), _('Approve'), _('Reject'), _('Discard')), values=(mm_cfg.DEFER, mm_cfg.UNSUBSCRIBE, mm_cfg.REJECT, mm_cfg.DISCARD), checked=0), TextBox('comment-%d' % id, size=45) ]) if num > 0: form.AddItem('<hr>') form.AddItem(Center(Header(2, _('Unsubscription Requests')))) form.AddItem(table) return num
def set_options(userdesc, perms, mlist, opts, vals): for (k, v) in vals.iteritems(): if k not in opts: continue if k == 'default_member_moderation': for member in mlist.getMembers(): mlist.setMemberOption(member, mm_cfg.Moderate, int(v)) t = type(mlist.__dict__[k]) if t is bool: mlist.__dict__[k] = bool(v) elif t is int: mlist.__dict__[k] = int(v) elif t is str: mlist.__dict__[k] = Utils.uncanonstr(v, 'fr') else: mlist.__dict__[k] = v return 1
def show_pending_subs(mlist, form): # Add the subscription request section pendingsubs = mlist.GetSubscriptionIds() if not pendingsubs: return 0 form.AddItem('<hr>') form.AddItem(Center(Header(2, _('Subscription Requests')))) table = Table(border=2) table.AddRow([Center(Bold(_('Address/name'))), Center(Bold(_('Your decision'))), Center(Bold(_('Reason for refusal'))) ]) # Alphabetical order by email address byaddrs = {} for id in pendingsubs: addr = mlist.GetRecord(id)[1] byaddrs.setdefault(addr, []).append(id) addrs = byaddrs.items() addrs.sort() num = 0 for addr, ids in addrs: # Eliminate duplicates for id in ids[1:]: mlist.HandleRequest(id, mm_cfg.DISCARD) id = ids[0] time, addr, fullname, passwd, digest, lang = mlist.GetRecord(id) fullname = Utils.uncanonstr(fullname, mlist.preferred_language) radio = RadioButtonArray(id, (_('Defer'), _('Approve'), _('Reject'), _('Discard')), values=(mm_cfg.DEFER, mm_cfg.SUBSCRIBE, mm_cfg.REJECT, mm_cfg.DISCARD), checked=0).Format() if addr not in mlist.ban_list: radio += ('<br>' + '<label>' + CheckBox('ban-%d' % id, 1).Format() + ' ' + _('Permanently ban from this list') + '</label>') # While the address may be a unicode, it must be ascii paddr = addr.encode('us-ascii', 'replace') table.AddRow(['%s<br><em>%s</em>' % (paddr, Utils.websafe(fullname)), radio, TextBox('comment-%d' % id, size=40) ]) num += 1 if num > 0: form.AddItem(table) return num
def show_pending_unsubs(mlist, form): # Add the pending unsubscription request section lang = mlist.preferred_language pendingunsubs = mlist.GetUnsubscriptionIds() if not pendingunsubs: return 0 table = Table(border=2) table.AddRow([Center(Bold(_('User address/name'))), Center(Bold(_('Your decision'))), Center(Bold(_('Reason for refusal'))) ]) # Alphabetical order by email address byaddrs = {} for id in pendingunsubs: addr = mlist.GetRecord(id) byaddrs.setdefault(addr, []).append(id) addrs = byaddrs.items() addrs.sort() num = 0 for addr, ids in addrs: # Eliminate duplicates # Here the order doesn't matter as the data is just the address. for id in ids[1:]: mlist.HandleRequest(id, mm_cfg.DISCARD) id = ids[0] addr = mlist.GetRecord(id) try: fullname = Utils.uncanonstr(mlist.getMemberName(addr), lang) except Errors.NotAMemberError: # They must have been unsubscribed elsewhere, so we can just # discard this record. mlist.HandleRequest(id, mm_cfg.DISCARD) continue num += 1 table.AddRow(['%s<br><em>%s</em>' % (addr, Utils.websafe(fullname)), RadioButtonArray(id, (_('Defer'), _('Approve'), _('Reject'), _('Discard')), values=(mm_cfg.DEFER, mm_cfg.UNSUBSCRIBE, mm_cfg.REJECT, mm_cfg.DISCARD), checked=0), TextBox('comment-%d' % id, size=45) ]) if num > 0: form.AddItem('<hr>') form.AddItem(Center(Header(2, _('Unsubscription Requests')))) form.AddItem(table) return num
def FormatUsers(self, digest, lang=None, list_hidden=False): if lang is None: lang = self.preferred_language conceal_sub = mm_cfg.ConcealSubscription people = [] if digest: members = self.getDigestMemberKeys() else: members = self.getRegularMemberKeys() for m in members: if list_hidden or not self.getMemberOption(m, conceal_sub): people.append(m) num_concealed = len(members) - len(people) if num_concealed == 1: concealed = _('<em>(1 private member not shown)</em>') elif num_concealed > 1: concealed = _( '<em>(%(num_concealed)d private members not shown)</em>') else: concealed = '' items = [] people.sort() obscure = self.obscure_addresses for person in people: id = Utils.ObscureEmail(person) url = self.GetOptionsURL(person, obscure=obscure) person = self.getMemberCPAddress(person) if obscure: showing = Utils.ObscureEmail(person, for_text=1) else: showing = person realname = Utils.uncanonstr(self.getMemberName(person), lang) if realname and mm_cfg.ROSTER_DISPLAY_REALNAME: showing += " (%s)" % Utils.websafe(realname) got = Link(url, showing) if self.getDeliveryStatus(person) <> MemberAdaptor.ENABLED: got = Italic('(', got, ')') items.append(got) # Just return the .Format() so this works until I finish # converting everything to htmlformat... return concealed + UnorderedList(*tuple(items)).Format()
def quick_maketext(templatefile, dict=None, lang=None, mlist=None): """Create an output using a template""" # Used by various html output functions such as as_html, html_TOC and write_index_entry if mlist is None: listname = '' else: listname = mlist._internal_name if lang is None: if mlist is None: lang = mm_cfg.DEFAULT_SERVER_LANGUAGE else: lang = mlist.preferred_language cachekey = (templatefile, lang, listname) filepath = _templatefilepathcache.get(cachekey) if filepath: template = _templatecache.get(filepath) if filepath is None or template is None: # Use the basic maketext, with defaults to get the raw template template, filepath = Utils.findtext(templatefile, lang=lang, raw=True, mlist=mlist) _templatefilepathcache[cachekey] = filepath _templatecache[filepath] = template # Copied from Utils.maketext() text = template if dict is not None: try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, Utils.GetCharSet(lang), 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError): # The template is really screwed up pass # Make sure the text is in the given character set, or html-ify any bogus # characters. return Utils.uncanonstr(text, lang)
def FormatUsers(self, digest, lang=None, list_hidden=False): if lang is None: lang = self.preferred_language conceal_sub = mm_cfg.ConcealSubscription people = [] if digest: members = self.getDigestMemberKeys() else: members = self.getRegularMemberKeys() for m in members: if list_hidden or not self.getMemberOption(m, conceal_sub): people.append(m) num_concealed = len(members) - len(people) if num_concealed == 1: concealed = _('<em>(1 private member not shown)</em>') elif num_concealed > 1: concealed = _( '<em>(%(num_concealed)d private members not shown)</em>') else: concealed = '' items = [] people.sort() obscure = self.obscure_addresses for person in people: id = Utils.ObscureEmail(person) url = self.GetOptionsURL(person, obscure=obscure) if obscure: showing = Utils.ObscureEmail(person, for_text=1) else: showing = person realname = Utils.uncanonstr(self.getMemberName(person), lang) if realname and mm_cfg.ROSTER_DISPLAY_REALNAME: showing += " (%s)" % Utils.websafe(realname) got = Link(url, showing) if self.getDeliveryStatus(person) <> MemberAdaptor.ENABLED: got = Italic('(', got, ')') items.append(got) # Just return the .Format() so this works until I finish # converting everything to htmlformat... return concealed + UnorderedList(*tuple(items)).Format()
def quick_maketext(templatefile, dict=None, lang=None, mlist=None): if mlist is None: listname = '' else: listname = mlist._internal_name if lang is None: if mlist is None: lang = mm_cfg.DEFAULT_SERVER_LANGUAGE else: lang = mlist.preferred_language cachekey = (templatefile, lang, listname) filepath = _templatefilepathcache.get(cachekey) if filepath: template = _templatecache.get(filepath) if filepath is None or template is None: # Use the basic maketext, with defaults to get the raw template template, filepath = Utils.findtext(templatefile, lang=lang, raw=True, mlist=mlist) _templatefilepathcache[cachekey] = filepath _templatecache[filepath] = template # Copied from Utils.maketext() text = template if dict is not None: try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, Utils.GetCharSet(lang), 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError): # The template is really screwed up pass # Make sure the text is in the given character set, or html-ify any bogus # characters. return Utils.uncanonstr(text, lang)
def set_options(vhost,listname,opts,vals): try: mlist = MailList.MailList(vhost+'-'+listname) except: return 0 try: for (k,v) in vals.iteritems(): if k not in opts: continue if k == 'default_member_moderation': for member in mlist.getMembers(): mlist.setMemberOption(member, mm_cfg.Moderate, int(v)) t = type(mlist.__dict__[k]) if t is bool: mlist.__dict__[k] = bool(v) elif t is int: mlist.__dict__[k] = int(v) elif t is str: mlist.__dict__[k] = Utils.uncanonstr(v,'fr') else: mlist.__dict__[k] = v mlist.Save() mlist.Unlock() return 1 except: mlist.Unlock() raise return 0
def options_page(mlist, doc, user, cpuser, userlang, message=""): # The bulk of the document will come from the options.html template, which # includes it's own html armor (head tags, etc.). Suppress the head that # Document() derived pages get automatically. doc.suppress_head = 1 if mlist.obscure_addresses: presentable_user = Utils.ObscureEmail(user, for_text=1) if cpuser is not None: cpuser = Utils.ObscureEmail(cpuser, for_text=1) else: presentable_user = user fullname = Utils.uncanonstr(mlist.getMemberName(user), userlang) if fullname: presentable_user += ", %s" % Utils.websafe(fullname) # Do replacements replacements = mlist.GetStandardReplacements(userlang) replacements["<mm-results>"] = Bold(FontSize("+1", message)).Format() replacements["<mm-digest-radio-button>"] = mlist.FormatOptionButton(mm_cfg.Digests, 1, user) replacements["<mm-undigest-radio-button>"] = mlist.FormatOptionButton(mm_cfg.Digests, 0, user) replacements["<mm-plain-digests-button>"] = mlist.FormatOptionButton(mm_cfg.DisableMime, 1, user) replacements["<mm-mime-digests-button>"] = mlist.FormatOptionButton(mm_cfg.DisableMime, 0, user) replacements["<mm-global-mime-button>"] = CheckBox("mime-globally", 1, checked=0).Format() replacements["<mm-delivery-enable-button>"] = mlist.FormatOptionButton(mm_cfg.DisableDelivery, 0, user) replacements["<mm-delivery-disable-button>"] = mlist.FormatOptionButton(mm_cfg.DisableDelivery, 1, user) replacements["<mm-disabled-notice>"] = mlist.FormatDisabledNotice(user) replacements["<mm-dont-ack-posts-button>"] = mlist.FormatOptionButton(mm_cfg.AcknowledgePosts, 0, user) replacements["<mm-ack-posts-button>"] = mlist.FormatOptionButton(mm_cfg.AcknowledgePosts, 1, user) replacements["<mm-receive-own-mail-button>"] = mlist.FormatOptionButton(mm_cfg.DontReceiveOwnPosts, 0, user) replacements["<mm-dont-receive-own-mail-button>"] = mlist.FormatOptionButton(mm_cfg.DontReceiveOwnPosts, 1, user) replacements["<mm-dont-get-password-reminder-button>"] = mlist.FormatOptionButton( mm_cfg.SuppressPasswordReminder, 1, user ) replacements["<mm-get-password-reminder-button>"] = mlist.FormatOptionButton( mm_cfg.SuppressPasswordReminder, 0, user ) replacements["<mm-public-subscription-button>"] = mlist.FormatOptionButton(mm_cfg.ConcealSubscription, 0, user) replacements["<mm-hide-subscription-button>"] = mlist.FormatOptionButton(mm_cfg.ConcealSubscription, 1, user) replacements["<mm-dont-receive-duplicates-button>"] = mlist.FormatOptionButton( mm_cfg.DontReceiveDuplicates, 1, user ) replacements["<mm-receive-duplicates-button>"] = mlist.FormatOptionButton(mm_cfg.DontReceiveDuplicates, 0, user) replacements["<mm-unsubscribe-button>"] = ( mlist.FormatButton("unsub", _("Unsubscribe")) + "<br>" + CheckBox("unsubconfirm", 1, checked=0).Format() + _("<em>Yes, I really want to unsubscribe</em>") ) replacements["<mm-new-pass-box>"] = mlist.FormatSecureBox("newpw") replacements["<mm-confirm-pass-box>"] = mlist.FormatSecureBox("confpw") replacements["<mm-change-pass-button>"] = mlist.FormatButton("changepw", _("Change My Password")) replacements["<mm-other-subscriptions-submit>"] = mlist.FormatButton("othersubs", _("List my other subscriptions")) replacements["<mm-form-start>"] = mlist.FormatFormStart("options", user) replacements["<mm-user>"] = user replacements["<mm-presentable-user>"] = presentable_user replacements["<mm-email-my-pw>"] = mlist.FormatButton("emailpw", (_("Email My Password To Me"))) replacements["<mm-umbrella-notice>"] = mlist.FormatUmbrellaNotice(user, _("password")) replacements["<mm-logout-button>"] = mlist.FormatButton("logout", _("Log out")) replacements["<mm-options-submit-button>"] = mlist.FormatButton("options-submit", _("Submit My Changes")) replacements["<mm-global-pw-changes-button>"] = CheckBox("pw-globally", 1, checked=0).Format() replacements["<mm-global-deliver-button>"] = CheckBox("deliver-globally", 1, checked=0).Format() replacements["<mm-global-remind-button>"] = CheckBox("remind-globally", 1, checked=0).Format() replacements["<mm-global-nodupes-button>"] = CheckBox("nodupes-globally", 1, checked=0).Format() days = int(mm_cfg.PENDING_REQUEST_LIFE / mm_cfg.days(1)) if days > 1: units = _("days") else: units = _("day") replacements["<mm-pending-days>"] = _("%(days)d %(units)s") replacements["<mm-new-address-box>"] = mlist.FormatBox("new-address") replacements["<mm-confirm-address-box>"] = mlist.FormatBox("confirm-address") replacements["<mm-change-address-button>"] = mlist.FormatButton( "change-of-address", _("Change My Address and Name") ) replacements["<mm-global-change-of-address>"] = CheckBox("changeaddr-globally", 1, checked=0).Format() replacements["<mm-fullname-box>"] = mlist.FormatBox("fullname", value=fullname) # Create the topics radios. BAW: what if the list admin deletes a topic, # but the user still wants to get that topic message? usertopics = mlist.getMemberTopics(user) if mlist.topics: table = Table(border="0") for name, pattern, description, emptyflag in mlist.topics: if emptyflag: continue quotedname = urllib.quote_plus(name) details = Link(mlist.GetScriptURL("options") + "/%s/?VARHELP=%s" % (user, quotedname), " (Details)") if name in usertopics: checked = 1 else: checked = 0 table.AddRow([CheckBox("usertopic", quotedname, checked=checked), name + details.Format()]) topicsfield = table.Format() else: topicsfield = _("<em>No topics defined</em>") replacements["<mm-topics>"] = topicsfield replacements["<mm-suppress-nonmatching-topics>"] = mlist.FormatOptionButton( mm_cfg.ReceiveNonmatchingTopics, 0, user ) replacements["<mm-receive-nonmatching-topics>"] = mlist.FormatOptionButton(mm_cfg.ReceiveNonmatchingTopics, 1, user) if cpuser is not None: replacements["<mm-case-preserved-user>"] = _( """ You are subscribed to this list with the case-preserved address <em>%(cpuser)s</em>.""" ) else: replacements["<mm-case-preserved-user>"] = "" doc.AddItem(mlist.ParseTags("options.html", replacements, userlang))
if dict is not None: try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, Utils.GetCharSet(lang), 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError), e: # The template is really screwed up syslog('error', 'broken template: %s\n%s', filepath, e) # Make sure the text is in the given character set, or html-ify any bogus # characters. return Utils.uncanonstr(text, lang) # Note: I'm overriding most, if not all of the pipermail Article class # here -ddm # The Article class encapsulates a single posting. The attributes are: # # sequence : Sequence number, unique for each article in a set of archives # subject : Subject # datestr : The posting date, in human-readable format # date : The posting date, in purely numeric format # fromdate : The posting date, in `unixfrom' format # headers : Any other headers of interest # author : The author's name (and possibly organization) # email : The author's e-mail address # msgid : A unique message ID
def getValue(self, mlist, kind, varname, params): if varname <> 'subject_prefix': return None # The subject_prefix may be Unicode return Utils.uncanonstr(mlist.subject_prefix, mlist.preferred_language)
def options_page(mlist, doc, user, cpuser, userlang, message=''): # The bulk of the document will come from the options.html template, which # includes it's own html armor (head tags, etc.). Suppress the head that # Document() derived pages get automatically. doc.suppress_head = 1 if mlist.obscure_addresses: presentable_user = Utils.ObscureEmail(user, for_text=1) if cpuser is not None: cpuser = Utils.ObscureEmail(cpuser, for_text=1) else: presentable_user = user fullname = Utils.uncanonstr(mlist.getMemberName(user), userlang) if fullname: presentable_user += ', %s' % Utils.websafe(fullname) # Do replacements replacements = mlist.GetStandardReplacements(userlang) replacements['<mm-results>'] = Bold(FontSize('+1', message)).Format() replacements['<mm-digest-radio-button>'] = mlist.FormatOptionButton( mm_cfg.Digests, 1, user) replacements['<mm-undigest-radio-button>'] = mlist.FormatOptionButton( mm_cfg.Digests, 0, user) replacements['<mm-plain-digests-button>'] = mlist.FormatOptionButton( mm_cfg.DisableMime, 1, user) replacements['<mm-mime-digests-button>'] = mlist.FormatOptionButton( mm_cfg.DisableMime, 0, user) replacements['<mm-global-mime-button>'] = (CheckBox('mime-globally', 1, checked=0).Format()) replacements['<mm-delivery-enable-button>'] = mlist.FormatOptionButton( mm_cfg.DisableDelivery, 0, user) replacements['<mm-delivery-disable-button>'] = mlist.FormatOptionButton( mm_cfg.DisableDelivery, 1, user) replacements['<mm-disabled-notice>'] = mlist.FormatDisabledNotice(user) replacements['<mm-dont-ack-posts-button>'] = mlist.FormatOptionButton( mm_cfg.AcknowledgePosts, 0, user) replacements['<mm-ack-posts-button>'] = mlist.FormatOptionButton( mm_cfg.AcknowledgePosts, 1, user) replacements['<mm-receive-own-mail-button>'] = mlist.FormatOptionButton( mm_cfg.DontReceiveOwnPosts, 0, user) replacements['<mm-dont-receive-own-mail-button>'] = ( mlist.FormatOptionButton(mm_cfg.DontReceiveOwnPosts, 1, user)) replacements['<mm-dont-get-password-reminder-button>'] = ( mlist.FormatOptionButton(mm_cfg.SuppressPasswordReminder, 1, user)) replacements['<mm-get-password-reminder-button>'] = ( mlist.FormatOptionButton(mm_cfg.SuppressPasswordReminder, 0, user)) replacements['<mm-public-subscription-button>'] = ( mlist.FormatOptionButton(mm_cfg.ConcealSubscription, 0, user)) replacements['<mm-hide-subscription-button>'] = mlist.FormatOptionButton( mm_cfg.ConcealSubscription, 1, user) replacements['<mm-dont-receive-duplicates-button>'] = ( mlist.FormatOptionButton(mm_cfg.DontReceiveDuplicates, 1, user)) replacements['<mm-receive-duplicates-button>'] = (mlist.FormatOptionButton( mm_cfg.DontReceiveDuplicates, 0, user)) replacements['<mm-unsubscribe-button>'] = ( mlist.FormatButton('unsub', _('Unsubscribe')) + '<br>' + CheckBox('unsubconfirm', 1, checked=0).Format() + _('<em>Yes, I really want to unsubscribe</em>')) replacements['<mm-new-pass-box>'] = mlist.FormatSecureBox('newpw') replacements['<mm-confirm-pass-box>'] = mlist.FormatSecureBox('confpw') replacements['<mm-change-pass-button>'] = (mlist.FormatButton( 'changepw', _("Change My Password"))) replacements['<mm-other-subscriptions-submit>'] = (mlist.FormatButton( 'othersubs', _('List my other subscriptions'))) replacements['<mm-form-start>'] = (mlist.FormatFormStart( 'options', user, mlist=mlist, contexts=AUTH_CONTEXTS, user=user)) replacements['<mm-user>'] = user replacements['<mm-presentable-user>'] = presentable_user replacements['<mm-email-my-pw>'] = mlist.FormatButton( 'emailpw', (_('Email My Password To Me'))) replacements['<mm-umbrella-notice>'] = (mlist.FormatUmbrellaNotice( user, _("password"))) replacements['<mm-logout-button>'] = (mlist.FormatButton( 'logout', _('Log out'))) replacements['<mm-options-submit-button>'] = mlist.FormatButton( 'options-submit', _('Submit My Changes')) replacements['<mm-global-pw-changes-button>'] = (CheckBox( 'pw-globally', 1, checked=0).Format()) replacements['<mm-global-deliver-button>'] = (CheckBox('deliver-globally', 1, checked=0).Format()) replacements['<mm-global-remind-button>'] = (CheckBox('remind-globally', 1, checked=0).Format()) replacements['<mm-global-nodupes-button>'] = (CheckBox('nodupes-globally', 1, checked=0).Format()) days = int(mm_cfg.PENDING_REQUEST_LIFE / mm_cfg.days(1)) if days > 1: units = _('days') else: units = _('day') replacements['<mm-pending-days>'] = _('%(days)d %(units)s') replacements['<mm-new-address-box>'] = mlist.FormatBox('new-address') replacements['<mm-confirm-address-box>'] = mlist.FormatBox( 'confirm-address') replacements['<mm-change-address-button>'] = mlist.FormatButton( 'change-of-address', _('Change My Address and Name')) replacements['<mm-global-change-of-address>'] = CheckBox( 'changeaddr-globally', 1, checked=0).Format() replacements['<mm-fullname-box>'] = mlist.FormatBox('fullname', value=fullname) # Create the topics radios. BAW: what if the list admin deletes a topic, # but the user still wants to get that topic message? usertopics = mlist.getMemberTopics(user) if mlist.topics: table = Table(border="0") for name, pattern, description, emptyflag in mlist.topics: if emptyflag: continue quotedname = urllib.parse.quote_plus(name) details = Link( mlist.GetScriptURL('options') + '/%s/?VARHELP=%s' % (user, quotedname), ' (Details)') if name in usertopics: checked = 1 else: checked = 0 table.AddRow([ CheckBox('usertopic', quotedname, checked=checked), name + details.Format() ]) topicsfield = table.Format() else: topicsfield = _('<em>No topics defined</em>') replacements['<mm-topics>'] = topicsfield replacements['<mm-suppress-nonmatching-topics>'] = ( mlist.FormatOptionButton(mm_cfg.ReceiveNonmatchingTopics, 0, user)) replacements['<mm-receive-nonmatching-topics>'] = ( mlist.FormatOptionButton(mm_cfg.ReceiveNonmatchingTopics, 1, user)) if cpuser is not None: replacements['<mm-case-preserved-user>'] = _(''' You are subscribed to this list with the case-preserved address <em>%(cpuser)s</em>.''') else: replacements['<mm-case-preserved-user>'] = '' page_text = mlist.ParseTags('options.html', replacements, userlang) if not (mlist.digestable or mlist.getMemberOption(user, mm_cfg.Digests)): page_text = DIGRE.sub('', page_text) doc.AddItem(page_text)
def options_page(mlist, doc, user, cpuser, userlang, message=''): # The bulk of the document will come from the options.html template, which # includes it's own html armor (head tags, etc.). Suppress the head that # Document() derived pages get automatically. doc.suppress_head = 1 if mlist.obscure_addresses: presentable_user = Utils.ObscureEmail(user, for_text=1) if cpuser is not None: cpuser = Utils.ObscureEmail(cpuser, for_text=1) else: presentable_user = user fullname = Utils.uncanonstr(mlist.getMemberName(user), userlang) if fullname: presentable_user += ', %s' % Utils.websafe(fullname) # Do replacements replacements = mlist.GetStandardReplacements(userlang) replacements['<mm-results>'] = Bold(FontSize('+1', message)).Format() replacements['<mm-digest-radio-button>'] = mlist.FormatOptionButton( mm_cfg.Digests, 1, user) replacements['<mm-undigest-radio-button>'] = mlist.FormatOptionButton( mm_cfg.Digests, 0, user) replacements['<mm-plain-digests-button>'] = mlist.FormatOptionButton( mm_cfg.DisableMime, 1, user) replacements['<mm-mime-digests-button>'] = mlist.FormatOptionButton( mm_cfg.DisableMime, 0, user) replacements['<mm-global-mime-button>'] = ( CheckBox('mime-globally', 1, checked=0).Format()) replacements['<mm-delivery-enable-button>'] = mlist.FormatOptionButton( mm_cfg.DisableDelivery, 0, user) replacements['<mm-delivery-disable-button>'] = mlist.FormatOptionButton( mm_cfg.DisableDelivery, 1, user) replacements['<mm-disabled-notice>'] = mlist.FormatDisabledNotice(user) replacements['<mm-dont-ack-posts-button>'] = mlist.FormatOptionButton( mm_cfg.AcknowledgePosts, 0, user) replacements['<mm-ack-posts-button>'] = mlist.FormatOptionButton( mm_cfg.AcknowledgePosts, 1, user) replacements['<mm-receive-own-mail-button>'] = mlist.FormatOptionButton( mm_cfg.DontReceiveOwnPosts, 0, user) replacements['<mm-dont-receive-own-mail-button>'] = ( mlist.FormatOptionButton(mm_cfg.DontReceiveOwnPosts, 1, user)) replacements['<mm-dont-get-password-reminder-button>'] = ( mlist.FormatOptionButton(mm_cfg.SuppressPasswordReminder, 1, user)) replacements['<mm-get-password-reminder-button>'] = ( mlist.FormatOptionButton(mm_cfg.SuppressPasswordReminder, 0, user)) replacements['<mm-public-subscription-button>'] = ( mlist.FormatOptionButton(mm_cfg.ConcealSubscription, 0, user)) replacements['<mm-hide-subscription-button>'] = mlist.FormatOptionButton( mm_cfg.ConcealSubscription, 1, user) replacements['<mm-dont-receive-duplicates-button>'] = ( mlist.FormatOptionButton(mm_cfg.DontReceiveDuplicates, 1, user)) replacements['<mm-receive-duplicates-button>'] = ( mlist.FormatOptionButton(mm_cfg.DontReceiveDuplicates, 0, user)) replacements['<mm-unsubscribe-button>'] = ( mlist.FormatButton('unsub', _('Unsubscribe')) + '<br>' + CheckBox('unsubconfirm', 1, checked=0).Format() + _('<em>Yes, I really want to unsubscribe</em>')) replacements['<mm-new-pass-box>'] = mlist.FormatSecureBox('newpw') replacements['<mm-confirm-pass-box>'] = mlist.FormatSecureBox('confpw') replacements['<mm-change-pass-button>'] = ( mlist.FormatButton('changepw', _("Change My Password"))) replacements['<mm-other-subscriptions-submit>'] = ( mlist.FormatButton('othersubs', _('List my other subscriptions'))) replacements['<mm-form-start>'] = ( mlist.FormatFormStart('options', user)) replacements['<mm-user>'] = user replacements['<mm-presentable-user>'] = presentable_user replacements['<mm-email-my-pw>'] = mlist.FormatButton( 'emailpw', (_('Email My Password To Me'))) replacements['<mm-umbrella-notice>'] = ( mlist.FormatUmbrellaNotice(user, _("password"))) replacements['<mm-logout-button>'] = ( mlist.FormatButton('logout', _('Log out'))) replacements['<mm-options-submit-button>'] = mlist.FormatButton( 'options-submit', _('Submit My Changes')) replacements['<mm-global-pw-changes-button>'] = ( CheckBox('pw-globally', 1, checked=0).Format()) replacements['<mm-global-deliver-button>'] = ( CheckBox('deliver-globally', 1, checked=0).Format()) replacements['<mm-global-remind-button>'] = ( CheckBox('remind-globally', 1, checked=0).Format()) replacements['<mm-global-nodupes-button>'] = ( CheckBox('nodupes-globally', 1, checked=0).Format()) days = int(mm_cfg.PENDING_REQUEST_LIFE / mm_cfg.days(1)) if days > 1: units = _('days') else: units = _('day') replacements['<mm-pending-days>'] = _('%(days)d %(units)s') replacements['<mm-new-address-box>'] = mlist.FormatBox('new-address') replacements['<mm-confirm-address-box>'] = mlist.FormatBox( 'confirm-address') replacements['<mm-change-address-button>'] = mlist.FormatButton( 'change-of-address', _('Change My Address and Name')) replacements['<mm-global-change-of-address>'] = CheckBox( 'changeaddr-globally', 1, checked=0).Format() replacements['<mm-fullname-box>'] = mlist.FormatBox( 'fullname', value=fullname) gpgkey = mlist.getGPGKey(user) if gpgkey==None: gpgkey="" replacements['<mm-gpgkey-box>'] = ( '<textarea name="gpgkey" rows=10 cols=80>%s</textarea>' % gpgkey) replacements['<mm-global-gpgkey-changes-button>'] = ( CheckBox('gpgkey-globally', 1, checked=0).Format()) replacements['<mm-change-gpgkey-button>'] = ( mlist.FormatButton('submitgpgkey', _('Submit GPG key'))) smimekey = mlist.getSMIMEKey(user) if not smimekey: smimekey="" replacements['<mm-smimekey-box>'] = ( '<textarea name="smimekey" rows=10 cols=80>%s</textarea>' % smimekey) replacements['<mm-global-smimekey-changes-button>'] = ( CheckBox('smimekey-globally', 1, checked=0).Format()) replacements['<mm-change-smimekey-button>'] = ( mlist.FormatButton('submitsmimekey', _('Submit S/MIME key'))) # Create the topics radios. BAW: what if the list admin deletes a topic, # but the user still wants to get that topic message? usertopics = mlist.getMemberTopics(user) if mlist.topics: table = Table(border="0") for name, pattern, description, emptyflag in mlist.topics: if emptyflag: continue quotedname = urllib.quote_plus(name) details = Link(mlist.GetScriptURL('options') + '/%s/?VARHELP=%s' % (user, quotedname), ' (Details)') if name in usertopics: checked = 1 else: checked = 0 table.AddRow([CheckBox('usertopic', quotedname, checked=checked), name + details.Format()]) topicsfield = table.Format() else: topicsfield = _('<em>No topics defined</em>') replacements['<mm-topics>'] = topicsfield replacements['<mm-suppress-nonmatching-topics>'] = ( mlist.FormatOptionButton(mm_cfg.ReceiveNonmatchingTopics, 0, user)) replacements['<mm-receive-nonmatching-topics>'] = ( mlist.FormatOptionButton(mm_cfg.ReceiveNonmatchingTopics, 1, user)) if cpuser is not None: replacements['<mm-case-preserved-user>'] = _(''' You are subscribed to this list with the case-preserved address <em>%(cpuser)s</em>.''') else: replacements['<mm-case-preserved-user>'] = '' doc.AddItem(mlist.ParseTags('options.html', replacements, userlang))
try: sdict = SafeDict(dict) try: text = sdict.interpolate(template) except UnicodeError: # Try again after coercing the template to unicode utemplate = unicode(template, Utils.GetCharSet(lang), 'replace') text = sdict.interpolate(utemplate) except (TypeError, ValueError), e: # The template is really screwed up syslog('error', 'broken template: %s\n%s', filepath, e) # Make sure the text is in the given character set, or html-ify any bogus # characters. return Utils.uncanonstr(text, lang) # Note: I'm overriding most, if not all of the pipermail Article class # here -ddm # The Article class encapsulates a single posting. The attributes are: # # sequence : Sequence number, unique for each article in a set of archives # subject : Subject # datestr : The posting date, in human-readable format # date : The posting date, in purely numeric format # fromdate : The posting date, in `unixfrom' format # headers : Any other headers of interest # author : The author's name (and possibly organization) # email : The author's e-mail address
def CGIescape(arg, lang=None): if isinstance(arg, types.UnicodeType): s = Utils.websafe(arg) else: s = Utils.websafe(str(arg)) return Utils.uncanonstr(s.replace('"', '"'), lang)
def escape(self, value): # transforms accents into html entities (é) # TODO: find out which language is current (here: assumes iso-8859-1) value = Utils.uncanonstr(value) return value