X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApp%2FEdwardNG.pm;h=2d81020ea24ca6a287929f1b683cf3dc0844be3c;hb=4224c4cea857a8ff83c22523e4adcf8e0568c042;hp=6ccc05942f977b6e118406d2e70877fa1c1d4989;hpb=2f9e679a099ab2e59aed109e1d5e3555b5c23b57;p=app-edwardng.git diff --git a/lib/App/EdwardNG.pm b/lib/App/EdwardNG.pm index 6ccc059..2d81020 100644 --- a/lib/App/EdwardNG.pm +++ b/lib/App/EdwardNG.pm @@ -36,25 +36,17 @@ sub first_part{ } sub process_message { - my ($msg) = @_; + my ($in) = @_; + my $msg; my $parser = MIME::Parser->new; $parser->decode_bodies(0); $parser->output_to_core(1); - if (ref $msg eq 'MIME::Entity') { - debug 'Got MIME::Entity'; - } elsif (ref $msg eq 'IO') { - debug 'Parsing from filehandle'; - $msg = $parser->parse($msg) - } elsif (ref $msg eq 'SCALAR') { - debug 'Parsing from string'; - $msg = $parser->parse_data($$msg) - } elsif (!ref $msg) { - debug "Parsing from file $msg"; - $msg = $parser->parse_open($msg) - } else { - die "Don't know how to parse $msg" - } + $msg = $in if ref $in eq 'MIME::Entity'; + $msg = $parser->parse ($in) if ref $in eq 'IO'; + $msg = $parser->parse_data ($in) if ref $in eq 'SCALAR'; + $msg = $parser->parse_open ($in) unless ref $in; + die "Don't know how to parse $in" unless $msg; if ($msg->mime_type ne 'multipart/signed' && $msg->mime_type ne 'multipart/encrypted') { # PGP/Inline requires decoding @@ -121,18 +113,19 @@ sub run { $params{plaintext} = first_part $params{decrypted} if $params{decrypted}; my $tt = Template->new(INCLUDE_PATH => 'tmpl/en'); - my ($data, $subject); + my $data; $tt->process($tmpl, \%params, \$data); - $tt->process('subject', undef, \$subject); my $email = MIME::Entity->build( From => $ENV{EDWARDNG_FROM}, To => $in->get('From'), - Subject => $subject, + Subject => 'Re: ' . $in->get('Subject'), Data => $data); + my $email_unencrypted = $email->dup; my $mg = mg always_trust => 1; - $mg->mime_signencrypt($email, $in->get('From') =~ /<(.*)>/) and debug 'Could not encrypt message. GnuPG said ', stringify $mg->{last_message}; - sendmail $email + 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; + sendmail $encrypt_failed ? $email_unencrypted : $email } 1; @@ -234,7 +227,7 @@ Marius Gavrilescu, Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2014 by Marius Gavrilescu +Copyright (C) 2014 by Fundația Ceata This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or,