our @EXPORT = qw/process_message/;
use Email::Sender::Simple qw/sendmail/;
+use File::Share qw/dist_file/;
use File::Slurp qw/read_file/;
+use File::Spec::Functions qw/rel2abs/;
use Getopt::Long;
use MIME::Entity;
use MIME::Parser;
sub first_part{
my ($ent) = @_;
return first_part $ent->parts(0) if $ent->parts;
- $ent->bodyhandle->as_string
+ stringify [$ent->bodyhandle->as_lines]
}
sub process_message {
'key=s' => \$ENV{EDWARDNG_KEY},
'keydir=s' => \$ENV{EDWARDNG_KEYDIR},
'passphrase=s' => \$ENV{EDWARDNG_PASSPHRASE},
+ 'tmpl-path=s' => \$ENV{EDWARDNG_TMPL_PATH},
'use-agent!' => \$ENV{EDWARDNG_USE_AGENT},
);
+ my $tmpl_path = $ENV{EDWARDNG_TMPL_PATH} // 'en';
my $parser = MIME::Parser->new;
$parser->decode_bodies(0);
$parser->output_to_core(1);
my $in = $parser->parse(\*STDIN);
+ debug 'Received mail from ', $in->get('From');
my ($tmpl, %params);
try {
} catch {
($tmpl, %params) = (error => message => $_)
};
+ debug "Result is $tmpl, GnuPG said:\n", $params{message};
$params{plaintext} = first_part $params{decrypted} if $params{decrypted};
- my $tt = Template->new(INCLUDE_PATH => 'tmpl/en');
+ my $tt = Template->new(INCLUDE_PATH => rel2abs $tmpl_path, dist_file 'App-EdwardNG', 'tmpl');
my $data;
$tt->process($tmpl, \%params, \$data);
my $email = MIME::Entity->build(
my $email_unencrypted = $email->dup;
my $mg = mg always_trust => 1;
my $encrypt_failed = $mg->mime_signencrypt($email, $in->get('From') =~ /<(.*)>/);
- debug 'Could not encrypt message, sending unencrypted. GnuPG said ', stringify $mg->{last_message} if $encrypt_failed;
+ debug 'Could not encrypt message, sending unencrypted. GnuPG said:', "\n", stringify $mg->{last_message} if $encrypt_failed;
sendmail $encrypt_failed ? $email_unencrypted : $email
}
EdwardNG is a reimplementation of the Edward reply bot referenced in L<https://emailselfdefense.fsf.org/>.
-It takes mail messages, checks them for PGP signatures and encryption, then replies appropriately.
-
This module exports a single function, B<process_message>, which takes a single parameter representing the message. This parameter can be:
=over