diff options
-rw-r--r-- | daemon.c | 45 | ||||
-rw-r--r-- | driver.c | 200 | ||||
-rw-r--r-- | fetchmail.c | 83 | ||||
-rw-r--r-- | imap.c | 21 | ||||
-rw-r--r-- | options.c | 47 | ||||
-rw-r--r-- | pop2.c | 16 | ||||
-rw-r--r-- | pop3.c | 12 | ||||
-rw-r--r-- | rcfile_l.l | 11 | ||||
-rw-r--r-- | rcfile_y.y | 2 | ||||
-rw-r--r-- | smtp.c | 126 | ||||
-rw-r--r-- | socket.c | 15 | ||||
-rw-r--r-- | uid.c | 12 | ||||
-rw-r--r-- | xmalloc.c | 13 |
13 files changed, 130 insertions, 473 deletions
@@ -1,19 +1,9 @@ /* + * damemon.c -- turn a process into a daemon under POSIX, SYSV, BSD. + * * For license terms, see the file COPYING in this directory. */ - -/*********************************************************************** - module: daemon - project: fetchmail - programmer: Carl Harris, ceharris@mal.com - description: This module contains all of the code needed to - turn a process into a daemon for POSIX, SysV, and - BSD systems. - - ***********************************************************************/ - - #include <config.h> #include <stdio.h> @@ -41,19 +31,9 @@ #include "fetchmail.h" -/****************************************************************** - function: sigchld_handler - description: Process the SIGCHLD (a.k.a SIGCLD) signal by calling - a wait() variant to obtain the exit code of the - terminating process. - arguments: none. - ret. value: none (or undefined if REGSIGTYPE is int). - globals: none. - calls: none. - *****************************************************************/ - RETSIGTYPE sigchld_handler () +/* process SIGCHLD/SIGCLD to obtain the exit code of the terminating process */ { pid_t pid; @@ -75,24 +55,9 @@ sigchld_handler () } - - -/****************************************************************** - function: daemonize - description: become a daemon process; i.e. detach from the - control terminal, don't reacquire a control terminal, - become process group leader of our own process group, - and set up to catch child process termination signals. - arguments: - logfile file to direct stdout and stderr to, if non-NULL. - - ret. value: none. - globals: termhook, sigchld_handler(). - calls: none. - *****************************************************************/ - int daemonize (logfile, termhook) +/* detach from control TTY, become process group leader, catch SIGCHLD */ const char *logfile; void (*termhook)(int); { @@ -210,3 +175,5 @@ nottyDetach: signal(SIGPWR, sigchld_handler); #endif } + +/* daemon.c ends here */ @@ -1,16 +1,11 @@ -/* Copyright 1996 by Eric S. Raymond +/* + * driver.c -- generic driver for mail fetch method protocols + * + * Copyright 1996 by Eric S. Raymond * All rights reserved. * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: driver.c - project: fetchmail - programmer: Eric S. Raymond - description: Generic driver for mail fetch method protocols - - ***********************************************************************/ - #include <config.h> #include <stdio.h> #if defined(STDC_HEADERS) @@ -49,23 +44,10 @@ static int tagnum; static char *shroud; -/********************************************************************* - function: - description: hack message headers so replies will work properly - - arguments: - after where to put the hacked header - before header to hack - host name of the pop header - - return value: none. - calls: none. - *********************************************************************/ - static void reply_hack(buf, host) -/* hack local mail IDs -- code by Eric S. Raymond 20 Jun 1996 */ -char *buf; -const char *host; +/* hack message headers so replies will work properly */ +char *buf; /* header to be hacked */ +const char *host; /* server hostname */ { const char *from; int state = 0; @@ -151,25 +133,19 @@ const char *host; *buf++ = '\0'; } -/********************************************************************* - function: nxtaddr - description: Parse addresses in succession out of a specified RFC822 - header. Note 1: RFC822 escaping with \ is *not* handled. - Note 2: it is important that this routine not stop on \r, - since we use \r as a marker for RFC822 continuations below. - arguments: - hdr header line to be parsed, NUL to continue in previous hdr - - return value: next address, or NUL if there is no next address - calls: none - *********************************************************************/ - static char *nxtaddr(hdr) -char *hdr; +/* parse addresses in succession out of a specified RFC822 header */ +char *hdr; /* header line to be parsed, NUL to continue in previous hdr */ { static char *hp, *tp, address[POPBUFSIZE+1]; static state; + /* + * Note 1: RFC822 escaping with \ is *not* handled. Note 2: it is + * important that this routine not stop on \r, since we use \r as + * a marker for RFC822 continuations below. + */ + if (hdr) { hp = hdr; @@ -271,30 +247,13 @@ char *hdr; return(NULL); } -/********************************************************************* - function: gen_readmsg - description: Read the message content - - as described in RFC 1225. - arguments: - socket ... to which the server is connected. - mboxfd open file descriptor to which the retrieved message will - be written. - len length of text - delimited does the protocol use a message delimiter? - queryctl host control block - - return value: zero if success else PS_* return code. - calls: SockGets. - globals: reads outlevel. - *********************************************************************/ - static int gen_readmsg (socket, mboxfd, len, delimited, queryctl) -int socket; -int mboxfd; -long len; -int delimited; -struct hostrec *queryctl; +/* read message content and ship to SMTP or MDA */ +int socket; /* to which the server is connected */ +int mboxfd; /* descriptor to which retrieved message will be written */ +long len; /* length of message */ +int delimited; /* does the protocol use a message delimiter? */ +struct hostrec *queryctl; /* query control record */ { char buf [MSGBUFSIZE+1]; char fromBuf[MSGBUFSIZE+1]; @@ -501,24 +460,11 @@ struct hostrec *queryctl; } #ifdef KERBEROS_V4 -/********************************************************************* - function: kerberos_auth - description: Authenticate to the server host using Kerberos V4 - - arguments: - socket socket to server - servername server name - - return value: exit code from the set of PS_.* constants defined in - fetchmail.h - calls: - globals: reads outlevel. - *********************************************************************/ - int kerberos_auth (socket, servername) - int socket; - char *servername; +/* authenticate to the server host using Kerberos V4 */ +int socket; /* socket to server host */ +char *servername; /* server name */ { char * host_primary; KTEXT ticket; @@ -562,25 +508,10 @@ kerberos_auth (socket, servername) } #endif /* KERBEROS_V4 */ -/********************************************************************* - function: do_protocol - description: retrieve messages from the specified mail server - using a given set of methods - - arguments: - queryctl fully-specified options (i.e. parsed, defaults invoked, - etc). - proto protocol method pointer - - return value: exit code from the set of PS_.* constants defined in - fetchmail.h - calls: - globals: reads outlevel. - *********************************************************************/ - int do_protocol(queryctl, proto) -struct hostrec *queryctl; -struct method *proto; +/* retrieve messages from server using given protocol method table */ +struct hostrec *queryctl; /* parsed options with merged-in defaults */ +struct method *proto; /* protocol method table */ { int ok, len; int mboxfd = -1; @@ -814,26 +745,15 @@ closeUp: return(ok); } -/********************************************************************* - function: gen_send - description: Assemble command in print style and send to the server - - arguments: - socket socket to which the server is connected. - fmt printf-style format - - return value: none. - calls: SockPuts. - globals: reads outlevel. - *********************************************************************/ - #if defined(HAVE_STDARG_H) void gen_send(int socket, char *fmt, ... ) +/* assemble command in printf(3) style and send to the server */ { #else void gen_send(socket, fmt, va_alist) -int socket; -const char *fmt; +/* assemble command in printf(3) style and send to the server */ +int socket; /* socket to which server is connected */ +const char *fmt; /* printf-style format */ va_dcl { #endif @@ -865,27 +785,15 @@ va_dcl { } } -/********************************************************************* - function: gen_transact - description: Assemble command in print style and send to the server. - then accept a protocol-dependent response. - - arguments: - socket socket to which the server is connected. - fmt printf-style format - - return value: none. - calls: SockPuts. - globals: reads outlevel. - *********************************************************************/ - #if defined(HAVE_STDARG_H) int gen_transact(int socket, char *fmt, ... ) +/* assemble command in printf(3) style, send to server, accept a response */ { #else int gen_transact(socket, fmt, va_alist) -int socket; -const char *fmt; +/* assemble command in printf(3) style, send to server, accept a response */ +int socket; /* socket to which server is connected */ +const char *fmt; /* printf-style format */ va_dcl { #endif @@ -922,24 +830,11 @@ va_dcl { return(ok); } -/********************************************************************* - function: strcrlf - description: replace LFs with CR-LF - - arguments: - dst new string with CR-LFs - src original string with LFs - count length of src - - return value: length of dst - calls: none. - globals: none. - *********************************************************************/ - int strcrlf(dst, src, count) -char *dst; -char *src; -int count; +/* replace LFs with CR-LF; return length of string with replacements */ +char *dst; /* new string with CR-LFs */ +char *src; /* original string with LFs */ +int count; /* length of src */ { int len = count; @@ -955,24 +850,15 @@ int count; *dst = '\0'; return len; } -/********************************************************************* - function: alarm_handler - description: In real life process can get stuck waiting for - something. This deadlock is avoided here by this - sending SIGALRM - - arguments: - signal hopefully SIGALRM - - return value: none. - calls: none - globals: sets alarmed to 1 - *********************************************************************/ + void alarm_handler (int signal) +/* handle server-timeout signal */ { alarmed = 1; fprintf(stderr, "fetchmail: timeout after %d seconds waiting for %s.\n", mytimeout, srvname); } + +/* driver.c ends here */ diff --git a/fetchmail.c b/fetchmail.c index 08ca78f9..de258a1c 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -1,18 +1,10 @@ /* + * fetchmail.c -- main driver module for fetchmail + * * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: fetchmail.c - project: fetchmail - programmer: Eric S. Raymond <esr@thyrsus.com> - description: main driver module for fetchmail - - ***********************************************************************/ - - #include <config.h> - #include <stdio.h> #if defined(STDC_HEADERS) @@ -59,19 +51,6 @@ char *rcfile; /* path name of rc file */ char *idfile; /* UID list file */ int versioninfo; /* emit only version info */ -/********************************************************************* - function: main - description: main driver routine - arguments: - argc argument count as passed by runtime startup code. - argv argument strings as passed by runtime startup code. - - return value: an exit status code for the shell -- see the - PS_.* constants defined above. - calls: parsecmdline, setdefaults, openuserfolder, doPOP2. - globals: none. - *********************************************************************/ - static void termhook(); static char *lockfile; static int popstatus; @@ -442,17 +421,8 @@ void termhook(int sig) exit(popstatus); } -/********************************************************************* - function: showproto - description: protocol index to name mapping - arguments: - proto protocol index - return value: string name of protocol - calls: none. - globals: none. - *********************************************************************/ - static char *showproto(proto) +/* protocol index to protocol name mapping */ int proto; { switch (proto) @@ -512,19 +482,9 @@ struct hostrec *queryctl; } } -/********************************************************************* - function: dump_params - description: display program options in English - arguments: - queryctl merged options - - return value: none. - calls: none. - globals: outlimit. -*********************************************************************/ - int dump_params (queryctl) -struct hostrec *queryctl; +/* display query parameters in English */ +struct hostrec *queryctl; /* query parameter block */ { printf("Options for %s retrieving from %s:\n", hostp->localname, visbuf(hostp->servername)); @@ -604,19 +564,9 @@ struct hostrec *queryctl; } } - /********************************************************************* - function: openmailpipe - description: open a one-way pipe to the mail delivery agent. - arguments: - queryctl fully-determined options (i.e. parsed, defaults invoked, - etc). - - return value: open file descriptor for the pipe or -1. - calls: none. - *********************************************************************/ - int openmailpipe (queryctl) -struct hostrec *queryctl; +/* open a one-way pipe to a mail delivery agent */ +struct hostrec *queryctl; /* query control block */ { int pipefd [2]; int childpid; @@ -652,19 +602,8 @@ struct hostrec *queryctl; return(pipefd[1]); } -/********************************************************************* - function: closemailpipe - description: close pipe to the mail delivery agent. - arguments: - queryctl fully-determined options record - fd pipe descriptor. - - return value: 0 if success, else -1. - calls: none. - globals: none. - *********************************************************************/ - int closemailpipe (fd) +/* close the pipe to the mail delivery agent */ int fd; { int err, status; @@ -702,8 +641,8 @@ int fd; void escapes(cp, tp) /* process standard C-style escape sequences in a string */ -const char *cp; -char *tp; +const char *cp; /* source string with escapes */ +char *tp; /* target buffer for digested string */ { while (*cp) { @@ -789,3 +728,5 @@ const char *buf; *tp++ = '\0'; return(vbuf); } + +/* fetchmail.c ends here */ @@ -1,28 +1,17 @@ -/* Copyright 1996 by Eric S. Raymond +/* + * imap.c -- IMAP2bis protocol methods + * + * Copyright 1996 by Eric S. Raymond * All rights reserved. * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: imap.c - project: fetchmail - programmer: Eric S. Raymond - description: IMAP client code - - ***********************************************************************/ - #include <config.h> #include <stdio.h> #include <string.h> #include "socket.h" #include "fetchmail.h" -/********************************************************************* - - Method declarations for IMAP - - *********************************************************************/ - static int count, seen; int imap_ok (socket, argbuf) @@ -201,4 +190,4 @@ struct hostrec *queryctl; return(do_protocol(queryctl, &imap)); } - +/* imap.c ends here */ @@ -1,15 +1,9 @@ /* + * options.c -- command-line option processing + * * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: options.c - project: fetchmail - programmer: Eric S. Raymond, <esr@thyrsus.com> - description: command-line option processing - - ***********************************************************************/ - #include <config.h> #include <stdio.h> #include <pwd.h> @@ -79,32 +73,20 @@ static struct option longoptions[] = { {(char *) 0, no_argument, (int *) 0, 0 } }; - -/********************************************************************* - function: parsecmdline - description: parse/validate the command line options. - arguments: - argc argument count. - argv argument strings. - queryctl pointer to a struct hostrec to receive the parsed - options. - - return value: if positive, argv index of last parsed option + 1 - (presumes one or more server names follows). - if zero, the command line switches are such that - no server names are required (e.g. --version). - if negative, the command line is has one or more - syntax errors. - calls: none. - globals: writes outlevel, versioninfo, yydebug, logfile, - poll_interval, quitmode, rcfile - *********************************************************************/ - int parsecmdline (argc,argv,queryctl) -int argc; -char **argv; -struct hostrec *queryctl; +/* parse and validate the command line options */ +int argc; /* argument count */ +char **argv; /* argument strings */ +struct hostrec *queryctl; /* option record to be initialized */ { + /* + * return value: if positive, argv index of last parsed option + 1 + * (presumes one or more server names follows). if zero, the + * command line switches are such that no server names are + * required (e.g. --version). if negative, the command line is + * has one or more syntax errors. + */ + int c; int ocount = 0; /* count of destinations specified */ int errflag = 0; /* TRUE when a syntax error is detected */ @@ -282,3 +264,4 @@ struct hostrec *queryctl; return(optind); } +/* options.c ends here */ @@ -1,16 +1,11 @@ -/* Copyright 1996 by Eric S. Raymond +/* + * pop2.c -- POP@ protocol methods + * + * Copyright 1996 by Eric S. Raymond * All rights reserved. * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: pop2.c - project: fetchmail - programmer: Eric S. Raymond - description: POP2 method code. - - ***********************************************************************/ - #include <config.h> #include <stdio.h> #include "socket.h" @@ -143,7 +138,10 @@ const static struct method pop2 = }; int doPOP2 (queryctl) +/* retrieve messages using POP2 */ struct hostrec *queryctl; { return(do_protocol(queryctl, &pop2)); } + +/* pop2.c ends here */ @@ -1,15 +1,9 @@ /* + * pop3.c -- POP3 protocol methods + * * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: pop3.c - project: fetchmail - programmer: Eric S. Raymond <esr@thyrsus.com> - description: POP3 client code. - - ***********************************************************************/ - #include <config.h> #include <stdio.h> @@ -243,4 +237,4 @@ struct hostrec *queryctl; return(do_protocol(queryctl, &pop3)); } - +/* pop3.c ends here */ @@ -1,18 +1,11 @@ %{ /* + * rcfile_l.l -- lexer for the run control file + * * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: rcfile_l.l - project: fetchmail - programmer: Carl Harris, ceharris@mal.com - Extensively hacked by esr. - description: configuration lexer - - ***********************************************************************/ - #include <config.h> #include "fetchmail.h" #include "rcfile_y.h" @@ -1,5 +1,7 @@ %{ /* + * rcfile_y.y -- Run control file parser for fetchmail + * * For license terms, see the file COPYING in this directory. */ @@ -1,18 +1,14 @@ -/* Copyright 1996 Eric S. Raymond +/* + * smtp.c -- code for speaking SMTP to a listener port + * + * Concept due to Harry Hochheiser. Implementation by ESR. Cleanup and + * strict RFC821 compliance by Cameron MacPherson. + * + * Copyright 1996 Eric S. Raymond * All rights reserved. * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: smtp.c - project: fetchmail - programmer: Harry Hochheiser - cleaned up and made rfc821 compliant by Cameron MacPherson - description: Handling of SMTP connections, and processing of mail - to be forwarded via SMTP connections. - - ***********************************************************************/ - #include <stdio.h> #include <config.h> #include <sys/types.h> @@ -22,17 +18,8 @@ #include "fetchmail.h" #include "smtp.h" -/********************************************************************* - function: SMTP_helo - description: Send a "HELO" message to the SMTP server. - - arguments: - socket TCP/IP socket for connection to SMTP - return value: Result of SMTP_OK: based on codes in fetchmail.h. - - *********************************************************************/ - int SMTP_helo(int socket,char *host) +/* send a "HELO" message to the SMTP listener */ { int ok; @@ -43,21 +30,8 @@ int SMTP_helo(int socket,char *host) return ok; } -/********************************************************************* - function: SMTP_from - description: Send a "MAIL FROM:" message to the SMTP server. - - arguments: - socket TCP/IP socket for connection to SMTP - from user name/host of originator - - Note: these args are likely to change, as we get fancier about - handling the names. - - return value: Result of SMTP_ok: based on codes in fetchmail.h. - - *********************************************************************/ int SMTP_from(int socket, char *from) +/* send a "MAIL FROM:" message to the SMTP listener */ { int ok; @@ -68,19 +42,8 @@ int SMTP_from(int socket, char *from) return ok; } -/********************************************************************* - function: SMTP_rcpt - description: Send a "RCPT TO:" message to the SMTP server. - - arguments: - socket TCP/IP socket for connection to SMTP - touser: user name of recipient - tohost: host name of recipient - - return value: Result of SMTP_OK: based on codes in fetchmail.h. - - *********************************************************************/ -int SMTP_rcpt(int socket,char *to) +int SMTP_rcpt(int socket, char *to) +/* send a "RCPT TO:" message to the SMTP listener */ { int ok; @@ -91,15 +54,8 @@ int SMTP_rcpt(int socket,char *to) return ok; } -/********************************************************************* - function: SMTP_data - description: Send a "DATA" message to the SMTP server. - - arguments: - socket TCP/IP socket for connection to SMTP - - *********************************************************************/ int SMTP_data(int socket) +/* send a "DATA" message to the SMTP listener */ { int ok; @@ -110,17 +66,8 @@ int SMTP_data(int socket) return ok; } -/********************************************************************* - function: SMTP_quit - description: Send a "QUIT" message to the SMTP server. - - arguments: - socket TCP/IP socket for connection to SMTP - - return value: Result of SMTP_OK: based on codes in fetchmail.h. - - *********************************************************************/ int SMTP_quit(int socket) +/* send a "QUIT" message to the SMTP listener */ { int ok; @@ -131,17 +78,8 @@ int SMTP_quit(int socket) return ok; } -/********************************************************************* - function: SMTP_eom - description: Send a message data termination to the SMTP server. - - arguments: - socket TCP/IP socket for connection to SMTP - return value: Result of SMTP_OK: based on codes in fetchmail.h. - - *********************************************************************/ - int SMTP_eom(int socket) +/* send a message data terminator to the SMTP listener */ { int ok; @@ -152,30 +90,16 @@ int SMTP_eom(int socket) return ok; } -/********************************************************************* - function: SMTP_rset - description: Send a "RSET" message to the SMTP server. - - arguments: - socket TCP/IP socket for connection to SMTP - - *********************************************************************/ void SMTP_rset(int socket) +/* send a "RSET" message to the SMTP listener */ { SockPrintf(socket,"RSET\r\n"); if (outlevel == O_VERBOSE) fprintf(stderr, "SMTP> RSET\n"); } -/********************************************************************* - function: SMTP_check - description: Returns the status of the smtp connection - arguments: - socket TCP/IP socket for connection to SMTP - return value: based on codes in fetchmail.h. - Do the dirty work of seeing what the status is.. - *********************************************************************/ static int SMTP_check(int socket,char *argbuf) +/* returns status of SMTP connection */ { int ok; char buf[SMTPBUFSIZE]; @@ -196,14 +120,8 @@ static int SMTP_check(int socket,char *argbuf) return (ok); } -/********************************************************************* - function: SMTP_ok - description: Returns the statsus of the smtp connection - arguments: - socket TCP/IP socket for connection to SMTP - return value: based on codes in fetchmail.h. - *********************************************************************/ int SMTP_ok(int socket,char *argbuf) +/* accepts SMTP response, returns status of SMTP connection */ { int ok; @@ -231,14 +149,10 @@ int SMTP_ok(int socket,char *argbuf) return ok; } -/********************************************************************* - function: SMTP_Gets - description: Gets a line from the SMTP connection - arguments: - socket TCP/IP socket for connection to SMTP - return value: number of bytes read. - *********************************************************************/ int SMTP_Gets(int socket,char *buf,int sz) +/* gets a line from the SMTP connection, returns bytes read */ { return read(socket,buf,sz); } + +/* smtp.c ends here */ @@ -1,15 +1,12 @@ /* + * socket.c -- socket library functions + * + * These were designed and coded by Carl Harris <ceharris@mal.com> + * and are essentially unchanged from the ancestral popclient. + * * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: socket.c - project: fetchmail - programmer: Carl Harris, ceharris@mal.com - description: socket library functions - - ***********************************************************************/ - #include <config.h> #include <fcntl.h> @@ -271,3 +268,5 @@ va_dcl { return SockWrite(socket, buf, strlen(buf)); } + +/* socket.c ends here */ @@ -1,15 +1,9 @@ /* + * uid.c -- UIDL handling for POP3 servers without LAST + * * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: uid.c - project: fetchmail - programmer: Eric S. Raymond - description: UID list handling - - ***********************************************************************/ - #include <config.h> #include <stdio.h> @@ -222,3 +216,5 @@ char *idfile; fclose(tmpfp); } } + +/* uid.c ends here */ @@ -1,16 +1,9 @@ /* + * xmalloc.c -- allocate space or die + * * For license terms, see the file COPYING in this directory. */ -/*********************************************************************** - module: xmalloc.c - project: fetchmail - programmer: Carl Harris, ceharris@mal.com - description: malloc wrapper. - - ***********************************************************************/ - - #include <config.h> #include <stdio.h> #include <string.h> @@ -45,3 +38,5 @@ char *s; strcpy(p,s); return p; } + +/* xmalloc.c ends here */ |