Merge lp:~abentley/launchpad/find-merge-directive into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Merged at revision: not available
Proposed branch: lp:~abentley/launchpad/find-merge-directive
Merge into: lp:launchpad
Diff against target: 53 lines (+31/-1)
2 files modified
lib/lp/code/mail/codehandler.py (+2/-1)
lib/lp/code/mail/tests/test_codehandler.py (+29/-0)
To merge this branch: bzr merge lp:~abentley/launchpad/find-merge-directive
Reviewer Review Type Date Requested Status
Gavin Panella (community) code Approve
Review via email: mp+20705@code.launchpad.net

Commit message

Fix content-type bugs

Description of the change

= Summary =
Fix bug #506835: findMergeDirectiveAndComment fails if no Content-Type
Fix bug #530455: content type fail parsing merge directive

== Proposed fix ==
Do case-insensitive comparison of content-type, and if there is no
Content-Type, pretend it was text/plain.

== Pre-implementation notes ==
None

== Implementation details ==
None

== Tests ==
bin/test -t findMergeDirective codehandler

== Demo and Q/A ==
Send a merge directive email with no content-type to <email address hidden>.
Send a merge directive email with a mixed-case content-type to
<email address hidden>.

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/code/mail/codehandler.py
  lib/lp/code/mail/tests/test_codehandler.py

== Pylint notices ==

lib/lp/code/mail/codehandler.py
    37: [F0401] Unable to import 'lazr.uri' (No module named uri)

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Looks good. Two questions:

 * The test docstrings look like they've been copy-n-pasted.

 * Is it necessary to commit at the end of each test? If so, could you add a short comment explaining why?

review: Approve (code)
Revision history for this message
Aaron Bentley (abentley) wrote :

The commits aren't necessary, and I've fixed the docstrings.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/mail/codehandler.py'
2--- lib/lp/code/mail/codehandler.py 2010-02-10 15:04:00 +0000
3+++ lib/lp/code/mail/codehandler.py 2010-03-05 14:45:47 +0000
4@@ -541,7 +541,8 @@
5 if part.is_multipart():
6 continue
7 payload = part.get_payload(decode=True)
8- if part['Content-type'].startswith('text/plain'):
9+ content_type = part.get('Content-type', 'text/plain').lower()
10+ if content_type.startswith('text/plain'):
11 body = payload
12 charset = part.get_param('charset')
13 if charset is not None:
14
15=== modified file 'lib/lp/code/mail/tests/test_codehandler.py'
16--- lib/lp/code/mail/tests/test_codehandler.py 2010-02-10 17:05:36 +0000
17+++ lib/lp/code/mail/tests/test_codehandler.py 2010-03-05 14:45:47 +0000
18@@ -436,6 +436,35 @@
19 self.assertEqual('', comment)
20 transaction.commit()
21
22+ def test_findMergeDirectiveAndComment_no_content_type(self):
23+ """Parts with no content-type are treated as text/plain."""
24+ md = self.factory.makeMergeDirective()
25+ message = self.factory.makeSignedMessage(
26+ body='', attachment_contents=''.join(md.to_lines()))
27+ body = message.get_payload()[0]
28+ del body['Content-type']
29+ body.set_payload('body')
30+ self.switchDbUser(config.processmail.dbuser)
31+ code_handler = CodeHandler()
32+ comment, md2 = code_handler.findMergeDirectiveAndComment(message)
33+ self.assertEqual('body', comment)
34+
35+ def test_findMergeDirectiveAndComment_case_insensitive(self):
36+ """findMergeDirectiveAndComment uses case-insensitive content-type."""
37+ md = self.factory.makeMergeDirective()
38+ message = self.factory.makeSignedMessage(
39+ body='', attachment_contents=''.join(md.to_lines()))
40+ body = message.get_payload()[0]
41+ # Unlike dicts, messages append when you assign to a key. So
42+ # we must delete the first Content-type before adding another.
43+ del body['Content-type']
44+ body['Content-type'] = 'Text/Plain'
45+ body.set_payload('body')
46+ self.switchDbUser(config.processmail.dbuser)
47+ code_handler = CodeHandler()
48+ comment, md2 = code_handler.findMergeDirectiveAndComment(message)
49+ self.assertEqual('body', comment)
50+
51 def test_findMergeDirectiveAndCommentUnicodeBody(self):
52 """findMergeDirectiveAndComment returns unicode comments."""
53 md = self.factory.makeMergeDirective()