]> khamidou — GitHub mirrors - flanker.git/commit
work harder to avoid re-serializing headers
authorJeremy Schlatter <jeremy.schlatter@gmail.com>
Wed, 10 Jun 2015 00:09:40 +0000 (17:09 -0700)
committerJeremy Schlatter <jeremy.schlatter@gmail.com>
Wed, 10 Jun 2015 00:09:40 +0000 (17:09 -0700)
commitcd271929bf831999c40e616da3dfacd3694eae56
treebe64e9ccde401968c33d54253ecd6799117b6fda
parent2c757154c54694de9a2f4bd89b090b34091972e8
work harder to avoid re-serializing headers

**Purpose**

We want to avoid re-serializing parsed messages, for two reasons:

1. It's slow. We already have the original text, so if we can output it
   as-is we save a bunch of work.
2. It canonicalizes headers. This can break DKIM signatures, which hurts
   deliverability.

**Implementation**

This commit does three things:

1. `message.headers["some-header"] = "some value"` now causes a prepend
   if "some-header" is not present in the message yet. Prepends are
   better than arbitrary insertions, because they do not force us to
   re-serialize the rest of the message.
2. `message.headers.add("some-header, "some value")` now causes a
   prepend, for the same reason as 1. This previously added the header
   at the end of the list instead. I am assuming this behavior change is OK.
3. `message.body = message.body` no longer causes the message to be
   marked as changed.

Related commit: 9c89b875dc0eafc01c7f9725d5db5aff8f798f70
flanker/mime/message/headers/headers.py
flanker/mime/message/part.py
tests/mime/message/fallback/fallback_test.py
tests/mime/message/headers/headers_test.py
tests/mime/message/scanner_test.py