From: Régis R. <svn...@pl...> - 2011-10-10 19:35:42
|
Author: regisrouet Date: Mon Oct 10 19:33:59 2011 New Revision: 245357 Modified: Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/browser/registration.py Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/browser/subscribers.py Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/content/EasyNewsletter.py Log: assume email can contain special chars (even if isEmail doesn't now) just use "-at-" as normalize change "--" in "-" Modified: Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/browser/registration.py ============================================================================== --- Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/browser/registration.py (original) +++ Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/browser/registration.py Mon Oct 10 19:33:59 2011 @@ -44,6 +44,8 @@ salutation = self.request.get("salutation", "") organization = self.request.get("organization", "") subscription = self.request.get("subscription", "") + props = getToolByName(self, "portal_properties").site_properties + charset = props.getProperty("default_charset") path_to_easynewsletter = self.request.get("newsletter") # remove leading slash from paths like: /mynewsletter path_to_easynewsletter = path_to_easynewsletter.strip('/') @@ -59,7 +61,7 @@ messages.addStatusMessage(_("Please enter a valid email address."), "error") return self.request.response.redirect(newsletter_container.absolute_url()) - subscriber_info = newsletter_container.getSubscriberInfo(subscriber) + subscriber_info = newsletter_container.getSubscriberInfo(unicode(subscriber, charset)) subscribed = subscriber_info is not None if subscription == "unsubscription" and subscribed: msg_subject = newsletter_container.unsubscriber_confirmation_mail_subject @@ -97,8 +99,6 @@ msg_text = msg_text.replace("${newsletter_title}", newsletter_container.Title()) msg_text = msg_text.replace("${subscriber_email}", subscriber) - props = getToolByName(self, "portal_properties").site_properties - charset = props.getProperty("default_charset") msg = MIMEText(msg_text, "plain", charset) # don't use Header() with a str and a charset arg, even if it is correct # this would generate a encoded header and mail server may not support utf-8 encoded email address @@ -118,12 +118,14 @@ def confirm_subscriber(self): hashkey = self.request.get('hkey') + props = getToolByName(self, "portal_properties").site_properties + charset = props.getProperty("default_charset") enl_registration_tool = queryUtility(IENLRegistrationTool, 'enl_registration_tool') regdataobj = enl_registration_tool.get(hashkey) messages = IStatusMessage(self.request) if regdataobj: easynewsletter = self.portal.restrictedTraverse(regdataobj.path_to_easynewsletter) - if easynewsletter.getSubscriberInfo(regdataobj.subscriber) is not None: + if easynewsletter.getSubscriberInfo(unicode(regdataobj.subscriber, charset)) is not None: del enl_registration_tool[hashkey] messages.addStatusMessage(_('This email address is already registered.')) else: Modified: Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/browser/subscribers.py ============================================================================== --- Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/browser/subscribers.py (original) +++ Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/browser/subscribers.py Mon Oct 10 19:33:59 2011 @@ -16,6 +16,9 @@ CSV_HEADER = ['salutation', 'fullname', 'email', 'organization', ] +import logging +logger = logging.getLogger("Products.EasyNewsletter.subscribers") + class IEnl_Subscribers_View(Interface): """ @@ -122,8 +125,8 @@ fullname = subscriber[1] email = subscriber[2] organization = subscriber[3] - id = context.getNewSubscriberId(email) - if context.getSubscriberInfo(email) is not None: + id = context.getNewSubscriberId(email.decode(encoding)) + if context.getSubscriberInfo(email.decode(encoding)) is not None: msg = _('This email address is already registered.') fail.append( {'salutation': salutation, @@ -147,7 +150,7 @@ title=title, description="") sub = context[id] - sub.email = email + sub.email = email.decode(encoding) sub.fullname = fullname.decode(encoding) sub.organization = organization.decode(encoding) sub.salutation = salutation.decode(encoding) Modified: Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/content/EasyNewsletter.py ============================================================================== --- Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/content/EasyNewsletter.py (original) +++ Products.EasyNewsletter/branches/bpi-rouet-2011-09/Products/EasyNewsletter/content/EasyNewsletter.py Mon Oct 10 19:33:59 2011 @@ -439,7 +439,9 @@ def addSubscriber(self, email, fullname, organization, salutation=None): """Adds a new subscriber to the newsletter (if valid). """ - subscriber_id = self.getNewSubscriberId(email) + props = getToolByName(self, "portal_properties").site_properties + charset = props.getProperty("default_charset") + subscriber_id = self.getNewSubscriberId(email.decode(charset)) if subscriber_id is None: logger.warning("subscriber_id is None when adding subscriber [%s]", email) return False @@ -552,13 +554,15 @@ result.append('<%s>' % self.senderEmail) return result - def getNewSubscriberId(self, email=u''): + def getNewSubscriberId(self, email): + """compute id from email (unicode) + """ plone_utils = getToolByName(self, 'plone_utils') id = email id = DASH_RE.sub(u"-dash-", id) # first id = DOT_RE.sub(u"-dot-", id) id = UNDERSCORE_RE.sub(u"-udsr-", id) - id = AT_RE.sub(u"--at--", id) + id = AT_RE.sub(u"-at-", id) id = plone_utils.normalizeString(id) if id in self.objectIds(): if email != self[id].getEmail(): @@ -566,7 +570,9 @@ return None return id - def getSubscriberInfo(self, email=u''): + def getSubscriberInfo(self, email): + """get subscriber info from email (unicode) + """ catalog = getToolByName(self, 'portal_catalog') for brain in catalog.unrestrictedSearchResults(portal_type = 'ENLSubscriber', path='/'.join(self.getPhysicalPath()), |