blob: 5a38ee3f648d2dc53979eb89ecb542daf8ff745b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use MIME::Base64;
my $headers = {};
my $last_key;
while (my $line = <STDIN>) {
# stop parsing once we reach the body
last if $line =~ /^$/;
if ($line =~ /^(?<key>[^:]+): (?<value>.*)$/) {
$last_key = lc($+{key});
$headers->{$last_key} = $+{value};
} elsif (defined($last_key) && $line =~ /^\s+(?<value>.*)$/) {
$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;
|