aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2002-08-26 17:54:55 +0000
committerEric S. Raymond <esr@thyrsus.com>2002-08-26 17:54:55 +0000
commit58d0bc3adbb7a9612d5b60c3652ebe29c0203f99 (patch)
tree394f4208406e9fa5b494ff6b31501777ede54773
parentb45d8a60dbcee6aa03a3177718cc0246a5222cf5 (diff)
downloadfetchmail-58d0bc3adbb7a9612d5b60c3652ebe29c0203f99.tar.gz
fetchmail-58d0bc3adbb7a9612d5b60c3652ebe29c0203f99.tar.bz2
fetchmail-58d0bc3adbb7a9612d5b60c3652ebe29c0203f99.zip
Edited RFC822 for cookbook.
svn path=/trunk/; revision=3686
-rw-r--r--Makefile.in2
-rw-r--r--rfc822.c40
2 files changed, 28 insertions, 14 deletions
diff --git a/Makefile.in b/Makefile.in
index 3331125d..6bee9ee4 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -133,7 +133,7 @@ dummy:
# Tester for address parsing
rfc822: rfc822.c
- gcc -DTESTMAIN -g rfc822.c -o rfc822
+ gcc -DMAIN -g rfc822.c -o rfc822
# Stand-alone MIME decoder
unmime: unmime.c base64.c rfc822.c xmalloc.c report.c
diff --git a/rfc822.c b/rfc822.c
index 53249c68..1957c037 100644
--- a/rfc822.c
+++ b/rfc822.c
@@ -1,17 +1,36 @@
-/*
- * rfc822.c -- code for slicing and dicing RFC822 mail headers
- *
- * Copyright 1997 by Eric S. Raymond
- * For license terms, see the file COPYING in this directory.
- */
+/*****************************************************************************
+NAME:
+ rfc822.c -- code for slicing and dicing RFC822 mail headers
+
+ENTRY POINTS:
+ nextaddr() -- parse the next address out of an RFC822 header
+ reply_hack() -- append hostname to local header addresses
+
+THEORY:
+ How to parse RFC822 headers in C. This is not a fully conformant
+implementation of RFC822 or RFC2822, but it has been in production use
+in a widely-deployed MTA (fetcmail) since 1996 without complaints.
+Really perverse combinations of quoting and commenting could break it.
+
+AUTHOR:
+ Eric S. Raymond <esr@thyrsus.com>, 1997. This source code example
+is part of fetchmail and the Unix Cookbook, and are released under the
+MIT license. Compile with -DMAIN to build the demonstrator.
+
+******************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
+#ifndef MAIN
#include "fetchmail.h"
#include "i18n.h"
+#else
+static int verbose;
+char *program_name = "rfc822";
+#endif /* MAIN */
#ifndef TRUE
#define TRUE 1
@@ -20,11 +39,6 @@
#define HEADER_END(p) ((p)[0] == '\n' && ((p)[1] != ' ' && (p)[1] != '\t'))
-#ifdef MAIN
-static int verbose;
-char *program_name = "rfc822";
-#endif /* MAIN */
-
unsigned char *reply_hack(buf, host)
/* hack message headers so replies will work properly */
unsigned char *buf; /* header to be hacked */
@@ -201,7 +215,7 @@ unsigned char *nxtaddr(hdr)
/* parse addresses in succession out of a specified RFC822 header */
const unsigned char *hdr; /* header to be parsed, NUL to continue previous hdr */
{
- static unsigned char address[POPBUFSIZE+1];
+ static unsigned char address[BUFSIZ];
static int tp;
static const unsigned char *hp;
static int state, oldstate;
@@ -394,7 +408,7 @@ static void parsebuf(unsigned char *longbuf, int reply)
main(int argc, char *argv[])
{
- unsigned char buf[MSGBUFSIZE], longbuf[BUFSIZ];
+ unsigned char buf[BUFSIZ], longbuf[BUFSIZ];
int ch, reply;
verbose = reply = FALSE;