]> diplodocus.org Git - nmh/blobdiff - sbr/mf.c
mhstore(1) now obeys its -noverbose switch.
[nmh] / sbr / mf.c
index 9a2c647012e48f1f9168fa4e6441cad57d4bc635..c88681787e5a72297eeb3880123b5e3eded978b4 100644 (file)
--- a/sbr/mf.c
+++ b/sbr/mf.c
@@ -2,25 +2,18 @@
 /*
  * mf.c -- mail filter subroutines
  *
 /*
  * mf.c -- mail filter subroutines
  *
- * $Id$
- *
  * 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>
  * 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 <stdio.h>
 #include <h/utils.h>
 
 /*
  * static prototypes
  */
 #include <h/utils.h>
 
 /*
  * static prototypes
  */
-static char *getcpy (char *);
-static char *add (char *, char *);
-static void compress (char *, char *);
-static int isat (char *);
+static int isat (const char *);
 static int parse_address (void);
 static int phrase (char *);
 static int route_addr (char *);
 static int parse_address (void);
 static int phrase (char *);
 static int route_addr (char *);
@@ -28,43 +21,11 @@ static int local_part (char *);
 static int domain (char *);
 static int route (char *);
 static int my_lex (char *);
 static int domain (char *);
 static int route (char *);
 static int my_lex (char *);
+static int contains8bit (const char *);
 
 
 
 
-static char *
-getcpy (char *s)
-{
-    register char *p;
-
-    if (!s) {
-/* causes compiles to blow up because the symbol _cleanup is undefined 
-   where did this ever come from? */
-       /* _cleanup(); */
-       abort();
-       for(;;)
-           pause();
-    }
-    p = mh_xmalloc ((size_t) (strlen (s) + 2));
-    strcpy (p, s);
-    return p;
-}
-
-
-static char *
-add (char *s1, char *s2)
-{
-    register char *p;
-
-    if (!s2)
-       return getcpy (s1);
-
-    p = mh_xmalloc ((size_t) (strlen (s1) + strlen (s2) + 2));
-    sprintf (p, "%s%s", s2, s1);
-    free (s2);
-    return p;
-}
-
 int
 int
-isfrom(char *string)
+isfrom(const char *string)
 {
     return (strncmp (string, "From ", 5) == 0
            || strncmp (string, ">From ", 6) == 0);
 {
     return (strncmp (string, "From ", 5) == 0
            || strncmp (string, ">From ", 6) == 0);
@@ -72,14 +33,16 @@ isfrom(char *string)
 
 
 int
 
 
 int
-lequal (char *a, char *b)
+lequal (const char *a, const char *b)
 {
     for (; *a; a++, b++)
        if (*b == 0)
            return FALSE;
        else {
 {
     for (; *a; a++, b++)
        if (*b == 0)
            return FALSE;
        else {
-           char c1 = islower (*a) ? toupper (*a) : *a;
-           char c2 = islower (*b) ? toupper (*b) : *b;
+           char c1 = islower ((unsigned char) *a) ?
+                                       toupper ((unsigned char) *a) : *a;
+           char c2 = islower ((unsigned char) *b) ?
+                                       toupper ((unsigned char) *b) : *b;
            if (c1 != c2)
                return FALSE;
        }
            if (c1 != c2)
                return FALSE;
        }
@@ -88,158 +51,8 @@ lequal (char *a, char *b)
 }
 
 
 }
 
 
-/* 
- * 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 char *cp, *wp, *xp, *yp, *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, char *tp)
-{
-    register char c, *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
 static int
-isat (char *p)
+isat (const char *p)
 {
     return (strncmp (p, " AT ", 4)
            && strncmp (p, " At ", 4)
 {
     return (strncmp (p, " AT ", 4)
            && strncmp (p, " At ", 4)
@@ -363,7 +176,7 @@ static struct adrx  adrxs2;
 
 
 struct adrx *
 
 
 struct adrx *
-getadrx (char *addrs)
+getadrx (const char *addrs)
 {
     register char *bp;
     register struct adrx *adrxp = &adrxs2;
 {
     register char *bp;
     register struct adrx *adrxp = &adrxs2;
@@ -384,7 +197,7 @@ getadrx (char *addrs)
     err[0] = 0;
 
     if (dp == NULL) {
     err[0] = 0;
 
     if (dp == NULL) {
-       dp = cp = getcpy (addrs ? addrs : "");
+       dp = cp = strdup (addrs ? addrs : "");
        glevel = 0;
     }
     else
        glevel = 0;
     }
     else
@@ -418,6 +231,15 @@ getadrx (char *addrs)
            break;
        }
 
            break;
        }
 
+    /*
+     * Reject the address if key fields contain 8bit characters
+     */
+
+    if (contains8bit(mbox) || contains8bit(host) || contains8bit(path) ||
+       contains8bit(grp)) {
+       strcpy(err, "Address contains 8-bit characters");
+    }
+
     if (err[0])
        for (;;) {
            switch (last_lex) {
     if (err[0])
        for (;;) {
            switch (last_lex) {
@@ -431,10 +253,10 @@ getadrx (char *addrs)
            }
            break;
        }
            }
            break;
        }
-    while (isspace (*ap))
+    while (isspace ((unsigned char) *ap))
        ap++;
     if (cp)
        ap++;
     if (cp)
-       sprintf (adr, "%.*s", cp - ap, ap);
+       sprintf (adr, "%.*s", (int)(cp - ap), ap);
     else
        strcpy (adr, ap);
     bp = adr + strlen (adr) - 1;
     else
        strcpy (adr, ap);
     bp = adr + strlen (adr) - 1;
@@ -465,7 +287,7 @@ again: ;
     switch (my_lex (buffer)) {
        case LX_ATOM: 
        case LX_QSTR: 
     switch (my_lex (buffer)) {
        case LX_ATOM: 
        case LX_QSTR: 
-           pers = getcpy (buffer);
+           pers = strdup (buffer);
            break;
 
        case LX_SEMI: 
            break;
 
        case LX_SEMI: 
@@ -719,7 +541,7 @@ domain (char *buffer)
 static int
 route (char *buffer)
 {
 static int
 route (char *buffer)
 {
-    path = getcpy ("@");
+    path = strdup ("@");
 
     for (;;) {
        switch (my_lex (buffer)) {
 
     for (;;) {
        switch (my_lex (buffer)) {
@@ -774,7 +596,7 @@ my_lex (char *buffer)
 {
     /* buffer should be at least BUFSIZ bytes long */
     int i, gotat = 0;
 {
     /* buffer should be at least BUFSIZ bytes long */
     int i, gotat = 0;
-    register char c, *bp;
+    char c, *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)
@@ -786,7 +608,7 @@ my_lex (char *buffer)
 
     gotat = isat (cp);
     c = *cp++;
 
     gotat = isat (cp);
     c = *cp++;
-    while (isspace (c))
+    while (isspace ((unsigned char) c))
        c = *cp++;
     if (c == 0) {
        cp = NULL;
        c = *cp++;
     if (c == 0) {
        cp = NULL;
@@ -818,7 +640,7 @@ my_lex (char *buffer)
                    if (--i < 0) {
                        *bp = 0;
                        note = note ? add (buffer, add (" ", note))
                    if (--i < 0) {
                        *bp = 0;
                        note = note ? add (buffer, add (" ", note))
-                           : getcpy (buffer);
+                           : strdup (buffer);
                        return my_lex (buffer);
                    }
            }
                        return my_lex (buffer);
                    }
            }
@@ -876,7 +698,7 @@ my_lex (char *buffer)
        if (c == special[i].lx_chr)
            return (last_lex = special[i].lx_val);
 
        if (c == special[i].lx_chr)
            return (last_lex = special[i].lx_val);
 
-    if (iscntrl (c))
+    if (iscntrl ((unsigned char) c))
        return (last_lex = LX_ERR);
 
     for (;;) {
        return (last_lex = LX_ERR);
 
     for (;;) {
@@ -885,7 +707,7 @@ my_lex (char *buffer)
        for (i = 0; special[i].lx_chr != 0; i++)
            if (c == special[i].lx_chr)
                goto got_atom;
        for (i = 0; special[i].lx_chr != 0; i++)
            if (c == special[i].lx_chr)
                goto got_atom;
-       if (iscntrl (c) || isspace (c))
+       if (iscntrl ((unsigned char) c) || isspace ((unsigned char) c))
            break;
        ADDCHR(c);
     }
            break;
        ADDCHR(c);
     }
@@ -906,15 +728,34 @@ got_atom: ;
 }
 
 
 }
 
 
+/*
+ * Return true if the string contains an 8-bit character
+ */
+
+static int
+contains8bit(const char *p)
+{
+    if (! p)
+       return 0;
+
+    for (; *p; p++) {
+       if (! isascii((unsigned char) *p))
+           return 1;
+    }
+
+    return 0;
+}
+
+
 char *
 char *
-legal_person (char *p)
+legal_person (const char *p)
 {
     int i;
 {
     int i;
-    register char *cp;
+    register const char *cp;
     static char buffer[BUFSIZ];
 
     if (*p == '"')
     static char buffer[BUFSIZ];
 
     if (*p == '"')
-       return p;
+       return (char *) p;
     for (cp = p; *cp; cp++)
        for (i = 0; special[i].lx_chr; i++)
            if (*cp == special[i].lx_chr) {
     for (cp = p; *cp; cp++)
        for (i = 0; special[i].lx_chr; i++)
            if (*cp == special[i].lx_chr) {
@@ -922,7 +763,7 @@ legal_person (char *p)
                return buffer;
            }
 
                return buffer;
            }
 
-    return p;
+    return (char *) p;
 }
 
 
 }
 
 
@@ -975,13 +816,8 @@ mfgets (FILE *in, char **bp)
                break;
        }
        if (cp >= ep) {
                break;
        }
        if (cp >= ep) {
-           if (!(dp = realloc (pp, (size_t) (len += BUFSIZ)))) {
-               free (pp);
-               pp = NULL;
-               return NOTOK;
-           }
-           else
-               cp += dp - pp, ep = (pp = cp) + len - 2;
+           dp = mh_xrealloc (pp, (size_t) (len += BUFSIZ));
+           cp += dp - pp, ep = (pp = cp) + len - 2;
        }
     }
 }
        }
     }
 }