[gem “Mail”] Cannot compose boundary for Mail::Body.split!

Good morning

My first post in this forum concerns mail 2.8.1 with Ruby 3.1.2p20

I appear to be unable to split a mail-body into parts. From what I read in body.rb from the Mail gem, a Regexp is created from my String-argument (boundary) by appending two dashes.

So, I see these boundaries in an authentic mail:
------=_Part_291375_1214917593.1717165035012
and create my boundary like this:

body.split!("\=_Part_")
parts = body.parts
debug "first part: " << parts[0].to_s

Unfortunately, parts[0] always contains all parts, i.e. the whole message-body, part[1] does – in consequence – not exist.

I notice that, no matter how many dashes I include in the boundary argument, the boundary which is stored by Mail::Body#split! is always missing two dashes. Authentic debug output:

EmlFile debug 10:15:12:703794: first part: Content-Type: multipart/alternative;
| boundary=“----=_Part_291375_1214917593.1717165035012”
|Content-Transfer-Encoding: 7bit
|
|
|------=_Part_291375_1214917593.1717165035012
|Content-Type: text/plain;
| charset=UTF-8
|Content-Transfer-Encoding: quoted-printable

Here, I used a call body.split!("----\=_Part_"), but, no matter how many dashes I use, I cannot match the original boundary in the mail.

Does anybody know something ?

2.) ri Mail informs me that

This whole class and associated specs is deprecated and will go away in
the version 3 release of mail.

I am reluctant to give up on this gem, because I use it for years, but maybe you can recommend something similar for Mail processing, excluding all network-activity.

TIA

Michael
P.S.: you do not need to mask the ‘=’ in the boundary-String, but I leave it here for authenticity.

Update on the situation.

  1. The mail-system is a mess.
  2. Detecting the borders in multipart-messages is not trivial and the Mail-gem cannot do it correctly in each possible context.

The very first boundary is announced in the Content-Type mail-header. Its format can be just about anything. Once you have that, you can find 1 (one) Mime-part, but this is only certain for the very first part, because the Content-Type declaration at the beginning of that part can announce a different border for the following part.

Felicitations.

I try to code that for myself but abstain from publication, in case something might work. Contributing to the mess is not what I had planned to do. Go beat up the guy who invented Mime-parts, I will.