You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdepim/kmail/kmail-upd-identities.pl

55 lines
1.6 KiB

#!/usr/bin/perl
my (%data);
$currentGroup = "";
while (<>) {
next if /^$/;
# filter out groups:
if ( /^\[(.+)\]$/ ) { $currentGroup = $1; next; };
# store all keys regarding Identities in the hash:
if ( $currentGroup =~ /^Identity/ ) {
($key,$value) = split /=/;
chomp $value;
$data{$currentGroup}{$key} = $value;
}
}
# We need to prevent this script from being run twice, since it would
# kill all identities then.
# Non-presence of the [Identity]IdentityList key is the best indiator:
unless ( defined( $data{'Identity'}{'IdentityList'} ) ) { exit; }
# first, delete all old groups:
foreach $group ( keys %data ) {
print "# DELETEGROUP [$group]\n";
}
# now, extract the list of valid identities (and their sequence):
$rawIdentityList = $data{'Identity'}{'IdentityList'};
# don't include the IdentityList anymore:
delete $data{'Identity'}{'IdentityList'};
# remove backslash-quoting:
$rawIdentityList =~ s/\\(.)/$1/g;
# split into a list at unquoted commas:
@identities = split /(?<!\\),/, $rawIdentityList;
# unquote individual items yet again:
for ( @identities ) { s/\\(.)/$1/g; }
# build the list of groups (this time incl. the default identity):
@groups = ( 'Identity', map { $_ = "Identity-$_"; } @identities );
# write out the groups, now named "Identity #n",
# with the same data and the same keys that the old groups had:
$n = 0;
foreach $group (@groups) {
%groupData = %{$data{$group}};
print "[Identity #$n]\n";
foreach $key ( keys %groupData ) {
print "$key="
. $groupData{$key} . "\n";
}
$n++;
}
# remember which one is default:
print "[General]\nDefault Identity=" . $data{'Identity'}{'Identity'} . "\n";