summaryrefslogtreecommitdiffstats
path: root/libkpgp/kpgp-3.1-upgrade-address-data.pl
blob: 46c416178dd0c0e30903980e3e4ced311a7a79ff (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl

# Read all "AddressKeyEntry #" groups and the "EncryptionPreferences" group
# and store the information together in new "Address #" groups

my %data;

$currentGroup = "";
$address = "";

while(<>) {
  next if /^$/;
  # filter out groups:
  if( /^\[(.+)\]$/ ) {
    $currentGroup = $1;
    # delete the obsolete groups
    if( ( $currentGroup =~ /^AddressKeyEntry \d*/ ) ||
        ( $currentGroup eq "EncryptionPreferences" ) ) {
      print "# DELETEGROUP [$currentGroup]\n";
    }
    next;
  }
  # store the values of the old groups and delete them
  if( $currentGroup =~ /^AddressKeyEntry \d*/ ) {
    if( /^Address=(.*)$/ ) {
      $address = $1;
    }
    elsif( /^Key ID=(.*)$/ ) {
      $data{$address}{"keyid"} = $1;
    }
  }
  elsif( $currentGroup eq "EncryptionPreferences" ) {
    ($address,$encrpref) = split /=/;
    chomp $encrpref;
    $data{$address}{"encrpref"} = $encrpref;
  }
}

# write the new address groups
$n = 1;
foreach $address ( keys %data ) {
  %addressData = %{$data{$address}};
  print "[Address #$n]\n";
  print "Address=$address\n";
  if( exists $addressData{"encrpref"} ) {
    $encrpref = $addressData{"encrpref"};
    print "EncryptionPreference=$encrpref\n";
  }
  if( exists $addressData{"keyid"} ) {
    $keyid = $addressData{"keyid"};
    print "Key IDs=$keyid\n";
  }
  $n++;
}
$n--;

# write the number of address groups
print "# DELETE [General]addressKeyEntries\n";
print "# DELETE [General]addressEntries\n";
print "[General]\naddressEntries=$n\n";