-
Notifications
You must be signed in to change notification settings - Fork 2
/
mdecrypt
executable file
·58 lines (48 loc) · 1.52 KB
/
mdecrypt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
# usage: mdecrypt msgno msgno:msgno ...
# We temporarily store the passphrase in a file, which we assume is in
# an encrypted filesystem. YMMV. We should probably change this to
# use file descriptors instead.
MBLAZE=${MBLAZE-$HOME/.mblaze}
crypt_tmp=$(mhdr -h CryptTmp "$MBLAZE/profile")
[ -z "${crypt_tmp}" ] && crypt_tmp=$HOME/mine/tmp
crypt_file_cmd=$(mhdr -h CryptFileCmd "$MBLAZE/profile")
[ -z "${crypt_file_cmd}" ] && crypt_file_cmd="fdm -acrypto fetch"
read_password () {
typeset something
stty -echo
read something
stty echo
echo "${something}"
}
read_passphrase () {
typeset pp
echo -n "passphrase: "
pp=$(read_password)
passphrase=${crypt_tmp}/pp
echo ${pp} > ${passphrase}
}
passphrase=""
# scan the input files for to/cc/bcc addresses and display them. we
# do this so the user knows what passphrase is appropriate
for picker in $*; do
mpick ${picker} | while read filename; do
mhdr -M -h to:cc:bcc ${filename}
done
done 2>/dev/null | sort -u
# this drops the passphrase into the file named ${passphrase}
# it should really only be done into a cryptofs, c.f. the
# CryptoTmp profile setting
read_passphrase
# now iterate over all the messages again and run them through GnuPG
# with that passphrase.
for picker in $*; do
mpick ${picker} | while read filename; do
# pass the Date header around gpg's back since it
# won't preserve it
(echo -n 'Date: '; mhdr -h Date ${filename}; \
mshow -r ${filename} | gpg --passphrase-file=${passphrase}) |\
${crypt_file_cmd}
done
done
rm -fP ${crypt_tmp}/pp