summaryrefslogtreecommitdiffstats
path: root/import-autocrypt
diff options
context:
space:
mode:
Diffstat (limited to 'import-autocrypt')
-rwxr-xr-ximport-autocrypt27
1 files changed, 27 insertions, 0 deletions
diff --git a/import-autocrypt b/import-autocrypt
new file mode 100755
index 0000000..5a38ee3
--- /dev/null
+++ b/import-autocrypt
@@ -0,0 +1,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;