witten
/
luminotes
Archived
1
0
Fork 0

Fixed a bug where an invite sent for a notebook with an accented unicode

name would cause a UnicodeEncodeError upon sending the invite email. Now
such invites are encoded as quoted-printable UTF-8, while other invites
continue to be 7-bit ASCII.
This commit is contained in:
Dan Helfman 2008-05-06 23:29:43 +00:00
parent bb77cefeaa
commit 70f52a7406
3 changed files with 78 additions and 7 deletions

6
NEWS
View File

@ -1,3 +1,9 @@
1.3.16: May 6, 2008
* Fixed a bug where an invite sent for a notebook with an accented unicode
name would cause a UnicodeEncodeError upon sending the invite email. Now
such invites are encoded as quoted-printable UTF-8, while other invites
continue to be 7-bit ASCII.
1.3.15: May 6, 2008
* Fixed a bug where the "show on startup" checkbox did not appear checked if
you created a startup note, hid it, and then opened it the note tree area.

View File

@ -835,7 +835,7 @@ class Users( object ):
raise Invite_error( u"Please enter at least one valid email address." )
import smtplib
from email import Message
from email import Message, Charset
for email_address in email_addresses_list:
# record the sending of this invite email
@ -868,11 +868,22 @@ class Users( object ):
message[ u"Sender" ] = u"Luminotes personal wiki <%s>" % self.__support_email
message[ u"To" ] = email_address
message[ u"Subject" ] = notebook_name
message.set_payload(
u"I've shared a wiki with you called \"%s\".\n" % notebook_name +
u"Please visit the following link to view it online:\n\n" +
payload = \
u"I've shared a wiki with you called \"%s\".\n" % notebook_name + \
u"Please visit the following link to view it online:\n\n" + \
u"%s/i/%s\n\n" % ( self.__https_url or self.__http_url, invite.object_id )
)
# try representing the payload as plain 7-bit ASCII for greatest compatibility
try:
str( notebook_name )
message.set_payload( payload )
# if that doesn't work, encode the payload as UTF-8 instead
except UnicodeEncodeError:
message.set_payload( payload.encode( "utf-8" ) )
charset = Charset.Charset( "utf-8" )
charset.body_encoding = Charset.QP
message.set_charset( charset )
# send the message out through localhost's smtp server
server = smtplib.SMTP()

View File

@ -378,7 +378,6 @@ class Test_users( Test_controller ):
), session_id = self.session_id )
print result
assert u"not configured" in result[ u"error" ]
def test_demo( self ):
@ -1094,6 +1093,62 @@ class Test_users( Test_controller ):
assert invite.read_write is False
assert invite.owner is False
def test_send_invites_with_unicode_notebook_name( self ):
# trick send_invites() into using a fake SMTP server
Stub_smtp.reset()
smtplib.SMTP = Stub_smtp
self.login()
self.user.rate_plan = 1
self.database.save( self.user )
self.notebooks[ 0 ].name = u"\xe4"
quoted_printable_notebook_name = u"=C3=A4"
self.database.save( self.notebooks[ 0 ] )
email_addresses_list = [ u"foo@example.com" ]
email_addresses = email_addresses_list[ 0 ]
result = self.http_post( "/users/send_invites", dict(
notebook_id = self.notebooks[ 0 ].object_id,
email_addresses = email_addresses,
access = u"viewer",
invite_button = u"send invites",
), session_id = self.session_id )
session_id = result[ u"session_id" ]
assert u"An invitation has been sent." in result[ u"message" ]
invites = result[ u"invites" ]
assert len( invites ) == 1
invite = invites[ -1 ]
assert invite
assert invite.read_write is False
assert invite.owner is False
assert smtplib.SMTP.connected == False
assert len( smtplib.SMTP.emails ) == 1
from email.Message import Message, Charset
( from_address, to_addresses, message ) = smtplib.SMTP.emails[ 0 ]
assert self.email_address in from_address
assert to_addresses == email_addresses_list
assert u'Content-Type: text/plain; charset="utf-8"' in message
assert u'Content-Transfer-Encoding: quoted-printable' in message
assert quoted_printable_notebook_name in message
matches = self.INVITE_LINK_PATTERN.search( message )
invite_id = matches.group( 2 )
assert invite_id
# assert that the invite has the read_write / owner flags set appropriately
invites = self.database.objects.get( invite_id )
assert invites
assert len( invites ) == 1
invite = invites[ -1 ]
assert invite
assert invite.read_write is False
assert invite.owner is False
def test_send_invites_collaborator( self ):
# trick send_invites() into using a fake SMTP server
Stub_smtp.reset()
@ -2286,7 +2341,6 @@ class Test_users( Test_controller ):
self.user.sql_load_notebooks()
notebooks = self.database.select_many( Notebook, self.user2.sql_load_notebooks() )
new_notebook = [ notebook for notebook in notebooks if notebook.object_id == invite.notebook_id ][ 0 ]
print new_notebook.rank
assert new_notebook.rank == 8 # one higher than the other notebook this user has access to
assert invite.redeemed_user_id == self.user2.object_id