Wez Furlong aa46113dee mailparsing: improve handling of bad messages
We had a user report problems with an incoming OOB message.
The issue was that `msg:from_header()` would raise an error
because one of the MIME parts in the incoming message had
8-bit data and didn't apply transfer encoding on the offending
part.

It's actually a bit deeper than just missing transfer encoding;
the issue was really that Spam Assassin was employed on the
remote system and it generated an `X-Ham-Report` header that
embedded 8-bit data (looks mostly UTF-8, but had an invalid byte)
in that header without applying RFC2047 header encoding.

```
X-Ham-Report: Spam detection software, running on the system "example.com",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 root\@localhost for details.
 Content preview:  <unencoded binary data here>
```

In the resultant rfc3464 delivery status report, the original
message payload is included as a message/rfc822 part in the body.
So to our parser this looks like a badly encoded body (which it is),
but only because the header in that part was badly encoded.

So this is a double-fail; the Spam Assassin header content
preview logic is generating a non-conforming header, and Exim's
DSN generation at the offending site is generating a non-conforming
message payload.

What this commit does is:

* Adds an `IntoSharedString` trait to encapsulate the conversion
  from String, str or bytes into SharedString.  Previously we
  used a fallible conversion for this, but now this conversion is
  infallible but returns a MessageConformance value. Internally,
  if the data is not UTF-8, we fall back to the lossy conversion
  and flag the part as needing transfer encoding.
* That will allow the parser to return something, even if it is
  slightly mangled by the unicode replacement character. This
  mangling is not a bug: it's a case of "garbage-in, garbage-out".
* This change allows check_fix_conformance to report
  NEEDS_TRANSFER_ENCODING when run in check mode. When run in fix
  mode, the offending part, *including the replacement character*
  will have transfer encoding applied to it. We can't "do better"
  here because the input message is bogus and is missing proper
  transfer encoding.
* Fixes an issue where whitespace from this fixed part was stripped
  out. I'm not sure why whitespace was being stripped; no unit
  tests fail as a result of this change, so it must be good?
2024-02-28 09:56:27 -07:00
2023-03-06 07:53:27 -07:00
2024-02-24 09:18:23 -07:00
2023-12-22 10:24:30 -07:00
2023-09-30 16:00:29 -07:00
2023-02-10 16:44:10 -07:00
2024-02-24 10:24:03 -07:00
2024-02-06 13:29:36 -07:00
2023-06-21 18:10:15 -07:00
2023-02-21 21:18:49 -07:00
2023-02-21 21:18:49 -07:00
2023-03-09 20:56:02 -07:00
2023-12-22 10:24:30 -07:00
2023-11-28 10:58:40 -05:00
2023-06-22 13:50:51 -07:00
2023-02-15 06:51:59 -07:00

KumoMTA

This repository holds the source code to KumoMTA, a modern Message Transfer Agent designed for large scale sending environments.

You can learn more about why it exists here.

Documentation

You can learn more about KumoMTA from the Documentation

Community

Real-time discussion is available on Our Discord.

Our Forum is better for long-form questions and discussions.

Developers

If you're interesting in contributing/extending KumoMTA, take a look at DEVELOPERS.md.

Reporting Bugs

Please see How to Report Bugs.

Getting Help

Please see How to Get Help

Talk to Us

We're available to talk about the project, book us at https://cal.com/team/kumomta/talk-with-kumomta.

S
Description
The first Open-Source high-performance MTA developed from the ground-up for high-volume email sending environments.
Readme
37 MiB
Languages
Rust 91.8%
Lua 6.3%
Python 0.9%
Shell 0.8%
JavaScript 0.1%