Perform >From quoting as described by RFC 4155

https://www.rfc-editor.org/rfc/rfc4155.txt
http://qmail.org/qmail-manual-html/man5/mbox.html

> The program then copies the message, applying >From quoting
> to each line.  >From quoting ensures that the resulting
> lines are not From_ lines:  the program prepends a > to any
> From_ line, >From_ line, >>From_ line, >>>From_ line, etc.
This commit is contained in:
Sami Samhuri 2021-12-28 15:22:49 -08:00
parent 0cc27cd570
commit 8a080fb076
No known key found for this signature in database
GPG key ID: 4B4195422742FC16
2 changed files with 12 additions and 0 deletions

View file

@ -167,6 +167,7 @@ def download_messages(server, filename, messages, config):
spinner = Spinner("Downloading %s new messages to %s" % (len(messages), filename), spinner = Spinner("Downloading %s new messages to %s" % (len(messages), filename),
config['nospinner']) config['nospinner'])
total = biggest = 0 total = biggest = 0
from_re = re.compile("\n(>*)From ")
# each new message # each new message
for msg_id in messages.keys(): for msg_id in messages.keys():
@ -190,6 +191,11 @@ def download_messages(server, filename, messages, config):
# This avoids Thunderbird mistaking a line starting "From " as the start # This avoids Thunderbird mistaking a line starting "From " as the start
# of a new message. _Might_ also apply to other mail lients - unknown # of a new message. _Might_ also apply to other mail lients - unknown
text = text.replace("\nFrom ", "\n From ") text = text.replace("\nFrom ", "\n From ")
else:
# Perform >From quoting as described by RFC 4155 and the qmail docs.
# https://www.rfc-editor.org/rfc/rfc4155.txt
# http://qmail.org/qmail-manual-html/man5/mbox.html
text = from_re.sub("\n>\\1From ", text)
mbox.write(text) mbox.write(text)
mbox.write('\n\n') mbox.write('\n\n')

View file

@ -155,6 +155,7 @@ def download_messages(server, filename, messages, overwrite, nospinner, thunderb
spinner = Spinner("Downloading %s new messages to %s" % (len(messages), filename), spinner = Spinner("Downloading %s new messages to %s" % (len(messages), filename),
nospinner) nospinner)
total = biggest = 0 total = biggest = 0
from_re = re.compile(b"\n(>*)From ")
# each new message # each new message
for msg_id in messages.keys(): for msg_id in messages.keys():
@ -183,6 +184,11 @@ def download_messages(server, filename, messages, overwrite, nospinner, thunderb
# This avoids Thunderbird mistaking a line starting "From " as the start # This avoids Thunderbird mistaking a line starting "From " as the start
# of a new message. _Might_ also apply to other mail lients - unknown # of a new message. _Might_ also apply to other mail lients - unknown
text_bytes = text_bytes.replace(b"\nFrom ", b"\n From ") text_bytes = text_bytes.replace(b"\nFrom ", b"\n From ")
else:
# Perform >From quoting as described by RFC 4155 and the qmail docs.
# https://www.rfc-editor.org/rfc/rfc4155.txt
# http://qmail.org/qmail-manual-html/man5/mbox.html
text_bytes = from_re.sub(b"\n>\\1From ", text_bytes)
mbox.write(text_bytes) mbox.write(text_bytes)
mbox.write(b'\n\n') mbox.write(b'\n\n')