[Bug 6925] New: patchbomb: hg email fails with "Message contains bare LF and is violating 822.bis section 2.3"

mercurial-bugs at mercurial-scm.org mercurial-bugs at mercurial-scm.org
Sat Oct 5 09:41:11 UTC 2024


https://bz.mercurial-scm.org/show_bug.cgi?id=6925

            Bug ID: 6925
           Summary: patchbomb: hg email fails with "Message contains bare
                    LF and is violating 822.bis section 2.3"
           Product: Mercurial
           Version: stable branch
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: bug
          Priority: wish
         Component: patchbomb
          Assignee: bugzilla at mercurial-scm.org
          Reporter: a.mux at inwind.it
                CC: mercurial-devel at mercurial-scm.org
    Python Version: ---

For some time now the "hg email" command fails with the following error:
    abort: (552, b'Message contains bare LF and is violating 822.bis section
2.3')

See for example this message on the TortoiseHg mailing list from 2024-04-10,
the current hg version then was 6.5.3:
https://groups.google.com/g/thg-dev/c/koxRO6uV7vI

I am not really sure if the problem is just happening on my system.

Nonetheless, I see that patchbomb is using the default policy for sending the
mail, and the python documentation states the following (at
https://docs.python.org/3.12/library/email.policy.html#email.policy.Policy.linesep):

    The string to be used to terminate lines in serialized output.
    The default is \n because that’s the internal end-of-line discipline
    used by Python, though \r\n is required by the RFCs.

I fixed this problem adding a linesep parameter to the generator.flatten()
call:

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -1000,7 +1000,7 @@ def email(ui, repo, *revs, **opts):
                 del m['Bcc']
             fp = stringio()
             generator = mail.Generator(fp, mangle_from_=False)
-            generator.flatten(m, False)
+            generator.flatten(m, linesep="\r\n") # 2024-09-20 muxator
             alldests = to + bcc + cc
             sendmail(sender_addr, alldests, fp.getvalue())



However, it would probably be better to pass a RFC-compliant, non default
policy parameter when constructing the Generator object (I see there are two
branches, one probably covering a special case when running tests).


I was not able to easily run the tests via ./run-tests.py test-patchbomb.t, so
I do not feel confident to submit a patch without a validation of the problem
by someone else.

Thanks.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list