From abee4fc028e486c84981cf3463932e505f09f3ff Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 26 Jan 2013 03:10:42 +0100 Subject: Switched from the buggy (according to its author) MIME::Lite to MIME::Entity. --- lib/Fripost/Schema/Mail.pm | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3