mirror of
https://github.com/moparisthebest/gpgit
synced 2024-11-13 12:35:03 -05:00
first commit
This commit is contained in:
commit
6948448fcb
1
README
Normal file
1
README
Normal file
@ -0,0 +1 @@
|
||||
See https://secure.grepular.com/Automatically_Encrypting_all_Incoming_Email
|
81
gpgit.pl
Normal file
81
gpgit.pl
Normal file
@ -0,0 +1,81 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
##############################################################################
|
||||
# #
|
||||
# Copyright 2011, Mike Cardwell - https://secure.grepular.com/ #
|
||||
# #
|
||||
# This program is free software; you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License as published by #
|
||||
# the Free Software Foundation; either version 2 of the License, or #
|
||||
# any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program; if not, write to the Free Software #
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #
|
||||
# #
|
||||
##############################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Mail::GnuPG;
|
||||
use MIME::Parser;
|
||||
|
||||
## Parse args
|
||||
my $recipient_email = $ARGV[0]||'';
|
||||
|
||||
## 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;
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
## Read the plain text email
|
||||
my $plain;
|
||||
{
|
||||
local $/ = undef;
|
||||
$plain = <STDIN>;
|
||||
}
|
||||
|
||||
## Parse the email
|
||||
my $mime;
|
||||
{
|
||||
my $parser = new MIME::Parser();
|
||||
$parser->decode_bodies(1);
|
||||
$parser->output_to_core(1);
|
||||
$mime = $parser->parse_data( $plain );
|
||||
}
|
||||
|
||||
## Test if it is already encrypted
|
||||
if( $gpg->is_encrypted( $mime ) ){
|
||||
print $plain; exit 0;
|
||||
}
|
||||
|
||||
## Encrypt
|
||||
{
|
||||
$mime->make_singlepart;
|
||||
|
||||
my $code = $mime->mime_type =~ /^text\/plain/
|
||||
? $gpg->ascii_encrypt( $mime, $recipient_email )
|
||||
: $gpg->mime_encrypt( $mime, $recipient_email );
|
||||
|
||||
if( $code ){
|
||||
print $plain;
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
|
||||
## Remove some headers which might have been broken by the process of encryption
|
||||
$mime->head()->delete($_) foreach qw( DKIM-Signature DomainKey-Signature );
|
||||
|
||||
## Print out the encrypted version
|
||||
print $mime->stringify;
|
Loading…
Reference in New Issue
Block a user