mjl- / mox

modern full-featured open source secure mail server for low-maintenance self-hosted email
https://www.xmox.nl
MIT License
3.38k stars 89 forks source link

Error: invalid bare carriage return or newline. #129

Closed x8x closed 4 months ago

x8x commented 5 months ago

After upgrading to 0.9 I got a few mail delivery errors like this:

Delivery has failed permanently for your email to:
    ..
No further deliveries will be attempted.
Error during the last delivery attempt:
    writing message as smtp data: invalid bare carriage return or newline, transient
Reporting-MTA: dns; ..

Thinking this commit was a related fix, I upgraded to version v0.0.10-0.20240209102133-ee1db2dde705, but am still getting such delivery errors.

./mox reparse returns these errors:

Reparsing account A...
parsing message 388: quotedprintable: invalid bytes after =: "\r\r\n" (continuing)
244 message(s) reparsed for account A

Reparsing account B...
parsing message 2809: quotedprintable: invalid bytes after =: "\r\r\n" (continuing)
parsing message 2936: quotedprintable: invalid bytes after =: "\r\r\n" (continuing)
parsing message 3334: quotedprintable: invalid bytes after =: "\r\r\n" (continuing)
parsing message 3422: quotedprintable: invalid bytes after =: "\r\r\n" (continuing)
1454 message(s) reparsed for account B

Reparsing account C...
parsing message 4786: first boundary cannot be finishing boundary (continuing)
parsing message 4893: first boundary cannot be finishing boundary (continuing)
586 message(s) reparsed for account C

How to fix stored messages reported by reparse and are there still known issues related to the smtp error above?

Thank you!

mjl- commented 5 months ago

Thinking this commit was a related fix, I upgraded to version v0.0.10-0.20240209102133-ee1db2dde705, but am still getting such delivery errors.

That's an error you are stilling getting for new incoming deliveries? Or is that coming from mox parsing the message from disk? It is still possible that mox rejects messages, but I'm thinking we should accept such messages if they are incoming for final delivery, and only keep rejecting them for messages that still need to be delivered (over submission).

The bug was that the smtpserver was adding an extra \r to the message file. Reparse only reads the message as stored on disk, it doesn't fix it. Could you try removing that \r from the on-disk file yourself and running reparse again? If that works, we may need some subcommand or instructions to fix up these issues...

x8x commented 5 months ago

That's an error you are stilling getting for new incoming deliveries? Or is that coming from mox parsing the message from disk? It is still possible that mox rejects messages, but I'm thinking we should accept such messages if they are incoming for final delivery, and only keep rejecting them for messages that still need to be delivered (over submission).

Got this two days ago, after upgrading mox to v0.0.10-0.20240209102133-ee1db2dde705:

Delivery has been delayed of your email to:

    user@gmail.com

Next attempts to deliver: in 4 hours, 8 hours and 16 hours.
If these attempts all fail, you will receive a notice.

Error during the last delivery attempt:

    writing message as smtp data: invalid bare carriage return or newline, transient
Reporting-MTA: dns; mail.server.com
Arrival-Date: 12 Feb 2024 22:32:47 +0000

Final-Recipient: rfc822;user@gmail.com
Action: delayed
Status: 4.0.0
Remote-MTA: dns;alt4.gmail-smtp-in.l.google.com ([173.194.202.26])
Diagnostic-Code: smtp; 4.0.0 (writing message as smtp data: invalid bare carriage return or newline, transient)
Last-Attempt-Date: 13 Feb 2024 00:24:44 +0000
Will-Retry-Until: 14 Feb 2024 04:24:44 +0000
Content-Type: multipart/alternative;
    boundary=".."
Mime-Version: 1.0
..

The bug was that the smtpserver was adding an extra \r to the message file. Reparse only reads the message as stored on disk, it doesn't fix it. Could you try removing that \r from the on-disk file yourself and running reparse again? If that works, we may need some subcommand or instructions to fix up these issues...

Had a quick go at it but it seams I am unable to locate it, will need to figure out the proper tooling, I welcome any suggestions. But then, that would probably only fix the stored messages but not fix the delivery issues.

What about this error:

parsing message 4786: first boundary cannot be finishing boundary (continuing)

Thank you!

x8x commented 5 months ago

Ok, I was able to fix the mails with \r\r\n and deleted those reporting first boundary cannot be finishing boundary.

Now mox reparse returns no errors.

Will be watching for new deliveries returninginvalid bare carriage return or newline, transient errors.

mjl- commented 5 months ago

I think I found the bug that was causing error message writing message as smtp data: invalid bare carriage return or newline that was failing to deliver outgoing messages. See commit message for the details.

Still good to keep this issue open for the reparse and "\r\r\n" issue.

mjl- commented 4 months ago

v0.0.10 is coming soon. It has instructions for fixing the "\r\r\n" issue. Closing this issue, but feel free to reopen if needed.