| 1 |
#! /usr/bin/env ruby |
| 2 |
|
| 3 |
require 'gpgmime.rb' |
| 4 |
|
| 5 |
def help |
| 6 |
infostr = <<INFO |
| 7 |
gpgmime - GnuPG encryption and decryption for MIME messages |
| 8 |
|
| 9 |
This application is used for encryption and decryption of |
| 10 |
GPG/Mime encoded email. It receives the complete MIME |
| 11 |
message consisted out of mail header and MIME formated |
| 12 |
content from standard input and writes the encoded respectively |
| 13 |
decoded result to standard output. |
| 14 |
|
| 15 |
Invocation: gpgmime [option] [passphrase] |
| 16 |
|
| 17 |
options: |
| 18 |
|
| 19 |
decode: decrypts GPG encoded input stream respectively |
| 20 |
checks GPG clear text signature. This is the |
| 21 |
default option. Passphrase is required as 2nd |
| 22 |
argument. |
| 23 |
|
| 24 |
encrypt: encrypts input stream to GPG/Mime message format. |
| 25 |
Uses all recipients declared in Mime header for |
| 26 |
encryption. Pay attention that BCC recipients |
| 27 |
are not included within Mime-header. |
| 28 |
|
| 29 |
encrypt_and_sign: same as encrypt but the message is signed in |
| 30 |
addition. Requires passphrase as 2nd argument. |
| 31 |
|
| 32 |
clear_sign: generates a clear text signature in GPG/Mime |
| 33 |
message format. Requires passphrase as 2nd |
| 34 |
argument. |
| 35 |
|
| 36 |
(C) 2009/09, GNU-General-Public-Licence, Author: Otto Linnemann |
| 37 |
INFO |
| 38 |
|
| 39 |
puts infostr |
| 40 |
end |
| 41 |
|
| 42 |
result_code = 0 |
| 43 |
|
| 44 |
if ARGV.length < 1 || ARGV.length > 2 |
| 45 |
help |
| 46 |
else |
| 47 |
mimeParser = GpgMime.new |
| 48 |
option = "" |
| 49 |
passphrase = "" |
| 50 |
|
| 51 |
if ARGV.length == 2 |
| 52 |
option = ARGV[0] |
| 53 |
passphrase = ARGV[1] |
| 54 |
else |
| 55 |
option = "decode" |
| 56 |
passphrase = ARGV[0] |
| 57 |
end |
| 58 |
|
| 59 |
if mimeParser.respond_to? :"#{option}" |
| 60 |
mimeParser.read_next_message( $stdin ) |
| 61 |
gpg_error_msg = mimeParser.send( :"#{option}", passphrase ) |
| 62 |
if gpg_error_msg.length == 0 |
| 63 |
puts mimeParser.getMessage |
| 64 |
else |
| 65 |
STDERR.puts gpg_error_msg |
| 66 |
result_code = -1 |
| 67 |
end |
| 68 |
else |
| 69 |
$stderr.puts "method #{option} undefined error!" |
| 70 |
end |
| 71 |
end |
| 72 |
|
| 73 |
exit result_code |
| 74 |
__END__ |