App-Eduard

 view release on metacpan or  search on metacpan

lib/App/Eduard.pm  view on Meta::CPAN

use File::Spec::Functions qw/rel2abs/;
use IO::Handle;
use Getopt::Long;
use MIME::Entity;
use MIME::Parser;
use Mail::GnuPG;
use PerlX::Maybe;
use Template;
use Try::Tiny;

sub debug { say STDERR @_ if $ENV{EDUARD_DEBUG} }
sub stringify ($) { join '', map {; '>', $_ } @{$_[0]} }
sub mg {
	Mail::GnuPG->new(
		key                => $ENV{EDUARD_KEY},
		maybe always_trust => $ENV{EDUARD_ALWAYS_TRUST},
		maybe keydir       => $ENV{EDUARD_KEYDIR},
		maybe passphrase   => $ENV{EDUARD_PASSPHRASE},
		maybe use_agent    => $ENV{EDUARD_USE_AGENT},
		@_);
}

lib/App/Eduard.pm  view on Meta::CPAN

		'passphrase=s'  => \$ENV{EDUARD_PASSPHRASE},
		'tmpl-path=s'   => \$ENV{EDUARD_TMPL_PATH},
		'use-agent!'    => \$ENV{EDUARD_USE_AGENT},
	);
	my $tmpl_path = $ENV{EDUARD_TMPL_PATH} // 'en';
	open STDERR, '>>', $ENV{EDUARD_LOGFILE} if $ENV{EDUARD_LOGFILE};

	my $in = mp->parse(\*STDIN);
	debug 'Received mail from ', $in->get('From');
	my @keys = import_pubkeys $in, mg;
	say 'Found keys: ', join ' ', @keys if @keys;

	my ($tmpl, %params);
	try {
		($tmpl, %params) = process_message $in
	} catch {
		($tmpl, %params) = (error => message => $_)
	};
	debug "Result is $tmpl, GnuPG said:\n", $params{message};

	$params{plaintext} = first_part $params{decrypted} if $params{decrypted};

lib/App/Eduard.pm  view on Meta::CPAN


=head1 NAME

App::Eduard - GnuPG email sign/encrypt testing bot

=head1 SYNOPSIS

  use App::Eduard;
  my ($status, %params) = process_message '/path/to/message';
  if ($status eq 'signencrypt') {
    say 'This message is encrypted and signed with key ', $params{keyid}, ' from ', $params{email};
    say 'Its contents are: ', $params{plaintext};
  } elsif ($status eq 'encrypt') {
    say 'This message is encrypted but not signed';
    say 'Its contents are: ', $params{plaintext};
  } elsif ($status eq 'encrypt_error') {
    say 'This message is encrypted but I was unable to decrypt it. GnuPG output: ', $params{message};
  } elsif ($status eq 'sign') {
    say 'This message is signed with key ', $params{keyid}, ' from ', $params{email};
  } elsif ($status eq 'sign_error') {
    say 'This message is signed but I was unable to verify the signature. GnuPG output: ', $params{message};
  } elsif ($status eq 'plain') {
    say 'This message is neither signed nor encrypted';
  } elsif ($status eq 'error') {
    say 'There was an error processing the message: ', $params{message};
  }

=head1 DESCRIPTION

Eduard is Ceata's reimplementation of the Edward reply bot referenced in L<https://emailselfdefense.fsf.org/>.

=head1 EXPORTS

None by default.



( run in 1.986 second using v1.01-cache-2.11-cpan-a1f116cd669 )