aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Schema
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-26 03:10:42 +0100
committerGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-26 03:10:42 +0100
commitabee4fc028e486c84981cf3463932e505f09f3ff (patch)
tree6fdc229dee60610b369e3915f297146e41c241b5 /lib/Fripost/Schema
parenta11bde40a35dd261ffa35bf1b5d36ef638319295 (diff)
Switched from the buggy (according to its author) MIME::Lite to MIME::Entity.
Diffstat (limited to 'lib/Fripost/Schema')
-rw-r--r--lib/Fripost/Schema/Mail.pm35
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