1
0
mirror of https://github.com/moparisthebest/gpgit synced 2024-11-15 21:45:03 -05:00

Encrypt for multiple email addresses

This commit is contained in:
Mike Cardwell 2011-02-24 11:26:54 +00:00
parent dbbd5496eb
commit e2f8c03627
2 changed files with 14 additions and 10 deletions

3
README
View File

@ -3,7 +3,8 @@ See https://grepular.com/Automatically_Encrypting_all_Incoming_Email
This application takes one argument on the command line. The email address to
look up the public key that the message will be encrypted with. An email
message is piped through the application, and the resulting email is sent to
STDOUT encrypted with the relevant public key.
STDOUT encrypted with the relevant public key. If you provide multiple email
addresses, then the message will be encrypted with multiple keys.
If the message is already encrypted, it doesn't get encrypted a second time. If
the message has multiple parts, PGP/MIME is used, otherwise inline PGP is used.

View File

@ -26,18 +26,21 @@ use Mail::GnuPG;
use MIME::Parser;
## Parse args
my $recipient_email = $ARGV[0]||'';
die "Bad arguments. Must supply a valid email address" unless $recipient_email =~ /^.+\@.+$/;
my @recipients = @ARGV;
die "Bad arguments. Missing email address\n" unless int(@recipients);
die "Bad arguments. Invalid email address\n" if grep( !/^.+\@.+$/, @recipients );
## Object for GPG encryption
my $gpg = new Mail::GnuPG();
## Make sure we have the appropriate public key
unless( $gpg->has_public_key( $recipient_email ) ){
while(<STDIN>){
print;
## Make sure we have the appropriate public key for all recipients
foreach( @recipients ){
unless( $gpg->has_public_key( $_ ) ){
while(<STDIN>){
print;
}
exit 0;
}
exit 0;
}
## Read the plain text email
@ -66,8 +69,8 @@ use MIME::Parser;
$mime->make_singlepart;
my $code = $mime->mime_type =~ /^text\/plain/
? $gpg->ascii_encrypt( $mime, $recipient_email )
: $gpg->mime_encrypt( $mime, $recipient_email );
? $gpg->ascii_encrypt( $mime, @recipients )
: $gpg->mime_encrypt( $mime, @recipients );
if( $code ){
print $plain;