diff --git a/README b/README index 833d0b5..7077c4f 100644 --- a/README +++ b/README @@ -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. diff --git a/gpgit.pl b/gpgit.pl index 7daef52..0db91a5 100755 --- a/gpgit.pl +++ b/gpgit.pl @@ -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(){ - print; +## Make sure we have the appropriate public key for all recipients + foreach( @recipients ){ + unless( $gpg->has_public_key( $_ ) ){ + while(){ + 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;