/** \file fetchmail.h header file for fetchmail */ #ifndef _FETCHMAIL_H #define _FETCHMAIL_H /* * For license terms, see the file COPYING in this directory. */ #include "config.h" struct addrinfo; /* We need this for size_t */ #include /* We need this for time_t */ #if TIME_WITH_SYS_TIME # include # include #else # if HAVE_SYS_TIME_H # include # else # include # endif #endif #ifdef HAVE_SYS_SOCKET_H #include #endif #ifdef HAVE_NET_SOCKET_H #include #endif #include #include /* Import Trio if needed */ #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) # include "trio/trio.h" #endif #include "fm_strl.h" #include "uid_db.h" /* constants designating the various supported protocols */ #define P_AUTO 1 #define P_POP2 2 #define P_POP3 3 #define P_APOP 4 #define P_RPOP 5 #define P_IMAP 6 #define P_ETRN 7 #define P_ODMR 8 #define SMTP_PORT "smtp" #define SMTP_PORT_NUM 25 #define KPOP_PORT "kpop" #ifdef SSL_ENABLE #define SIMAP_PORT 993 #define SPOP3_PORT 995 #endif /* * We need to distinguish between mailbox and mailbag protocols. * Under a mailbox protocol wwe're pulling mail for a speecific user. * Under a mailbag protocol we're fetching mail for an entire domain. */ #define MAILBOX_PROTOCOL(ctl) ((ctl)->server.protocol < P_ETRN) /* authentication types */ #define A_ANY 0 /* use the first method that works */ #define A_PASSWORD 1 /* password authentication */ #define A_NTLM 2 /* Microsoft NTLM protocol */ #define A_CRAM_MD5 3 /* CRAM-MD5 shrouding (RFC2195) */ #define A_OTP 4 /* One-time password (RFC1508) */ #define A_KERBEROS_V4 5 /* authenticate w/ Kerberos V4 */ #define A_KERBEROS_V5 6 /* authenticate w/ Kerberos V5 */ #define A_GSSAPI 7 /* authenticate with GSSAPI */ #define A_SSH 8 /* authentication at session level */ #define A_MSN 9 /* same as NTLM with keyword MSN */ #define A_EXTERNAL 10 /* external authentication (client cert) */ /* some protocols or authentication types (KERBEROS, GSSAPI, SSH) don't * require a password */ #define NO_PASSWORD(ctl) \ ((ctl)->server.authenticate == A_OTP \ || (ctl)->server.authenticate == A_KERBEROS_V4 \ || (ctl)->server.authenticate == A_KERBEROS_V5 \ || (ctl)->server.authenticate == A_GSSAPI \ || (ctl)->server.authenticate == A_SSH \ || (ctl)->server.authenticate == A_EXTERNAL \ || (ctl)->server.protocol == P_ETRN) /* * Definitions for buffer sizes. We get little help on setting maxima * from IMAP RFCs up to 2060, so these are mostly from POP3. */ #define HOSTLEN 635 /* max hostname length (RFC1123) */ #define POPBUFSIZE 512 /* max length of response (RFC1939) */ #define IDLEN 128 /* max length of UID (RFC1939) */ /* per RFC1939 this should be 40, but Microsoft Exchange ignores that limit */ #define USERNAMELEN 128 /* max POP3 arg length */ /* clear a netBSD kernel parameter out of the way */ #undef MSGBUFSIZE /* * The RFC822 limit on message line size is just 998. But * make this *way* oversized; idiot DOS-world mailers that * don't line-wrap properly often ship entire paragraphs as * lines. */ #define MSGBUFSIZE 8192 #define NAMELEN 64 /* max username length */ #define PASSWORDLEN 256 /* max password length */ #define DIGESTLEN 33 /* length of MD5 digest */ /* exit code values */ /* NOTE THAT PS_SUCCESS MUST ALWAYS BE 0 - SOME PARTS OF THE CODE * RELY ON THIS VALUE! */ #define PS_SUCCESS 0 /* successful receipt of messages */ #define PS_NOMAIL 1 /* no mail available */ #define PS_SOCKET 2 /* socket I/O woes */ #define PS_AUTHFAIL 3 /* user authorization failed */ #define PS_PROTOCOL 4 /* protocol violation */ #define PS_SYNTAX 5 /* command-line syntax error */ #define PS_IOERR 6 /* bad permissions on rc file */ #define PS_ERROR 7 /* protocol error */ #define PS_EXCLUDE 8 /* client-side exclusion error */ #define PS_LOCKBUSY 9 /* server responded lock busy */ #define PS_SMTP 10 /* SMTP error */ #define PS_DNS 11 /* fatal DNS error */ #define PS_BSMTP 12 /* output batch could not be opened */ #define PS_MAXFETCH 13 /* poll ended by fetch limit */ #define PS_SERVBUSY 14 /* server is busy */ /* leave space for more codes */ #define PS_UNDEFINED 23 /* something I hadn't thought of */ #define PS_TRANSIENT 24 /* transient failure (internal use) */ #define PS_REFUSED 25 /* mail refused (internal use) */ #define PS_RETAINED 26 /* message retained (internal use) */ #define PS_REPOLL 28 /* repoll immediately with changed parameters (internal use) */ #define PS_IDLETIMEOUT 29 /* timeout on imap IDLE (internal use) */ #define PS_UNTAGGED 30 /* untagged response on imap command (internal use) */ /* output noise level */ #define O_SILENT 0 /* mute, max squelch, etc. */ #define O_NORMAL 1 /* user-friendly */ #define O_VERBOSE 2 /* chatty */ #define O_DEBUG 3 /* prolix */ #define O_MONITOR O_VERBOSE #define SIZETICKER 1024 /* print 1 dot per this many bytes */ /* * We #ifdef this and use flag rather than bool * to avoid a type clash with curses.h */ #ifndef TRUE #define FALSE 0 #define TRUE 1 #endif /* TRUE */ typedef char flag; /* we need to use zero as a flag-uninitialized value */ #define FLAG_TRUE 2 #define FLAG_FALSE 1 /** run control data */ struct runctl { char *logfile; /** where to write log information */ char *idfile; /** where to store UID data */ char *pidfile; /** where to record the PID of daemon mode processes */ const char *postmaster; char *properties; int poll_interval; /** poll interval in seconds (daemon mode, 0 == off) */ flag bouncemail; flag spambounce; flag softbounce; flag use_syslog; flag invisible; flag showdots; }; /** \name idlist */ /** Dual-use entry of singly-linked list for storing id/status or id/id2 * pairs. */ struct idlist { char *id; /**< key */ union { struct { int num; flag mark; /**< UID-index information */ } status; /**< value for id/status pairs */ char *id2; /**< value for id/id2 pairs */ } val; /**< union to store value for key \a id */ struct idlist *next; /**< pointer to next list element */ }; /** List of possible values for idlist::mark */ enum { UID_UNSEEN= 0, /**< id hasn't been seen */ UID_SEEN= 1, /**< id was seen, but not deleted */ UID_DELETED= 2, /**< this message has been marked deleted */ UID_EXPUNGED= 3 /**< this message has been expunged */ }; /**/ struct query; struct method /* describe methods for protocol state machine */ { const char *name; /* protocol name */ const char *service; /* service port (unencrypted) */ const char *sslservice; /* service port (SSL) */ flag tagged; /* if true, generate & expect command tags */ flag delimited; /* if true, accept "." message delimiter */ int (*parse_response)(int, char *); /* response_parsing function */ int (*getauth)(int, struct query *, char *); /* authorization fetcher */ int (*getrange)(int, struct query *, const char *, int *, int *, int *); /* get message range to fetch */ int (*getsizes)(int, int, int *); /* get sizes of messages */ int (*getpartialsizes)(
#!/bin/sh

MSG() {
cat << EOF

# Fetchsetup is a shell script for creating a .fetchmailrc file,  
# that will be used by the program "fetchmail" to connect to your 
# mail domain and retrieve your mail. 
# This script is linux specific, so it may not work on another system.
# Kent Robotti <krobot@erols.com> (3-31-99)

EOF
}

if [ ! "$UID" = "0" ]; then
echo "[$LOGNAME] You need to be [root] to run this script."
echo "You could login: root"
echo "You could also try one of these: # sudo fetchsetup"
echo "                                 # su -c fetchsetup"
exit 1
fi

MSG
echo -n "Continue? (Y/n) : "
read ans
if [ "$ans" = "n" -o "$ans" = "N" ]; then
echo "Cancelled."
exit 0
fi

stty erase "^?" 2>/dev/null

echo
echo "Remote mail site?: pop.boo.com   <Your service providers mail domain name>"
echo -n "Remote mail site?: "
read SITE
echo
echo "Protocol?: pop3   <My service provider uses the 'pop3' mail protocol>"
echo "Protocol?: auto   <If not sure put: auto>"
echo "Choices: apop auto etrn imap imap-gss imap-k4 kpop pop2 pop3 rpop sdps" 
echo -n "Protocol?: "
read PROTO
echo
echo "Remote username?: jerry   <My username or login is jerry>"
echo -n "Remote username?: "
read USR
echo
echo "Remote password?: ?       <What's the password for?: $USR>"
echo -n "Remote password?: "
read PASS

echo
echo -n "Create $HOME/.fetchmailrc file? (Y/n) : "
read ans
if [ "$ans" = "n" -o "$ans" = "N" ]; then
echo
echo "Fetchsetup cancelled."
echo
exit 0
fi

echo 'poll "'$SITE'"' > $HOME/.fetchmailrc
echo "protocol $PROTO" >> $HOME/.fetchmailrc
echo 'username "'$USR'"' >> $HOME/.fetchmailrc
echo 'password "'$PASS'"' >> $HOME/.fetchmailrc
 
PROCMAIL=`type -all procmail | sed -n "1 p" | cut -d' ' -f3`  
SENDMAIL=`type -all sendmail | sed -n "1 p" | cut -d' ' -f3`  

if [ ! "$PROCMAIL" = "" ]; then
echo 'mda "'$PROCMAIL -d %s'"' >> $HOME/.fetchmailrc
MDA="1"
elif [ ! "$SENDMAIL" = "" ]; then
echo 'mda "'$SENDMAIL %s'"' >> $HOME/.fetchmailrc
MDA="2"
else
MDA="3"
fi 

echo >> $HOME/.fetchmailrc
echo
echo "This is your $HOME/.fetchmailrc file."

chmod 600 $HOME/.fetchmailrc

echo
cat $HOME/.fetchmailrc

if [ ! "$MAIL" = "" ]; then
echo "Fetchmail will retrieve your mail and put it in:"
echo "$MAIL"
if [ ! -f "$MAIL" ]; then
touch $MAIL 2>/dev/null
chmod 600 $MAIL 2>/dev/null
fi
fi

echo
if [ "$MDA" = "1" ]; then
echo "I put that (m)ail (d)elivery (a)gent in .fetchmailrc"
echo "because i found it on your system, this doesn't mean" 
echo "it's correct or the one you want to use."
echo
echo "The first time you run fetchmail, you should run it"
echo "this way: # fetchmail -k"
echo
elif [ "$MDA" = "2" ]; then
echo "You seem to have sendmail, sendmail will be used"
echo "as the (m)ail (d)elivery (a)gent for fetchmail."
echo
echo "WARNING! There's no way to know if sendmail is set up"
echo "properly for local mail delivery, so the first time you"
echo "run fetchmail run it this way: # fetchmail -k"
echo
echo "If the mail that fetchmail retrieves is not put in your mailbox," 
echo "you'll know that sendmail is not set up properly for the delivery" 
echo "of local mail."
echo
elif [ "$MDA" = "3" ]; then
echo "I Don't know what (m)ail (d)elivery (a)gent you're going to use."
echo "You need a <mda> to deliver the mail to you, after <fetchmail> retrieves it."
echo
echo "Put the <mda> in your .fetchmailrc file, like below."
echo "password $PASS"
echo mda