NAME

Mail::DKIM::Signer - generates a DKIM signature for a message

SYNOPSIS

use Mail::DKIM::Signer;

# create a signer object
my $dkim = Mail::DKIM::Signer->new_object(
                Algorithm => "rsa-sha1",
                Method => "nowsp",
                Domain => "example.org",
                Selector => "selector1",
                KeyFile => "private.key");
           );

# read an email from a file handle
$dkim->load(*STDIN);

# or read an email and pass it into the signer, one line at a time
while (<STDIN>)
{
    # remove local line terminators
    chomp;
    s/\015$//;

    # use SMTP line terminators
    $dkim->PRINT("$_\015\012");
}
$dkim->CLOSE;

# what is the signature result?
my $signature = $dkim->signature;

CONSTRUCTOR

new_object() - construct an object-oriented signer

my $dkim = Mail::DKIM::Signer->new_object(
                Algorithm => "rsa-sha1",
                Method => "nowsp",
                Domain => "example.org",
                Selector => "selector1",
                KeyFile => "private.key"
           );

my $dkim = Mail::DKIM::Signer->new_object(
                Policy => $signer_policy,
                KeyFile => "private.key"
           );

You must always specify the name of a private key file. In addition, you must specify a policy object, or specify the algorithm, method, domain, and selector to use. Use of the policy object lets you defer the determination of algorithm, method, domain and selector until the message being signed has been partially read.

See Mail::DKIM::SignerPolicy for more information about policy objects.

METHODS

PRINT() - feed part of the message to the signer

$dkim->PRINT("a line of the message\015\012");

Feeds content of the message being signed into the signer. The API is designed this way so that the entire message does NOT need to be read into memory at once.

CLOSE() - call this when finished feeding in the message

$dkim->CLOSE;

This method finishes the canonicalization process, computes a hash, and generates a signature.

algorithm() - get or set the selected algorithm

$alg = $dkim->algorithm;

$dkim->algorithm("rsa-sha1");

domain() - get or set the selected domain

$alg = $dkim->domain;

$dkim->domain("example.org");

load() - load the entire message from a file handle

$dkim->load($file_handle);

Reads a complete message from the designated file handle, feeding it into the signer. The message must use <CRLF> line terminators (same as the SMTP protocol).

method() - get or set the selected canonicalization method

$alg = $dkim->method;

$dkim->method("relaxed");

message_originator() - access the "From" header

my $address = $dkim->message_originator;

Returns the "originator address" found in the message. This is typically the (first) name and email address found in the From: header. The returned object is of type Mail::Address. To get just the email address part, do:

my $email = $dkim->message_originator->address;

message_sender() - access the "From" or "Sender" header

my $address = $dkim->message_sender;

Returns the "sender" found in the message. This is typically the (first) name and email address found in the Sender: header. If there is no Sender: header, it is the first name and email address in the From: header. The returned object is of type Mail::Address, so to get just the email address part, do:

my $email = $dkim->message_sender->address;

The "sender" is the mailbox of the agent responsible for the actual transmission of the message. For example, if a secretary were to send a message for another person, the "sender" would be the secretary and the "originator" would be the actual author.

selector() - get or set the current key selector

$alg = $dkim->selector;

$dkim->selector("alpha");

signature() - access the generated signature object

my $signature = $dkim->signature;

Returns the generated signature. The signature is an object of type Mail::DKIM::Signature.

SEE ALSO

Mail::DKIM::SignerPolicy

Mail::DKIM::SigningFilter