summaryrefslogtreecommitdiffstats
path: root/kmail/kmail-pgpidentity.pl
diff options
context:
space:
mode:
Diffstat (limited to 'kmail/kmail-pgpidentity.pl')
-rwxr-xr-xkmail/kmail-pgpidentity.pl34
1 files changed, 34 insertions, 0 deletions
diff --git a/kmail/kmail-pgpidentity.pl b/kmail/kmail-pgpidentity.pl
new file mode 100755
index 000000000..b6e7bcad5
--- /dev/null
+++ b/kmail/kmail-pgpidentity.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+# For each KMail Identity convert the "PGP Identity" entry (which contains a
+# user ID) to a "Default PGP Key" entry (which contains a key ID)
+
+$DEBUG = 0;
+
+while(<>)
+{
+ if( /\[(Identity.*)\]/ )
+ {
+ $section = $1;
+ next;
+ }
+ if( /^PGP Identity=(.*)$/ )
+ {
+ print STDERR "\n[$section]PGP Identity=$1\n" if ( $DEBUG );
+
+ if( ( $1 ne "" ) &&
+ ( open GnuPG, "gpg --list-secret-keys --utf8-strings '$1' |" ) )
+ {
+ while (<GnuPG>)
+ {
+ # search in gpg's output for the key id of the first matching key
+ if(/^sec[^\/]*\/([0-9A-F]*)/)
+ {
+ print "[$section]\nDefault PGP Key=$1\n";
+ last;
+ }
+ }
+ }
+ print "# DELETE [$section]PGP Identity\n";
+ }
+}