Parsing email with email :: MIME and multipart / signed

I'm a novice beginner trying to figure out how to decode a MIME-encoded multi-part email. I’m not sure about the agreements, so I’ll just include parts of the letter that I think are relevant:

 Content-Type: multipart/mixed; boundary="===============3385789078715843912=="
 Mime-Version: 1.0

 --===============3385789078715843912==
 Content-Type: multipart/signed; micalg="pgp-sha256";
     protocol="application/pgp-signature"; boundary="=-0+dmFxz+BsFOEAAxvudu"


 --=-0+dmFxz+BsFOEAAxvudu
 Content-Type: text/plain; charset="UTF-8"
 Content-Transfer-Encoding: base64

 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT0KVWJ1bnR1IFNlY3VyaXR5IE5vdGljZSBVU04tMzIxMC0xCkZlYnJ1
 YXJ5IDIzLCAyMDE3CgpMaWJyZU9mZmljZSB2dWxuZXJhYmlsaXR5Cj09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 CgpBIHNlY3VyaXR5IGlzc3VlIGFmZmVjdHMgdGhlc2UgcmVsZWFzZXMgb2YgVWJ1bnR1IGFuZCBp
 dHMgZGVyaXZhdGl2ZXM6CgotIFVidW50dSAxNi4wNCBMVFMKLSBVYnVudHUgMTQuMDQgTFRTCi0g

I have the following bit of code:

  my $msg = Email::MIME->new($buf);

  for my $part ($msg->parts) {
      if ($part->content_type =~ m!multipart/mixed!
              or $part->content_type eq '' )
          {   
              print "Found Multipart";
              for my $subpart ($part->parts) {
                  print $subpart->body;
             }
      }
  }

I really don't know what to do next. I had a dozen different variations on this, and I didn't get any closer after four hours of working on it. I would appreciate if someone would help me identify the correct perl modules and functions that will be used to read this part of the text of the signed letter.

+4
source share
1 answer

: MIME parts, . , . .

subparts , . , . , . body , .

foreach my $part ( $msg->subparts ) {
    foreach my $sub_part ($part->subparts) {
            print $sub_part->body;
    }
}
+3

Source: https://habr.com/ru/post/1672314/


All Articles