Nocturnus has asked for the wisdom of the Perl Monks concerning the following question:

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

  • Comment on Module to deal with PGP-encrypted email messages in 2025

Replies are listed 'Best First'.
Re: Module to deal with PGP-encrypted email messages in 2025
by choroba (Cardinal) on Aug 07, 2025 at 18:13 UTC
    > Mail::PGP seemed like a good candidate,

    Do you mean PGP::Mail? What errors do you get? On the Testers page, there is a successful installation in 5.38.2, 5.40 is missing and 5.42 shows a failure.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Thanks for your help.

      Unfortunately, Mail::PGP can't decrypt messages; it seems that it only can sign messages.

      Anyway, I have managed to introduce a typo in my first post at an important place: I meant Mail::GPG where I wrote Mail::PGP. The latter does not exist. In the meantime, I have corrected that typo.

      Mail:GPG seemed like the way to go, but I couldn't install it, and it seems that I am not alone with that problem; see here.