Dear well-respected monks,

I was wandering in the darkest night without any hope and orientation, but finally saw the promising lights of the monastery. The heart began to beat again, and I dare to ask you for your wisdom regarding the following question:

I need to deal with PGP-encrypted email messages. To be precise, I would like to permanently decrypt thousands of PGP-encrypted email messages that I have on disk in the form of .eml files.

To my surprise, I haven't found a PGP module for Perl that actually is usable in 2025 with recent Perl versions. Mail::PGP Mail::GPG seemed like a good candidate, but I now have lost nearly two days with trying to install it using CPAN in three different environments (Cygwin, Strawberry Perl / Native Windows and Linux). It seems that it cannot be used with recent Perl versions any more; no wonder that I've failed in trying to make it work.

Then there is Mail:GnuPG. It seems to be the predecessor of Mail:PGP, seems to contain some bugs, and seems to be even more outdated. I managed to install it under Linux, but failed to install it under Cygwin and under Strawberry Perl. The latter would not be the key point, but for certain reasons it would simply be more comfortable for me to run the script under native Windows. At least, Mail::GnuPG could be the last resort.

I am quite sure that I have missed something. What module would you, dear monks, use nowadays to decrypt PGP-encrypted email messages?

To avoid misunderstandings:

This question is about email messages that mostly contain nested MIME structures. When decrypting, all mail headers, MIME parts and attachments of the respective message should be preserved or decrypted, respectively. This means that I cannot use the Perl modules that can handle PGP on ordinary files; that would indeed be a no-brainer.

Furthermore, I could use the GnuPG application directly to permanently decrypt those messages; I have verified that this is possible in general. However, when doing this, the mail headers of the original message do not exist any more in the decrypted version. Instead, the decrypted version contains the headers that were in the encrypted part of the original message. For example, the Date header gets lost; funnily enough, it exists only as a non-encrypted header in the original message.

When anything else fails, I'll eventually take that route: Decrypt using the GnuPG application directly, then merge the headers from the original message with those of the decrypted message. As mentioned above, I'd like to listen to the monks before I take that effort.

Your devoted novice Nocturnus


In reply to Module to deal with PGP-encrypted email messages in 2025 by Nocturnus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.