Skip to content

Commit 2ae7247

Browse files
committed
Strip newlines from mulitline headers
As per the RFC https://tools.ietf.org/html/rfc3028 > Folding of long header lines (as described in [IMAIL] 3.4.8) is > removed prior to interpretation of the data. The folding syntax (the > CRLF that ends a line plus any leading whitespace at the beginning of > the next line that indicates folding) are interpreted as if they were > a single space.
1 parent a707d10 commit 2ae7247

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

sifter/tests/header.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import re
12
import sifter.grammar
23
import sifter.grammar.string
34
import sifter.validators
45

56
__all__ = ('TestHeader',)
67

8+
# Newline striping
9+
_newline_re = re.compile(r'\n+\s+')
10+
711
# section 5.7
812
class TestHeader(sifter.grammar.Test):
913

@@ -35,6 +39,7 @@ def evaluate(self, message, state):
3539
for header in self.headers:
3640
header = sifter.grammar.string.expand_variables(header, state)
3741
for value in message.get_all(header, []):
42+
value = _newline_re.sub(" ", value)
3843
for key in self.keylist:
3944
key = sifter.grammar.string.expand_variables(key, state)
4045
if sifter.grammar.string.compare(str(value), key, state,

0 commit comments

Comments
 (0)