Rev 27: Cleanup from review comments by Marius Gedminas in http://bzr.arbash-meinel.com/plugins/email
John Arbash Meinel
john at arbash-meinel.com
Fri Jan 26 15:24:01 GMT 2007
------------------------------------------------------------
revno: 27
revision-id: john at arbash-meinel.com-20070126152332-4fnp2osfss3a4eoc
parent: john at arbash-meinel.com-20070125231227-d9ff9bxynpk6gtj9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: email
timestamp: Fri 2007-01-26 09:23:32 -0600
message:
Cleanup from review comments by Marius Gedminas
modified:
README README-20051018071212-c081f89570802202
emailer.py emailer.py-20070123220937-ec5y2n2oeoa0p4ue-1
smtp_connection.py smtp_connection.py-20070125220755-k6ueimjqwn16wvr9-1
tests/test_smtp_connection.py test_smtp_connection-20070125220755-k6ueimjqwn16wvr9-2
-------------- next part --------------
=== modified file 'README'
--- a/README 2007-01-25 23:04:53 +0000
+++ b/README 2007-01-26 15:23:32 +0000
@@ -23,7 +23,7 @@
configure the settings "smtp_server=host[:port]", "smtp_username=userid",
"smtp_password". If "smtp_username" is set but "smtp_password" is not, you
will be prompted for a password.
-Also, if using 'smtplib', the messages will be sent as a utf-8 text message,
+Also, if using 'smtplib', the messages will be sent as a UTF-8 text message,
with a 8-bit text diff attached (rather than all-as-one). Work has also been
done to make sure usernames do not have to be ascii.
=== modified file 'emailer.py'
--- a/emailer.py 2007-01-25 22:08:12 +0000
+++ b/emailer.py 2007-01-26 15:23:32 +0000
@@ -47,7 +47,8 @@
# use 'replace' so that we don't abort if trying to write out
# in e.g. the default C locale.
- # We must use StringIO.StringIO because we want a Unicode string
+ # We must use StringIO.StringIO because we want a Unicode string that
+ # we can pass to send_email and have that do the proper encoding.
from StringIO import StringIO
outf = StringIO()
lf = log_formatter('long',
@@ -87,12 +88,12 @@
tree_new = self.branch.repository.revision_tree(revid_new)
tree_old = self.branch.repository.revision_tree(revid_old)
- # We want a cStringIO because we want an 8-bit string
+ # We can use a cStringIO because show_diff_trees should only write
+ # 8-bit strings. It is an error to write a Unicode string here.
from cStringIO import StringIO
diff_content = StringIO()
show_diff_trees(tree_old, tree_new, diff_content)
- lines = diff_content.getvalue().split("\n")
- numlines = len(lines)
+ numlines = diff_content.getvalue().count('\n')+1
if numlines <= difflimit:
return diff_content.getvalue()
else:
@@ -101,7 +102,7 @@
% (numlines, difflimit))
def difflimit(self):
- """maximum number of lines of diff to show."""
+ """Maximum number of lines of diff to show."""
result = self.config.get_user_option('post_commit_difflimit')
if result is None:
result = 1000
=== modified file 'smtp_connection.py'
--- a/smtp_connection.py 2007-01-25 23:12:27 +0000
+++ b/smtp_connection.py 2007-01-26 15:23:32 +0000
@@ -126,7 +126,7 @@
# Which is how Thunderbird does it
from_user, from_email = self._split_address(from_address)
- msg['From'] = '%s <%s>' % (Header(from_user, 'utf8'), from_email)
+ msg['From'] = '%s <%s>' % (Header(unicode(from_user)), from_email)
msg['User-Agent'] = 'bzr/%s' % _bzrlib_version
to_emails = []
@@ -134,7 +134,7 @@
for addr in to_addresses:
to_user, to_email = self._split_address(addr)
to_emails.append(to_email)
- to_header.append('%s <%s>' % (Header(to_user, 'utf8'), to_email))
+ to_header.append('%s <%s>' % (Header(unicode(to_user)), to_email))
msg['To'] = ', '.join(to_header)
msg['Subject'] = Header(subject)
=== modified file 'tests/test_smtp_connection.py'
--- a/tests/test_smtp_connection.py 2007-01-25 22:54:39 +0000
+++ b/tests/test_smtp_connection.py 2007-01-26 15:23:32 +0000
@@ -65,7 +65,7 @@
def get_connection(self, text):
my_config = config.GlobalConfig()
config_file = StringIO(text)
- (my_config._get_parser(config_file))
+ my_config._get_parser(config_file)
return InstrumentedSMTPConnection(my_config)
def test_defaults(self):
@@ -123,9 +123,9 @@
self.assertEqualDiff((
'Content-Type: multipart/mixed; boundary="=====123456=="\n'
'MIME-Version: 1.0\n'
- 'From: =?utf8?q?Jerry_F=C2=B5z?= <jerry at fooz.com>\n'
+ 'From: =?utf-8?q?Jerry_F=C2=B5z?= <jerry at fooz.com>\n'
'User-Agent: bzr/%s\n'
- 'To: =?utf8?q?Biz_N=C3=A5?= <biz at na.com>\n'
+ 'To: =?utf-8?q?Biz_N=C3=A5?= <biz at na.com>\n'
'Subject: =?utf-8?q?Hello_Biz_N=C3=A5?=\n'
'\n'
'--=====123456==\n'
@@ -160,9 +160,9 @@
self.assertEqualDiff((
'Content-Type: multipart/mixed; boundary="=====123456=="\n'
'MIME-Version: 1.0\n'
- 'From: =?utf8?q?Jerry_F=C2=B5z?= <jerry at fooz.com>\n'
+ 'From: =?utf-8?q?Jerry_F=C2=B5z?= <jerry at fooz.com>\n'
'User-Agent: bzr/%s\n'
- 'To: =?utf8?q?Biz_N=C3=A5?= <biz at na.com>\n'
+ 'To: =?utf-8?q?Biz_N=C3=A5?= <biz at na.com>\n'
'Subject: =?utf-8?q?Hello_Biz_N=C3=A5?=\n'
'\n'
'--=====123456==\n'
@@ -222,9 +222,9 @@
self.assertEqualDiff((
'Content-Type: multipart/mixed; boundary="=====123456=="\n'
'MIME-Version: 1.0\n'
- 'From: =?utf8?q?Joe_Foo?= <joe at foo.com>\n'
+ 'From: Joe Foo <joe at foo.com>\n'
'User-Agent: bzr/%s\n'
- 'To: =?utf8?q?Jane_Foo?= <jane at foo.com>, =?utf8?q?Barry_Foo?= <barry at foo.com>\n'
+ 'To: Jane Foo <jane at foo.com>, Barry Foo <barry at foo.com>\n'
'Subject: Hi Jane and Barry\n'
'\n'
'--=====123456==\n'
More information about the bazaar-commits
mailing list