summaryrefslogtreecommitdiffstats
path: root/kmail/kmail-pgpidentity.pl
blob: b6e7bcad56cbe63cf12821ce5ff7517dfa7eb85b (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
28
29
30
31
32
33
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";
  }
}