# Unexplained Email::Receiver::InvalidPost errors

**URL:** <https://meta.discourse.org/t/unexplained-email-invalidpost-errors/377793>\
**Category:** Bug\
**Created:** [August 7, 2025, 8:31pm UTC](https://meta.discourse.org/t/unexplained-email-invalidpost-errors/377793 "2025-08-07T20:31:32Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [January 13, 2026, 9:22pm UTC](https://meta.discourse.org/t/unexplained-email-invalidpost-errors/377793/21 "2026-01-13T21:22:26Z")

</div>

> [@lavamind](#):
>
> There’s no duplication, and the parts are ordered correctly.

Oh! Given this I’ve gone back and re-investigated… and turns out it’s our problem after all.

From the raw email you posted above, I’ve just discovered that IncomingEmail.raw does _not_ actually store the raw email… we munge it first with `Email::Cleaner`.

(sorry, this whole time I thought we could trust it, we used to be able to)

This seems to be the Ruby mail gem’s fault… it _reorders parts of a mail message_ when writing it back out:

```plaintext
[1] pry(main)> m = File.open('test.eml').read;
[2] pry(main)> Mail.new(m).parts
=> [
  #<Mail::Part:39680, Multipart: true, Headers: <Content-Type: multipart/signed; boundary="Sig_/gizYC_1dGsAzUHvksdaMIe2"; protocol="application/pgp-signature"; micalg=pgp-sha256>>,
  #<Mail::Part:39700, Multipart: false, Headers: <MIME-Version: 1.0>, <Content-Type: text/plain; charset="us-ascii">, <Content-Transfer-Encoding: 7bit>, <Content-Disposition: inline>>
 ]
[3] pry(main)> Mail.new(Mail.new(m).to_s).parts
=> [
  #<Mail::Part:39720, Multipart: false, Headers: <MIME-Version: 1.0>, <Content-Type: text/plain; charset=us-ascii>, <Content-Transfer-Encoding: 7bit>, <Content-Disposition: inline>, <Content-ID: <6966b4914df79_31d5b1d38126@mars.mail>>>,
  #<Mail::Part:39740, Multipart: true, Headers: <Content-Type: multipart/signed; boundary="Sig_/gizYC_1dGsAzUHvksdaMIe2"; micalg=pgp-sha256; protocol="application/pgp-signature">, <Content-Transfer-Encoding: 7bit>>
]

```

which causes the problem:

```plaintext
[38] pry(main)> puts Email::Receiver.new(m).select_body[0];
> We received a court order to preserve the data on the system and were
> forbidden from informing the system owner, which was awkward since
> they had informed the system owner...

Which data did they request?

> Since then I've always run my exit on a separate system on it's own
> IP so if there were a legal demand to turn over "the system" it would
> really only be that system. I'm not a lawyer but I don't think docker
> provides enough isolation for that.

Can they deny you to turn the relay off?
If so, you could then operate a new "system" on another IP.

[39] pry(main)> puts Email::Receiver.new(Mail.new(m).to_s).select_body[0];
«no output»

```

> **Difference details**
>
> test.eml: raw message as provided  
> test-rubyparsed.eml: message parsed by ruby then turned back into a string  
> test-pythonparsed.eml: message parsed by python then turned back into a string
> 
> ```diff
> --- test.eml	2026-01-13 15:58:18.769489410 -0500
> +++ test-rubyparsed.eml	2026-01-13 16:11:17.767312268 -0500
> @@ -1,25 +1,46 @@
> +Date: Tue, 13 Jan 2026 16:07:21 -0500
> +From: Marco Moock via tor-relays <tor-relays@lists.torproject.org>
> +Reply-To: Marco Moock <mm@dorfdsl.de>
> +Message-ID: <6966b40914be8_31d5b1d38719@mars.mail>
> Subject: [tor-relays] Re: Questions about running an exit relay
> +MIME-Version: 1.0
> +Content-Type: multipart/mixed;
> + boundary="===============8958541500975114832=="
> +Content-Transfer-Encoding: 7bit
> List-Id: "support and questions about running Tor relays (exit, non-exit,
> bridge)" <tor-relays.lists.torproject.org>
> -Archived-At: 
> - <https://lists.torproject.org/mailman3/hyperkitty/list/tor-relays@lists.torproject.org/message/OAX7EO72GLXS4KPKUG7QSG7EOAR2WYVA/>
> -List-Archive: 
> - <https://lists.torproject.org/mailman3/hyperkitty/list/tor-relays@lists.torproject.org/>
> +Archived-At: <https://lists.torproject.org/mailman3/hyperkitty/list/tor-relays@lists.torproject.org/message/OAX7EO72GLXS4KPKUG7QSG7EOAR2WYVA/>
> +List-Archive: <https://lists.torproject.org/mailman3/hyperkitty/list/tor-relays@lists.torproject.org/>
> List-Help: <mailto:tor-relays-request@lists.torproject.org?subject=help>
> List-Owner: <mailto:tor-relays-owner@lists.torproject.org>
> List-Post: <mailto:tor-relays@lists.torproject.org>
> List-Subscribe: <mailto:tor-relays-join@lists.torproject.org>
> List-Unsubscribe: <mailto:tor-relays-leave@lists.torproject.org>
> -From: Marco Moock via tor-relays <tor-relays@lists.torproject.org>
> -Reply-To: Marco Moock <mm@dorfdsl.de>
> -Content-Type: multipart/mixed; boundary="===============8958541500975114832=="
> +
> +
> +--===============8958541500975114832==
> +MIME-Version: 1.0
> +Content-Type: text/plain;
> + charset=us-ascii
> +Content-Transfer-Encoding: 7bit
> +Content-Disposition: inline
> +Content-ID: <6966b40914ae9_31d5b1d38641@mars.mail>
> +
> + _______________________________________________
> +tor-relays mailing list -- tor-relays@lists.torproject.org
> +To unsubscribe send an email to tor-relays-leave@lists.torproject.org
>  
> --===============8958541500975114832==
> -Content-Type: multipart/signed; boundary="Sig_/gizYC_1dGsAzUHvksdaMIe2";
> - protocol="application/pgp-signature"; micalg=pgp-sha256
> +Content-Type: multipart/signed;
> + boundary="Sig_/gizYC_1dGsAzUHvksdaMIe2";
> + micalg=pgp-sha256;
> + protocol="application/pgp-signature"
> +Content-Transfer-Encoding: 7bit
> +
>  
> --Sig_/gizYC_1dGsAzUHvksdaMIe2
> -Content-Type: text/plain; charset=US-ASCII
> +Content-Type: text/plain;
> + charset=US-ASCII
> Content-Transfer-Encoding: quoted-printable
>  
> On 02.01.2026 18:46 Jon via tor-relays
> @@ -39,7 +60,8 @@
> Can they deny you to turn the relay off?
> If so, you could then operate a new "system" on another IP.
>  
> ---=20
> +-- =
> +
> kind regards
> Marco
>  
> @@ -47,6 +69,7 @@
>  
> --Sig_/gizYC_1dGsAzUHvksdaMIe2
> Content-Type: application/pgp-signature
> +Content-Transfer-Encoding: 7bit
> Content-Description: Digitale Signatur von OpenPGP
>  
> -----BEGIN PGP SIGNATURE-----
> @@ -69,14 +92,5 @@
>  
> --Sig_/gizYC_1dGsAzUHvksdaMIe2--
>  
> ---===============8958541500975114832==
> -Content-Type: text/plain; charset="us-ascii"
> -MIME-Version: 1.0
> -Content-Transfer-Encoding: 7bit
> -Content-Disposition: inline
> -
> - _______________________________________________
> -tor-relays mailing list -- tor-relays@lists.torproject.org
> -To unsubscribe send an email to tor-relays-leave@lists.torproject.org
> -
> --===============8958541500975114832==--
> +
> 
> ```
> 
> ```diff
> --- test.eml	2026-01-13 15:58:18.769489410 -0500
> +++ test-pythonparsed.eml	2026-01-13 16:19:30.385608544 -0500
> @@ -1,10 +1,8 @@
> Subject: [tor-relays] Re: Questions about running an exit relay
> List-Id: "support and questions about running Tor relays (exit, non-exit,
> bridge)" <tor-relays.lists.torproject.org>
> -Archived-At: 
> - <https://lists.torproject.org/mailman3/hyperkitty/list/tor-relays@lists.torproject.org/message/OAX7EO72GLXS4KPKUG7QSG7EOAR2WYVA/>
> -List-Archive: 
> - <https://lists.torproject.org/mailman3/hyperkitty/list/tor-relays@lists.torproject.org/>
> +Archived-At: <https://lists.torproject.org/mailman3/hyperkitty/list/tor-relays@lists.torproject.org/message/OAX7EO72GLXS4KPKUG7QSG7EOAR2WYVA/>
> +List-Archive: <https://lists.torproject.org/mailman3/hyperkitty/list/tor-relays@lists.torproject.org/>
> List-Help: <mailto:tor-relays-request@lists.torproject.org?subject=help>
> List-Owner: <mailto:tor-relays-owner@lists.torproject.org>
> List-Post: <mailto:tor-relays@lists.torproject.org>
> 
> ```

* * *

I opened:

[https://github.com/mikel/mail/issues/1658](https://github.com/mikel/mail/issues/1658)

---

_[View the full topic](https://meta.discourse.org/t/unexplained-email-invalidpost-errors/377793)._
