ZConf-Mail
view release on metacpan or search on metacpan
lib/ZConf/Mail.pm view on Meta::CPAN
#make sure a key is specified
if (!defined($Aargs{PGPkey})) {
$self->{error}=41;
$self->{errorString}='"PGPkey" account arg is not defined';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
#make sure the sign type is supported
my @types=('clearsign', 'mimesign', 'signencrypt');
my $int=0;
my $matched=0;
while($types[$int]){
if ($types[$int] eq $Aargs{pgpType}) {
$matched=1;
}
$int++;
}
if (!$matched) {
$self->{error}=43;
$self->{errorString}='The type, "'.$Aargs{pgpType}.'", is not a valid type';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
#creates the body directory
my $bodydir='/tmp/'.time().rand();
if (!mkdir($bodydir)) {
$self->{error}=39;
$self->{errorString}='Faied to create the temporary directory,"'.
$bodydir.'", for signing.';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
my $bodyfile=$bodydir.'/body';
#if we are doing mimesigning, we need to
if ($Aargs{pgpType} eq 'mimesign') {
$body=~s/\n/\r\n/g;
}
#open it and write to it
if (!open(BODYWRITE, '>'.$bodyfile)) {
rmdir($bodydir);
$self->{error}=40;
$self->{errorString}='Failed to write body to "'.$bodyfile.
'", for signing';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
print BODYWRITE $body;
#this is the file that will be read into $sign
my $read=undef;
#this is what will be returned
my $sign=undef;
#handles clear signing
my $execstring='gpg -u '.$Aargs{PGPkey}.' --digest-algo '.$hash.' ';
if ($Aargs{pgpType} eq 'clearsign') {
$execstring=$execstring.' --clearsign '.$bodyfile;
system($execstring);
if ($? ne '0') {
$sign->{error}=44;
$sign->{errorString}='Signing failed. Command="'.$execstring.'"';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
$read=$bodyfile.'.asc';
}
#handles mime signing
if ($Aargs{pgpType} eq 'mimesign') {
$execstring=$execstring.' -a --detach-sign '.$bodyfile;
system($execstring);
if ($? ne '0') {
$sign->{error}=44;
$sign->{errorString}='Signing failed. Command="'.$execstring.'"';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
$read=$bodyfile.'.asc';
}
#handles sign and encrypt
if ($Aargs{pgpType} eq 'signencrypt') {
$execstring=$execstring.' -se -r '..' '.$bodyfile;
system($execstring);
if ($? ne '0') {
$sign->{error}=44;
$sign->{errorString}='Signing failed. Command="'.$execstring.'"';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
$read=$bodyfile.'.gpg';
}
open(SIGNREAD, '<'.$read);
$sign=join("", <SIGNREAD>);
close(SIGNREAD);
unlink($bodyfile);
unlink($read);
rmdir($bodydir);
return $sign;
}
=head1 ERROR RELATED METHODS
=head2 error
Returns the current error code and true if there is an error.
If there is no error, undef is returned.
if($zconf->error){
warn('error: '.$zconf->error.":".$zconf->errorString);
}
=cut
sub error{
return $_[0]->{error};
}
=head2 errorBlank
This blanks the error storage and is only meant for internal usage.
It does the following.
$self->{error}=undef;
$self->{errorString}="";
=cut
#blanks the error flags
sub errorBlank{
my $self=$_[0];
if ($self->{perror}){
warn($self->{module}.' errorBlank; A permanent error is set');
return undef;
}
$self->{error}=undef;
$self->{errorString}="";
return 1;
}
=head2 errorString
Returns the error string if there is one. If there is not,
lib/ZConf/Mail.pm view on Meta::CPAN
=head3 accounts/smtp/*/server
The SMTP server to use.
=head3 accounts/smtp/*/port
The port on the server to use.
=head3 accounts/smtp/*/useSSL
If set to a boolean value of true, SSL will be used.
=head3 accounts/smtp/*/from
The from address to use for a account.
=head3 accounts/smtp/*/name
The name that will be used with the account.
=head3 accounts/smtp/*/saveTo
This is the account to save it to. If it not defined
or blank, it will not saved.
=head3 accounts/smtp/*/saveToFolder
This is the folder to save it to for the account.
=head3 accounts/smtp/*/timeout
The time out for connecting to the server.
=head3 accounts/smtp/*/usePGP
If PGP should be used or not for this account. This is a Perl boolean value.
=head3 accounts/smtp/*/pgpType
=head4 clearsign
Clear sign the message.
=head4 mimesign
Attach the signature as a attachment.
=head4 signencrypt
Sign and encrypt the message. Not yet implemented.
=head3 accounts/smtp/*/PGPkey
The PGP key to use.
=head3 accounts/smtp/*/PGPdigestAlgo
The digest algorithym to use. It will default to 'SHA512' if not specified.
To find what out what your version supports, run 'gpg --version'.
=head2 EXEC
=head3 deliver
This is the command to execute for delivering a mail message. A single message
will be delivered at a time by running the specified program and piping the message
into it. Only a single message is delivered at once.
A example would be setting this to '/usr/local/libexec/dovecot/deliver' to deliver a
message one's dovecot account.
=head2 FORMATTER
=head3 formatter/marginLeft
This is the left margin. The default is zero if this is not defined.
=head3 formatter/marginRight
This is the right margin. The default is 72 if this is not defined.
=head3 formatter/squeeze
Removes unneeded whitespace. This is on by default.
=head3 formatter/ignore
Don't reformat any paragraph that matches this line. The default is '^[ \t]'.
=head3 formatter/justify
How to justify the text. The default is left.
=head3 formatter/tabspace
This is the default spaces per tab. The default is '4'.
=head2 MISC
=head3 default/sendable
This is the default sendable account. If this key does not exist or set to '',
there is no default sendable account.
=head3 default/fetchable
This is the default fetchable account. If this key does not exist or set to '',
there is no default fetchable account.
=head2 INTERNAL VARIABLES
=head3 $zcmail->{init}
If this is false, '$zcmail->init' needs run.
=head3 $zcmail->{legal}
This hashes which contains the legal values for each type in a array. So for SMTP,
'$zcmail->{legal}{smtp}' contains the array of legal values for SMTP.
( run in 0.586 second using v1.01-cache-2.11-cpan-df04353d9ac )