]> git.sur5r.net Git - openldap/blob - clients/fax500/xrpcomp
Initial revision
[openldap] / clients / fax500 / xrpcomp
1 : run this script through /bin/sh
2
3 RP500=ETCDIR/rp500
4
5 NAME="$1"
6 if [ -z "$NAME" ]; then
7     echo "usage: xrpcomp name [arguments for comp]" 2>&1
8     exit 1
9 fi
10
11 DB=".rpdb"
12 if [ ! -s "$DB" ]; then
13     DB="$HOME/.rpdb"
14 fi
15 if [ ! -s "$DB" ]; then
16     echo "unable to read $DB" 2>&1
17     exit 1
18 fi
19
20 C=/tmp/rp$$.comp        S=/tmp/rp$$.sh  O=/tmp/rp$$.orig
21 trap "rm -f $C $S $O" 0 1 2 3 13 15
22
23 cp /dev/null $S
24 gawk -v NAME="$NAME" -v S="$S" -v O="$O" '
25 function rev(f) {
26     s = ""
27     for (l = length(f); l > 0; l--)
28         s = s "." substr(f, l, 1)
29     return substr(s, 2, length(s) - 1)
30 }
31
32 BEGIN   {
33             RS= ""; FS = "\n"
34         }
35         {
36             if (NR == 1) {
37                 from = $2
38                 gsub("Recipient[        ]*:", "Originator:", from);
39                 orig = "\r\n" from
40                 for (i = 3; i <= NF; i++)
41                     orig = orig "\r\n" $i;
42                 printf orig "\r\n" > O
43             }
44
45             if ($1 != NAME)
46                 next
47             for (i = 2; i <= NF; i++) {
48                 if (match($i, "Facsimile[       ]*:") > 0) {
49                     fax = substr($i, RSTART+RLENGTH)
50                     gsub("[     +-]", "", fax)
51
52                     printf "ADDR=\"remote-printer@%s.tpc.int\"\n", rev(fax) > S
53                     printf "To: remote-printer@%s.tpc.int\n", rev(fax)
54                     printf "Subject:\n"
55                     printf "--------\n"
56                     printf "#<application/remote-printing\n"
57
58                     recip = $2
59                     for (i = 3; i <= NF; i++)
60                         recip = recip "\r\n" $i;
61                     printf "%s\r\n%s\r\n", recip, orig
62
63                     printf "#\n"
64                     exit(0)
65                 }
66             }
67         }' < $DB > $C
68 . $S
69 if [ -z "$ADDR" ]; then
70     echo "recipient \"$NAME\" not in $DB, checking X.500..." 2>&1
71     $RP500 "$NAME" > $C
72     RC=$?
73     if [ $RC = 1 ]; then
74         exit 1
75     elif [ $RC = 0 ]; then
76         cat $O >> $C
77         echo "#" >> $C
78     else
79         echo "error searching X.500" 2>&1
80         exit 1
81     fi
82 fi
83
84 shift
85 comp -form $C $* -editor rpprompter