Merge branch 'master' into 4.next
[exim.git] / test / aux-fixed / dkim / sign.pl
1 use Mail::DKIM::Signer;
2 use Mail::DKIM::TextWrap; #recommended
3 use Getopt::Long;
4
5 # default option values
6 my $method = "simple/simple";
7 my $selector = "sel";
8 my $keyfile = "aux-fixed/dkim/dkim.private";
9 my $algorithm = "rsa-sha1";
10
11 GetOptions(
12 "method=s" => \$method,
13 "selector=s" => \$selector,
14 "keyfile=s" => \$keyfile,
15 "algorithm=s" => \$algorithm,
16 );
17
18 # create a signer object
19 my $dkim = Mail::DKIM::Signer->new(
20 Algorithm => $algorithm,
21 Method => $method,
22 Domain => "test.ex",
23 Selector => $selector,
24 KeyFile => $keyfile,
25 );
26
27 # read an email and pass it into the signer, one line at a time
28 while (<STDIN>)
29 {
30 # remove local line terminators
31 chomp;
32 s/\015$//;
33
34 # use SMTP line terminators
35 $dkim->PRINT("$_\015\012");
36 }
37 $dkim->CLOSE;
38
39 # what is the signature result?
40 my $signature = $dkim->signature;
41 print $signature->as_string;
42 print "\n";
43
44 #print $dkim->headers;
45 #print "\n";