diff options
Diffstat (limited to 'lib/Fripost')
-rw-r--r-- | lib/Fripost/Schema/Mail.pm | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/Fripost/Schema/Mail.pm b/lib/Fripost/Schema/Mail.pm index 309dad8..c07c6d1 100644 --- a/lib/Fripost/Schema/Mail.pm +++ b/lib/Fripost/Schema/Mail.pm @@ -16,26 +16,53 @@ use strict; use warnings; use utf8; -use MIME::Lite; +use MIME::Entity; +use Mail::GnuPG; +use Encode 'encode'; + +my $DEBUG = 0; sub new { my $class = shift; my $self = bless {}, $class; my %msg = @_; + $msg{To} //= $ENV{USER}.'@localhost'; $msg{Encoding} //= 'quoted-printable'; $msg{Charset} //= 'utf-8'; - $self->{_msg} = MIME::Lite->new(@_); + $msg{From} = Encode::encode( 'MIME-Q', $msg{From}) if $msg{From}; + $msg{To} = Encode::encode( 'MIME-Q', $msg{To}) if $msg{To}; + $msg{Subject} = Encode::encode( 'MIME-Q', $msg{Subject}) if $msg{Subject}; + + my $msg = MIME::Entity::->build( %msg ); + $msg->sign( Signature => $msg{Signature} ) if $msg{Signature}; + + $self->{_msg} = $msg; + return $self; +} + +sub sign { + my $self = shift; + my $sign_as = shift; + + my $msg = $self->{_msg}; + # TODO: use a config option. + my $gpg = Mail::GnuPG::->new( use_agent => 1 ); + my $ret = $gpg->mime_sign( $msg ); + map { warn "WARN: $_" } @{$gpg->{last_message}} if $ret; + return $self; } sub send { my $self = shift; - print STDERR $self->{_msg}->as_string; - $self->{_msg}->send; + my $msg = $self->{_msg}; + print STDERR $msg->as_string if $DEBUG; +# $msg->send; } + =back =head1 AUTHOR |