Sisimai::MIME(3pm)

πŸ“¦
version 4.25.15 Β· 2 versions
, in debian bookworm

πŸ’– Sisimai::MIME β€” the MIME utilities era πŸ’–

okay bestie, sit down, hydrate, because this is the Sisimai::MIME page from the User Contributed Perl Documentation and it's genuinely so useful. it's the little toolkit that handles all the MIME nonsense hiding inside email headers. no cap. πŸŽ€


✨ NAME ✨

Sisimai::MIME β€” MIME Utilities πŸ¦‹


✨ SYNOPSIS ✨

lowkey just load it and go:

use Sisimai::MIME;

my $e = '=?utf-8?B?55m954yr44Gr44KD44KT44GT?=';
my $v = Sisimai::MIME->is_mimeencoded(\$e);
print $v;   # 1

my $x = Sisimai::MIME->mimedecode([$e]);
print $x;

see that? is_mimeencoded says 1 (yes bestie it IS encoded) and mimedecode hands you back the actual readable string. main character behaviour. πŸ’…


✨ DESCRIPTION ✨

Sisimai::MIME is MIME Utilities for "Sisimai". that's it, that's the vibe. it does the messy decoding work so the rest of Sisimai doesn't have to. 🫢


✨ CLASS METHODS ✨

🌸 is_mimeencoded(Scalar Reference)

is_mimeencoded() returns that the argument is MIME-Encoded string or not.

ngl the answer comes back as a truthy 1 when it's encoded. vibe check passed βœ…
my $e = '=?utf-8?B?55m954yr44Gr44KD44KT44GT?=';
my $v = Sisimai::MIME->is_mimeencoded(\$e);  # 1

🌸 mimedecode(Array-Ref)

mimedecode() is a decoder method for getting the original string from MIME Encoded string in email headers.

it's giving "unscramble the header" energy. pass an array ref, get the real text back πŸ”₯
my $r = '=?utf-8?B?55m954yr44Gr44KD44KT44GT?=';
my $v = Sisimai::MIME->mimedecode([$r]);

🌸 base64d(\String)

base64d is a decoder method for getting the original string from MIME Base564 encoded string.

yes bestie, the original really says Base564. we are reporting it exactly as written. periodt. πŸ’€
my $r = '44Gr44KD44O844KT';
my $v = Sisimai::MIME->base64d(\$r);

🌸 qprintd(\String)

qprintd is a decoder method for getting the original string from MIME Quoted- printable encoded string.

(the original has that lil space in "Quoted- printable", keeping it, iconic typo behaviour πŸ’…)
my $r = '=4e=65=6b=6f';
my $v = Sisimai::MIME->qprintd(\$r);

🌸 boundary(String)

boundary() returns a boundary string from the value of Content-Type header.

this one is so satisfying honestly. feed it a header, get the boundary back. and you can ask for the decorated versions too πŸŽ€
my $r = 'Content-Type: multipart/mixed; boundary=Apple-Mail-1-526612466';
my $v = Sisimai::MIME->boundary($r);
print $v;   # Apple-Mail-1-526612466

print Sisimai::MIME->boundary($r, 0); # --Apple-Mail-1-526612466
print Sisimai::MIME->boundary($r, 1); # --Apple-Mail-1-526612466--

so: no second arg β†’ just the raw boundary. 0 β†’ the opening -- version. 1 β†’ the closing --...-- version. slay. ✨


🌸 breaksup(\String, String)

breaksup is a multipart/* message decoder: Decode quoted-printable, base64, and other encoded message part, leave only text/plain, message/*, text/html (only in multipart/alternative), returns string as a reference. This method is called from makeflat() and breaksup() itself.

yes bestie it calls itself. recursive queen behaviour πŸ‘‘ it keeps text/plain, message/*, and text/html (but only when it's inside multipart/alternative) and yeets everything else, returning a reference to the string.

🌸 makeflat(String, \String)

makeflat makes flat multipart/* message: it leaves only text/html, message/, and text/html (Content-Type of upper part is not multipart/alternative) part. In other words, this method remove parts which is not needed to parse bounce message such as image/, text/html inside of multipart/alternative.

flattening a whole multipart message into one clean blob so the bounce parser doesn't have to deal with random image/* parts. the way that it just ✨removes✨ the irrelevant stuff. obsessed. 🌈
my $r = 'multipart/report; ...';    # Content-Type: MIME type, boundary
my $b = '...';                      # Multipart message body
my $v = Sisimai::MIME->makeflat($r, \$b);   # Returns scalar reference
print $$v;                  # Flatten message body
heads up: the return value is a scalar reference, so deref it with $$v before printing, bestie πŸ’–

✨ AUTHOR ✨

azumakuniyuki β€” the legend themselves 🫢


Copyright (C) 2014-2016,2018-2020 azumakuniyuki, All rights reserved.


✨ LICENSE ✨

This software is distributed under The BSD 2-Clause License. go read it, it's short and sweet πŸ’œ


and that's the whole page, bestie!! this was documented as Sisimai::MIME(3pm) for perl v5.36.0, dated 2022-12-23. mwah. stay decoded, stay iconic. πŸ’…πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from