• Remember Mailing List

Re: Why fullname cannot be a unicode string?

from Rob Miller on Jul 29, 2008 02:46 PM
Claudio Battaglino wrote:
> This is the "register" method into the file remember/content/member.py 
> (remember 1.0rc1):
> 
> 
>    def register(self):
>        """
>        perform any registration information necessary after a member is 
> registered
>        """
>        rtool = getToolByName(self, 'portal_registration')
>        site_props = getToolByName(self, 
> 'portal_properties').site_properties
> 
>        # XXX unicode names break sending the email
>        unicode_name = self.getFullname()
>        self.setFullname(str(unicode_name))
>        if site_props.validate_email or self.getMail_me():
>            rtool.registeredNotify(self.getUserName())

you left out the next line:

          self.setFullname(unicode_name)

which sets the fullname back to its original unicode value.  considering this, 
and the comment which says "unicode names break sending the email", it's clear 
that this code is a bit of a hackish workaround.  if the fullname is a unicode 
string, then something in the registeredNotify call can have problems when 
using that fullname to send emails.

you're right that this isn't very robust, though.  the code should probably 
look something like this:

         reset_fullname = False
         unicode_name = self.getFullname()
         if type(unicode_name) == unicode:
             self.setFullname(unicode_name.encode('utf-8', 'replace')
             reset_fullname = True
         if site_props.validate_email or self.getMail_me():
             rtool.registeredNotify(self.getUserName())

         if reset_fullname:
             self.setFullname(unicode_name)

try this out, see if it works for you.  i'm pretty sure it will... if so, i'll 
work on writing a test that demonstrates the problem and committing this to 
the remember trunk.  faster turnaround guaranteed if you (or anyone out there 
in remember-list-land) writes and commits a failing test that demonstrates the 
problem.

-r
Return to date view: threaded or flat