X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApp%2FEdwardNG.pm;h=e778d6a20b70f6c065ca5a6f47b1c89a44238976;hb=2044b38a0328a71f923cbe1e55f0d95254f3fff4;hp=2d81020ea24ca6a287929f1b683cf3dc0844be3c;hpb=4224c4cea857a8ff83c22523e4adcf8e0568c042;p=app-edwardng.git diff --git a/lib/App/EdwardNG.pm b/lib/App/EdwardNG.pm index 2d81020..e778d6a 100644 --- a/lib/App/EdwardNG.pm +++ b/lib/App/EdwardNG.pm @@ -9,6 +9,7 @@ our @EXPORT = qw/process_message/; use Email::Sender::Simple qw/sendmail/; use File::Slurp qw/read_file/; +use File::Spec::Functions qw/rel2abs/; use Getopt::Long; use MIME::Entity; use MIME::Parser; @@ -95,13 +96,16 @@ sub run { '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 { @@ -109,10 +113,11 @@ sub run { } 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, 'tmpl'); my $data; $tt->process($tmpl, \%params, \$data); my $email = MIME::Entity->build( @@ -124,7 +129,7 @@ sub run { 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 } @@ -163,8 +168,6 @@ App::EdwardNG - GnuPG email sign/encrypt testing bot EdwardNG is a reimplementation of the Edward reply bot referenced in L. -It takes mail messages, checks them for PGP signatures and encryption, then replies appropriately. - This module exports a single function, B, which takes a single parameter representing the message. This parameter can be: =over