X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/a9dd3e44a1d78e038a97c54f27aa778f41371ae9..bfc6b93af:/sbr/mf.c?ds=sidebyside diff --git a/sbr/mf.c b/sbr/mf.c index c8868178..870a0a52 100644 --- a/sbr/mf.c +++ b/sbr/mf.c @@ -21,31 +21,29 @@ static int local_part (char *); static int domain (char *); static int route (char *); static int my_lex (char *); -static int contains8bit (const char *); int isfrom(const char *string) { - return (strncmp (string, "From ", 5) == 0 - || strncmp (string, ">From ", 6) == 0); + return (HasPrefix(string, "From ") + || HasPrefix(string, ">From ")); } int lequal (const char *a, const char *b) { - for (; *a; a++, b++) + char c1, c2; + + for (; *a; a++, b++) { if (*b == 0) return FALSE; - else { - 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; - } + c1 = toupper((unsigned char)*a); + c2 = toupper((unsigned char)*b); + if (c1 != c2) + return FALSE; + } return (*b == 0); } @@ -54,10 +52,8 @@ lequal (const char *a, const char *b) static int isat (const char *p) { - return (strncmp (p, " AT ", 4) - && strncmp (p, " At ", 4) - && strncmp (p, " aT ", 4) - && strncmp (p, " at ", 4) ? FALSE : TRUE); + return HasPrefix(p, " AT ") || HasPrefix(p, " At ") || + HasPrefix(p, " aT ") || HasPrefix(p, " at "); } @@ -66,7 +62,7 @@ isat (const 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. + * 733 syntax as well. Most problems arise from trying to accommodate both. * * In terms of 822, the route-specification in * @@ -175,24 +171,19 @@ static char adr[BUFSIZ]; static struct adrx adrxs2; +/* eai = Email Address Internationalization */ struct adrx * -getadrx (const char *addrs) +getadrx (const char *addrs, int eai) { - register char *bp; - register struct adrx *adrxp = &adrxs2; - - if (pers) - free (pers); - if (mbox) - free (mbox); - if (host) - free (host); - if (path) - free (path); - if (grp) - free (grp); - if (note) - free (note); + char *bp; + struct adrx *adrxp = &adrxs2; + + mh_xfree(pers); + mh_xfree(mbox); + mh_xfree(host); + mh_xfree(path); + mh_xfree(grp); + mh_xfree(note); pers = mbox = host = path = grp = note = NULL; err[0] = 0; @@ -231,13 +222,15 @@ getadrx (const char *addrs) break; } - /* - * Reject the address if key fields contain 8bit characters - */ + if (! eai) { + /* + * 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 (contains8bit(mbox, NULL) || contains8bit(host, NULL) || + contains8bit(path, NULL) || contains8bit(grp, NULL)) { + strcpy(err, "Address contains 8-bit characters"); + } } if (err[0]) @@ -256,7 +249,7 @@ getadrx (const char *addrs) while (isspace ((unsigned char) *ap)) ap++; if (cp) - sprintf (adr, "%.*s", (int)(cp - ap), ap); + snprintf(adr, sizeof adr, "%.*s", (int)(cp - ap), ap); else strcpy (adr, ap); bp = adr + strlen (adr) - 1; @@ -296,10 +289,8 @@ again: ; return NOTOK; } case LX_COMA: - if (note) { - free (note); - note = NULL; - } + mh_xfree(note); + note = NULL; goto again; case LX_END: @@ -315,7 +306,7 @@ again: ; return OK; /* why be choosy? */ default: - sprintf (err, "illegal address construct (%s)", buffer); + snprintf(err, sizeof err, "illegal address construct (%s)", buffer); return NOTOK; } @@ -334,13 +325,13 @@ again: ; return NOTOK; if (last_lex == LX_RBRK) return OK; - sprintf (err, "missing right-bracket (%s)", buffer); + snprintf(err, sizeof err, "missing right-bracket (%s)", buffer); return NOTOK; case LX_COLN: get_group: ; if (glevel++ > 0) { - sprintf (err, "nested groups not allowed (%s)", pers); + snprintf(err, sizeof err, "nested groups not allowed (%s)", pers); return NOTOK; } grp = add (": ", pers); @@ -369,7 +360,7 @@ again: ; goto more_phrase; default: - sprintf (err, "no mailbox in address, only a phrase (%s%s)", + snprintf(err, sizeof err, "no mailbox in address, only a phrase (%s%s)", pers, buffer); return NOTOK; } @@ -405,7 +396,7 @@ again: ; return OK; default: - sprintf (err, "junk after local@domain (%s)", buffer); + snprintf(err, sizeof err, "junk after local@domain (%s)", buffer); return NOTOK; } @@ -422,7 +413,7 @@ again: ; return OK; default: - sprintf (err, "missing mailbox (%s)", buffer); + snprintf(err, sizeof err, "missing mailbox (%s)", buffer); return NOTOK; } } @@ -447,7 +438,7 @@ phrase (char *buffer) static int route_addr (char *buffer) { - register char *pp = cp; + char *pp = cp; if (my_lex (buffer) == LX_AT) { if (route (buffer) == NOTOK) @@ -470,7 +461,7 @@ route_addr (char *buffer) return OK; default: - sprintf (err, "no at-sign after local-part (%s)", buffer); + snprintf(err, sizeof err, "no at-sign after local-part (%s)", buffer); return NOTOK; } } @@ -489,7 +480,7 @@ local_part (char *buffer) break; default: - sprintf (err, "no mailbox in local-part (%s)", buffer); + snprintf(err, sizeof err, "no mailbox in local-part (%s)", buffer); return NOTOK; } @@ -516,7 +507,7 @@ domain (char *buffer) break; default: - sprintf (err, "no sub-domain in domain-part of address (%s)", buffer); + snprintf(err, sizeof err, "no sub-domain in domain-part of address (%s)", buffer); return NOTOK; } @@ -551,7 +542,7 @@ route (char *buffer) break; default: - sprintf (err, "no sub-domain in domain-part of address (%s)", buffer); + snprintf(err, sizeof err, "no sub-domain in domain-part of address (%s)", buffer); return NOTOK; } switch (my_lex (buffer)) { @@ -567,7 +558,7 @@ route (char *buffer) break; default: - sprintf (err, "no at-sign found for next domain in route (%s)", + snprintf(err, sizeof err, "no at-sign found for next domain in route (%s)", buffer); } break; @@ -584,7 +575,7 @@ route (char *buffer) return OK; default: - sprintf (err, "no colon found to terminate route (%s)", buffer); + snprintf(err, sizeof err, "no colon found to terminate route (%s)", buffer); return NOTOK; } } @@ -728,30 +719,11 @@ 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 * legal_person (const char *p) { int i; - register const char *cp; + const char *cp; static char buffer[BUFSIZ]; if (*p == '"') @@ -759,7 +731,7 @@ legal_person (const char *p) for (cp = p; *cp; cp++) for (i = 0; special[i].lx_chr; i++) if (*cp == special[i].lx_chr) { - sprintf (buffer, "\"%s\"", p); + snprintf(buffer, sizeof buffer, "\"%s\"", p); return buffer; } @@ -771,7 +743,7 @@ int mfgets (FILE *in, char **bp) { int i; - register char *cp, *dp, *ep; + char *cp, *dp, *ep; static int len = 0; static char *pp = NULL;