From 6677b0b33fb573ee6a05e1caf16ca545d771993f Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 1 Jun 2019 11:50:41 +0200 Subject: Add import-autocrypt Signed-off-by: Florian Pritz --- import-autocrypt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 import-autocrypt 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 = ) { + # 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; -- cgit v1.2.3-24-g4f1b