/*
- * mf.c -- mail filter subroutines
- *
- * This code is Copyright (c) 2002, by the authors of nmh. See the
- * COPYRIGHT file in the root directory of the nmh distribution for
- * complete copyright information.
- */
+** mf.c -- mail filter subroutines
+**
+** This code is Copyright (c) 2002, by the authors of nmh. See the
+** COPYRIGHT file in the root directory of the nmh distribution for
+** complete copyright information.
+*/
#include <h/mf.h>
#include <ctype.h>
#include <h/utils.h>
/*
- * static prototypes
- */
+** static prototypes
+*/
static char *getcpy (char *);
-static void compress (char *, unsigned char *);
static int isat (char *);
static int parse_address (void);
static int phrase (char *);
register char *p;
if (!s) {
-/* causes compiles to blow up because the symbol _cleanup is undefined
- * where did this ever come from? */
+ /*
+ ** causes compiles to blow up because the symbol _cleanup
+ ** is undefined where did this ever come from?
+ */
/* _cleanup(); */
abort();
for(;;)
}
-int
-isfrom(char *string)
-{
- return (strncmp (string, "From ", 5) == 0
- || strncmp (string, ">From ", 6) == 0);
-}
-
-
-int
-lequal (unsigned char *a, unsigned char *b)
-{
- for (; *a; a++, b++)
- if (*b == 0)
- return FALSE;
- else {
- char c1 = islower (*a) ? toupper (*a) : *a;
- char c2 = islower (*b) ? toupper (*b) : *b;
- if (c1 != c2)
- return FALSE;
- }
-
- return (*b == 0);
-}
-
-
-/*
- * seekadrx() is tricky. We want to cover both UUCP-style and ARPA-style
- * addresses, so for each list of addresses we see if we can find some
- * character to give us a hint.
- */
-
-
#define CHKADR 0 /* undertermined address style */
#define UNIXDR 1 /* UNIX-style address */
#define ARPADR 2 /* ARPAnet-style address */
-static char *punctuators = ";<>.()[]";
-static char *vp = NULL;
-static char *tp = NULL;
-
-static struct adrx adrxs1;
-
-
-struct adrx *
-seekadrx (char *addrs)
-{
- static int state = CHKADR;
- register char *cp;
- register struct adrx *adrxp;
-
- if (state == CHKADR)
- for (state = UNIXDR, cp = addrs; *cp; cp++)
- if (strchr(punctuators, *cp)) {
- state = ARPADR;
- break;
- }
-
- switch (state) {
- case UNIXDR:
- adrxp = uucpadrx (addrs);
- break;
-
- case ARPADR:
- default:
- adrxp = getadrx (addrs);
- break;
- }
-
- if (adrxp == NULL)
- state = CHKADR;
-
- return adrxp;
-}
-
-
-/*
- * uucpadrx() implements a partial UUCP-style address parser. It's based
- * on the UUCP notion that addresses are separated by spaces or commas.
- */
-
-
-struct adrx *
-uucpadrx (char *addrs)
-{
- register unsigned char *cp, *wp, *xp, *yp;
- register char *zp;
- register struct adrx *adrxp = &adrxs1;
-
- if (vp == NULL) {
- vp = tp = getcpy (addrs);
- compress (addrs, vp);
- } else if (tp == NULL) {
- free (vp);
- vp = NULL;
- return NULL;
- }
-
- for (cp = tp; isspace (*cp); cp++)
- continue;
- if (*cp == 0) {
- free (vp);
- vp = tp = NULL;
- return NULL;
- }
-
- if ((wp = strchr(cp, ',')) == NULL) {
- if ((wp = strchr(cp, ' ')) != NULL) {
- xp = wp;
- while (isspace (*xp))
- xp++;
- if (*xp != 0 && isat (--xp)) {
- yp = xp + 4;
- while (isspace (*yp))
- yp++;
- if (*yp != 0) {
- if ((zp = strchr(yp, ' ')) != NULL)
- *zp = 0, tp = ++zp;
- else
- tp = NULL;
- } else
- *wp = 0, tp = ++wp;
- } else
- *wp = 0, tp = ++wp;
- } else
- tp = NULL;
- } else
- *wp = 0, tp = ++wp;
-
- if (adrxp->text)
- free (adrxp->text);
- adrxp->text = getcpy (cp);
- adrxp->mbox = cp;
- adrxp->host = adrxp->path = NULL;
- if ((wp = strrchr(cp, '@')) != NULL) {
- *wp++ = 0;
- adrxp->host = *wp ? wp : NULL;
- } else
- for (wp = cp + strlen (cp) - 4; wp >= cp; wp--)
- if (isat (wp)) {
- *wp++ = 0;
- adrxp->host = wp + 3;
- }
-
- adrxp->pers = adrxp->grp = adrxp->note = adrxp->err = NULL;
- adrxp->ingrp = 0;
-
- return adrxp;
-}
-
-
-static void
-compress (char *fp, unsigned char *tp)
-{
- register char c;
- register unsigned char *cp;
-
- for (c = ' ', cp = tp; (*tp = *fp++) != 0;)
- if (isspace (*tp)) {
- if (c != ' ')
- *tp++ = c = ' ';
- } else
- c = *tp++;
-
- if (c == ' ' && cp < tp)
- *--tp = 0;
-}
-
-
static int
isat (char *p)
{
/*
- *
- * getadrx() implements a partial 822-style address parser. The parser
- * is neither complete nor correct. It does however recognize nearly all
- * of the 822 address syntax. In addition it handles the majority of the
- * 733 syntax as well. Most problems arise from trying to accomodate both.
- *
- * In terms of 822, the route-specification in
- *
- * "<" [route] local-part "@" domain ">"
- *
- * is parsed and returned unchanged. Multiple at-signs are compressed
- * via source-routing. Recursive groups are not allowed as per the
- * standard.
- *
- * In terms of 733, " at " is recognized as equivalent to "@".
- *
- * In terms of both the parser will not complain about missing hosts.
- *
- * -----
- *
- * We should not allow addresses like
- *
- * Marshall T. Rose <MRose@UCI>
- *
- * but should insist on
- *
- * "Marshall T. Rose" <MRose@UCI>
- *
- * Unfortunately, a lot of mailers stupidly let people get away with this.
- *
- * -----
- *
- * We should not allow addresses like
- *
- * <MRose@UCI>
- *
- * but should insist on
- *
- * MRose@UCI
- *
- * Unfortunately, a lot of mailers stupidly let people's UAs get away with
- * this.
- *
- * -----
- *
- * We should not allow addresses like
- *
- * @UCI:MRose@UCI-750a
- *
- * but should insist on
- *
- * Marshall Rose <@UCI:MRose@UCI-750a>
- *
- * Unfortunately, a lot of mailers stupidly do this.
- *
- */
+**
+** getadrx() implements a partial 822-style address parser. The parser
+** is neither complete nor correct. It does however recognize nearly all
+** of the 822 address syntax. In addition it handles the majority of the
+** 733 syntax as well. Most problems arise from trying to accomodate both.
+**
+** In terms of 822, the route-specification in
+**
+** "<" [route] local-part "@" domain ">"
+**
+** is parsed and returned unchanged. Multiple at-signs are compressed
+** via source-routing. Recursive groups are not allowed as per the
+** standard.
+**
+** In terms of 733, " at " is recognized as equivalent to "@".
+**
+** In terms of both the parser will not complain about missing hosts.
+**
+** -----
+**
+** We should not allow addresses like
+**
+** Marshall T. Rose <MRose@UCI>
+**
+** but should insist on
+**
+** "Marshall T. Rose" <MRose@UCI>
+**
+** Unfortunately, a lot of mailers stupidly let people get away with this.
+**
+** -----
+**
+** We should not allow addresses like
+**
+** <MRose@UCI>
+**
+** but should insist on
+**
+** MRose@UCI
+**
+** Unfortunately, a lot of mailers stupidly let people's UAs get away with
+** this.
+**
+** -----
+**
+** We should not allow addresses like
+**
+** @UCI:MRose@UCI-750a
+**
+** but should insist on
+**
+** Marshall Rose <@UCI:MRose@UCI-750a>
+**
+** Unfortunately, a lot of mailers stupidly do this.
+**
+*/
#define QUOTE '\\'
break;
default:
- sprintf (err, "no mailbox in local-part (%s)", buffer);
+ sprintf (err, "no mailbox in local-part (%s)",
+ buffer);
return NOTOK;
}
register unsigned char c;
register char *bp;
-/* Add C to the buffer bp. After use of this macro *bp is guaranteed to be within the buffer. */
-#define ADDCHR(C) do { *bp++ = (C); if ((bp - buffer) == (BUFSIZ-1)) goto my_lex_buffull; } while (0)
+ /*
+ ** Add C to the buffer bp. After use of this macro *bp is guaranteed
+ ** to be within the buffer.
+ */
+#define ADDCHR(C) \
+ do { \
+ *bp++ = (C); \
+ if ((bp - buffer) == (BUFSIZ-1)) \
+ goto my_lex_buffull; \
+ } while (0)
bp = buffer;
*bp = 0;
return p;
}
-
-
-int
-mfgets (FILE *in, char **bp)
-{
- int i;
- register char *cp, *dp, *ep;
- static int len = 0;
- static char *pp = NULL;
-
- if (pp == NULL)
- pp = mh_xmalloc ((size_t) (len = BUFSIZ));
-
- for (ep = (cp = pp) + len - 2;;) {
- switch (i = getc (in)) {
- case EOF:
- eol: ;
- if (cp != pp) {
- *cp = 0;
- *bp = pp;
- return OK;
- }
- eoh: ;
- *bp = NULL;
- free (pp);
- pp = NULL;
- return DONE;
-
- case 0:
- continue;
-
- case '\n':
- if (cp == pp) /* end of headers, gobble it */
- goto eoh;
- switch (i = getc (in)) {
- default: /* end of line */
- case '\n': /* end of headers, save for next call */
- ungetc (i, in);
- goto eol;
-
- case ' ': /* continue headers */
- case '\t':
- *cp++ = '\n';
- break;
- } /* fall into default case */
-
- default:
- *cp++ = i;
- break;
- }
- if (cp >= ep) {
- dp = mh_xrealloc (pp, (size_t) (len += BUFSIZ));
- cp += dp - pp, ep = (pp = cp) + len - 2;
- }
- }
-}