aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/maildaemon
blob: 3728c333054786ffcd5a9e7873af7a463f720cac (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
#
# maildaemon, fetchmail driver intended to be invoked hourly by cron.
#
# Script by Larry Fahnoe <fahnoe@kegworks.mn.org>, who writes:
#
# This is intended to support a standalone system (NeXTSTEP in this case) 
# which makes manual, on-demand PPP connections to the outside world.  The
# script is run as the target user from cron on an hourly basis.  If it
# finds a PPP link is up (it sees routes on a PPP interface), fetchmail is
# invoked.  If the link is not up, and the hour is in the list of hours that
# connections should be made, the link is brought up and fetchmail is
# invoked.  The program or script used to bring up the link should return an
# exit status which reflects whether the link actually came up. 
# 
# I wrote this because I wanted to be able to have control over the amount
# of time spent connected to an ISP and yet still be able to poll for mail
# at intervals that made sense to me.  One limitation of this script is that
# it does not take into account that an existing PPP link might be going to
# a different ISP or network.
#

# You'll have to configure these
USER=fahnoe			# your name
HOME=/Users/fahnoe		# home directory (for the logfile)
FORCEHOURS="05 09 13 17"	# when to bring the link up if it's not already
SERVER=mailserver.isp.com	# mailserver host name

# Link initialization and wrapup scripts (you may have to configure these)
PPPUP="/usr/local/bin/pppup $SERVER"
PPPDOWN=/usr/local/bin/pppdown

PATH=/usr/local/bin:/bin:/usr/ucb:/usr/bin:/usr/etc
export PATH USER HOME

LOG=$HOME/log/maildaemon.log

# get the mail, depends on $HOME/.fetchmailrc and $USER
FETCHMAIL( ) {
    ( echo "`date` $SERVER"
      fetchmail $SERVER
      if [ $? -gt 1 ]
      then
          echo "`date` $SERVER (evil things happened in fetchmail)"
      fi
    ) >> $LOG 2>&1
}

# if the link is already up, check for mail.
# if the hour is in FORCEHOURS, force the link up and check for mail.
(netstat -rn | awk '{ print $6 }' | grep ppp[0-9] > /dev/null)
if [ $? -eq 0 ]
then
    FETCHMAIL
else
    hour=`date | sed -e 's/:/ /g' | awk '{ print $4 }'`
    for x in $FORCEHOURS
    do
        if [ $hour = $x ]
        then
            $PPPUP
            if [ $? -eq 0 ]
            then
                FETCHMAIL
                $PPPDOWN
            else
                echo "`date` $SERVER (link establishment failure)" >> $LOG
                exit 1
            fi
        fi
    done
fi

exit
d needs to run without root permissions</li> <li>all input must be validated, all strings must be length checked, all integers range checked</li> <li>all types will need to be reviewed whether they are signed or unsigned</li> </ul> <h2>SMTP forwarding</h2> <p>Fetchmail's multidrop and rewrite options will process addresses received from remote sites. Special care must be taken so these features cannot be abused to relay mail to foreign sites.</p> <p>ESR's attempt to make fetchmail use SMTP exclusively failed, fetchmail got LMTP and --mda options &ndash; the latter has a lot of flaws unfortunately, is inconsistent with the SMTP forwarder and needs to be reviewed and probably bugfixed. --mda doesn't properly work with multiple recipients, it cannot properly communicate errors and is best avoided for now.</p> <h2>Server-side vs. client-side state.</h2> <h3>Why we need client-side tracking</h3> <p>ESR asserted that server-side state were essential and those persons repsonsible for removing the LAST command from POP3 deserved to suffer. ESR is right in stating that the POP3 UID tracks which messages have been read <em>by this client</em> &ndash; and that is exactly what we need to do.</p> <p>If fetchmail is supposed to retrieve all mail from a mailbox reliably, without being disturbed by someone occasionally using another client on another host, or a webmailer, or similar, then <em>client</em>-side tracking of the state is indispensable. This is also needed to match behavior to ETRN and ODMR or to support read-only mailboxes in --keep mode.</p> <h3>Present and future</h3> <p>Fetchmail supports client-side state in POP3 if the UIDL option is used (which is strongly recommended). Similar effort needs to be made to track IMAP state by means of UIDVALIDITY and UID.</p> <p>This will also mean that the UID handling code be revised an perhaps use one file per account or per folder.</p> <h2>Concurrent queries/concurrent fetchmail instances</h2> <p>ESR refused to make fetchmail query multiple hosts or accounts concurrently, on the grounds that finer-grained locks would be hard to implement portably.</p> <p>The idea of using one file per folder or account to track UIDs on the client-side will make solving this locking problem easy &ndash; the lock can be placed on the UID file instead.</p> <h2>Multidrop issues</h2> <p>Fetchmail tries to guess recipients from headers that are not routing relevant, for instance, To:, Cc:, or Resent-headers (which are rare anyways). It is important that fetchmail insists on the real envelope operation for multidrop. This is detailed in <a href="http://home.pages.de/~mandree/mail/multidrop">my article &quot;Requisites for working multidrop mailboxes&quot;</a>.</p> <p>As Terry Lambert pointed out in the FreeBSD-arch mailing list on 2001-02-17 under the subject "UUCP must stay; fetchmail sucks", fetchmail performs DNS MX lookups to determine domains for which multidrop is valid, on the assumption that the receiving SMTP host upstream were the same as the IMAP or POP3 server.</p> <hr /> <table width="100%" cellpadding="0" summary="Canned page footer"> <tr> <td width="30%">Back to <a href="index.html">Fetchmail Home Page</a></td> <td width="30%" align="right">$Date$</td> </tr> </table> <br clear="left" /> <address>Matthias Andree <a href="mailto:matthias.andree@gmx.de">&lt;matthias.andree@gmx.de&gt;</a></address> </body> </html>