summaryrefslogtreecommitdiffstats
path: root/kmail/upgrade-signature.pl
blob: 23c3d63b694bd7aea069160a2f0353df596a9802 (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
62
63
#!/usr/bin/perl

my (%data);
my $section = "";

sub process {
    # delete obsolete keys:
    print "# DELETE [$section]UseSignatureFile\n";

    # now determine the type of signature:
    if ( $data{'usefile'} =~ /false/i ) {
	# type = inline
	if ( $data{'inline'} ne "" ) {
	    print "[$section]\nSignature Type=inline\n";
	} else {
	    print "[$section]\nSignature Type=disabled\n";
	    print "# DELETE [$section]Inline Signature\n";
	}
	print "# DELETE [$section]Signature File\n";
    } else {
	# type = file or command
	if ( $data{'file'} =~ /\|$/ ) {
	    # a trailing pipe means:
	    # type = command
	    chop $data{'file'};
	    print "[$section]\nSignature Type=command\n";
	    print "[$section]\nSignature Command=", $data{'file'}, "\n";
	    print "# DELETE [$section]Signature File\n";
	    print "# DELETE [$section]Inline Signature\n";
	} elsif ( $data{'file'} eq "" ) {
	    # empty filename means:
	    # type = disabled
	    print "[$section]\nSignature Type=disabled\n";
	    print "# DELETE [$section]Inline Signature\n";
	    print "# DELETE [$section]Signature File\n";
	} else {
	    # type = file
	    print "[$section]\nSignature Type=file\n";
	    print "# DELETE [$section]Inline Signature\n";
	}
    }
}

#loop over all lines to find Identity sections:
while (<>) {
    if ( /\[(Identity[^]]*)\]/ ) {
        # new group means that we have to process the old group:
        if ( $section ne "" ) { process(); }
	$section = $1;
	%data = ();
	next;
    }
    chomp;
    # We need to prevent this script from begin run twice
    # since it would set all signatures to 'disabled' then.
    # Presence of the Signature Type key is the best indicator.
    /^Signature Type/ and exit;
    /^Inline Signature=(.*)$/ and $data{'inline'} = $1;
    /^Signature File=(.*)$/   and $data{'file'} = $1;
    /^UseSignatureFile=(.*)$/ and $data{'usefile'} = $1;
}
#and don't forget to preocess the last group ;-)
if ( $section ne "" ) { process(); }