aboutsummaryrefslogtreecommitdiff
path: root/misc/poc/firma-0.1.5
blob: 029a09d3671deb8c1069e683303bcea3f986785b (plain)
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
#!/bin/bash
#
# firma v0.2: simple encrypted mailing list aliases
# feedback: rhatto@riseup.net | GPL
#
# list configuration is passed through a config file,
# where you put PARAMETER=value (whithout spaces)
#
# MAIL= path for mail program
# GPG= path for gnupg binary
# TMP= where you want the temp files
# LISTNAME= list email
# GPGDIR= gpg dir for the lists' keyring
# PASSWD= passwd for the lists' keyring
# FOOTER= message footer

# eval the config file
source $1

GPGCOMMAND="$GPG -q --homedir $GPGDIR"
GPGLIST="$GPGCOMMAND --list-keys" 
GPGDECRYPT="$GPGCOMMAND --decrypt"
GPGENCRYPT="$GPGCOMMAND --always-trust -e -s -a -r" 

rm $TMP $TMP.gpg
touch $TMP; chmod 600 $TMP;
touch $TMP.gpg; chmod 600 $TMP.gpg;

# todo: use an array
while read STDIN; do
  echo $STDIN >> $TMP
done

# get the headers
FROM=$(grep -m 1 ^From: $TMP | cut -f 2 -d :)
DATE=$(grep -m 1 ^Date: $TMP)
SUBJECT=$(grep -m 1 ^Subject: $TMP)

# detect the encrypted message
sed -n '/-----BEGIN PGP MESSAGE-----/,/-----END PGP MESSAGE-----/p' $TMP >> $TMP.gpg

# encrypting and sending for each recipient on the list
for EMAIL in $($GPGLIST | grep pub | cut -d "<" -f 2 | sed -e 's/>//' | grep @ | grep -v $LISTNAME); do 

  echo "$PASSWD
  Message from: $FROM
  $SUBJECT
  $DATE

  $(echo "$PASSWD" | $GPGDECRYPT $TMP.gpg)

  ---
  $FOOTER " | sed -e 's/=20$//' | $GPGENCRYPT $EMAIL | $MAIL -r $LISTNAME $EMAIL 

done
 
rm $TMP $TMP.gpg