#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use MIME::Base64; my $headers = {}; my $last_key; while (my $line = ) { # stop parsing once we reach the body last if $line =~ /^$/; if ($line =~ /^(?[^:]+): (?.*)$/) { $last_key = lc($+{key}); $headers->{$last_key} = $+{value}; } elsif (defined($last_key) && $line =~ /^\s+(?.*)$/) { $headers->{$last_key} .= $+{value}; } } my $autocrypt = {split(/=|;\s*/, $headers->{autocrypt})}; my $keydata = decode_base64($autocrypt->{keydata}); open my $gpg, '|-', qw(gpg --import); print $gpg $keydata; close $gpg;