]> Pileus Git - ~andy/fetchmail/blob - contrib/fetchspool
Credit John Beck's fixes.
[~andy/fetchmail] / contrib / fetchspool
1 #!/bin/sh -
2 #
3 # Quick hack for fetchmail to locally spool messages.
4 #
5 # To spool:
6 #     fetchmail --mda "fetchspool -t %T %F"
7 # To de-spool
8 #     fetchspool -f
9 #
10 # Robert de Bath  <robert@mayday.cix.co.uk>
11 # updated by william boughton <bill@xencat.demon.co.uk>
12 # 4th/10/1998 and tested
13 #
14 # William Boughton comments:
15 # Still has some potential problems, with using inline from address.
16 # The use of _ is bad because fetchmails uses this if it notices
17 # shell escapes.
18 # 10th/11/1998
19 # Changed to using 3 _@@s to delimit the message, i hope this is ok.
20 # Whilst i have tested and used this script, with my demon account and
21 # SDPS, it may still have serious problems, that i've not noticed etc.
22
23 MAILSPOOL=/tmp/spool
24
25 if [ "$1" != "-f" ]
26 then
27    if [ "$1" = "-t" ]
28    then 
29         ADDR="$2"
30         FROM="$3"
31    else 
32         ADDR="$1"
33         FROM="$2"
34    fi
35
36    cat - > $MAILSPOOL/tmp.$$                               || exit 1
37    mv $MAILSPOOL/tmp.$$ "$MAILSPOOL/msg.`date +%j%H%M%S`$$.to.${ADDR}_@@${FROM}"  || exit 1
38
39    exit 0
40 else
41    for i in $MAILSPOOL/msg.*.to.*
42    do
43       [ -f "$i" ] || continue
44      # TO="`echo \"$i\" | sed 's/^msg.[^.]*.to.//'`"
45         TO=$(basename $i | sed -e 's/^msg.[^.]*.to.//' -e 's/_@@.*$//')
46         FROM=$(basename $i | sed 's/^msg.[^.]*.to.*_@@//')
47 # need the \<\> so for bounces to have a proper from addr
48 echo the to was \<$TO\>  and the from \<$FROM\>
49       /usr/lib/sendmail -f \<${FROM}\> -oem "$TO" < "$i" ||
50       {
51          echo "Sendmail failed on `basename \"$i\"`"
52          continue
53       }
54       rm -f "$i"
55    done
56    exit 0
57 fi
58