X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/19e4b527a4256490d4d143465e86dd205d618b2e..ec173fd2c:/sbr/addrsbr.c diff --git a/sbr/addrsbr.c b/sbr/addrsbr.c index c3f01b61..43352bde 100644 --- a/sbr/addrsbr.c +++ b/sbr/addrsbr.c @@ -1,17 +1,21 @@ - -/* - * addrsbr.c -- parse addresses 822-style +/* addrsbr.c -- parse addresses 822-style * * 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 -#include -#include -#include -#include +#include "h/mh.h" +#include "snprintb.h" +#include "strindex.h" +#include "uprf.h" +#include "getcpy.h" +#include "context_find.h" +#include "error.h" +#include "h/addrsbr.h" +#include "h/mf.h" +#include "h/mts.h" +#include "h/utils.h" /* High level parsing of addresses: @@ -23,10 +27,10 @@ REALLYDUMB are now the default in the code. If #ifdef DUMB is in effect, a full 822-style parser is called - for syntax recongition. This breaks each address into its components. + for syntax recognition. This breaks each address into its components. Note however that no semantics are assumed about the parts or their totality. This means that implicit hostnames aren't made explicit, - and explicit hostnames aren't expanded to their "official" represenations. + and explicit hostnames aren't expanded to their "official" representations. If DUMB is not in effect, then this module does some high-level thinking about what the addresses are. @@ -79,7 +83,8 @@ static char adr[BUFSIZ]; static int eai = 0; void -enable_eai() { +enable_eai(void) +{ eai = 1; } @@ -91,7 +96,7 @@ getname (const char *addrs) pers = mbox = host = route = grp = note = NULL; err[0] = '\0'; - if ((ap = getadrx (addrs ? addrs : "", eai)) == NULL) { + if ((ap = getadrx (FENDNULL(addrs), eai)) == NULL) { return NULL; } @@ -206,36 +211,32 @@ mnfree (struct mailname *mp) if (!mp) return; - mh_xfree(mp->m_text); - mh_xfree(mp->m_pers); - mh_xfree(mp->m_mbox); - mh_xfree(mp->m_host); - mh_xfree(mp->m_path); - mh_xfree(mp->m_gname); - mh_xfree(mp->m_note); + free(mp->m_text); + free(mp->m_pers); + free(mp->m_mbox); + free(mp->m_host); + free(mp->m_path); + free(mp->m_gname); + free(mp->m_note); - free ((char *) mp); + free(mp); } -#define empty(s) ((s) ? (s) : "") - char * auxformat (struct mailname *mp, int extras) { - static char addr[BUFSIZ]; + static char addr[BUFSIZ-4]; static char buffer[BUFSIZ]; if (mp->m_nohost) - strncpy (addr, mp->m_mbox ? mp->m_mbox : "", sizeof(addr)); - else - - if (mp->m_type != UUCPHOST) { + strncpy (addr, FENDNULL(mp->m_mbox), sizeof(addr)); + else if (mp->m_type != UUCPHOST) { if (mp->m_host) - snprintf (addr, sizeof(addr), "%s%s@%s", empty(mp->m_path), - empty(mp->m_mbox), mp->m_host); - else snprintf (addr, sizeof(addr), "%s%s", empty(mp->m_path), - empty(mp->m_mbox)); + snprintf (addr, sizeof(addr), "%s%s@%s", FENDNULL(mp->m_path), + FENDNULL(mp->m_mbox), mp->m_host); + else snprintf (addr, sizeof(addr), "%s%s", FENDNULL(mp->m_path), + FENDNULL(mp->m_mbox)); } else snprintf (addr, sizeof(addr), "%s!%s", mp->m_host, mp->m_mbox); @@ -251,12 +252,10 @@ auxformat (struct mailname *mp, int extras) snprintf (buffer, sizeof(buffer), "%s <%s>", legal_person (mp->m_pers ? mp->m_pers : mp->m_mbox), addr); - } + } else if (mp->m_note) + snprintf (buffer, sizeof(buffer), "%s %s", addr, mp->m_note); else - if (mp->m_note) - snprintf (buffer, sizeof(buffer), "%s %s", addr, mp->m_note); - else - strncpy (buffer, addr, sizeof(buffer)); + strncpy (buffer, addr, sizeof(buffer)); return buffer; } @@ -275,10 +274,10 @@ auxformat (struct mailname *mp, int extras) * Check if this is my address */ -int +bool ismymbox (struct mailname *np) { - int oops; + bool oops; int len, i; char *cp; char *pp; @@ -286,7 +285,7 @@ ismymbox (struct mailname *np) struct mailname *mp; static char *am = NULL; static struct mailname mq; - static int localmailbox = 0; + static bool localmailbox; /* * If this is the first call, initialize @@ -298,24 +297,21 @@ ismymbox (struct mailname *np) if ((am = context_find ("local-mailbox"))) { - localmailbox++; + localmailbox = true; if ((cp = getname(am)) == NULL) { - admonish (NULL, "Unable to find address in local-mailbox"); - return 0; + inform("Unable to find address in local-mailbox, continuing..."); + return false; } if ((mq.m_next = getm (cp, NULL, 0, NULL, 0)) == NULL) { - admonish (NULL, "invalid entry in local-mailbox: %s", cp); - return 0; + inform("invalid entry in local-mailbox: %s, continuing...", cp); + return false; } - /* - * Sigh, it turns out that the address parser gets messed up - * if you don't call getname() until it returns NULL. - */ - - while ((cp = getname(am)) != NULL) + /* Sigh, it turns out that the address parser gets messed up + * if you don't call getname() until it returns NULL. */ + while (getname(am) != NULL) ; } @@ -323,11 +319,11 @@ ismymbox (struct mailname *np) am = getusername(); else { mp = mq.m_next ? mq.m_next : &mq; - oops = 0; + oops = false; while ((cp = getname (am))) { if ((mp->m_next = getm (cp, NULL, 0, NULL, 0)) == NULL) { - admonish (NULL, "illegal address: %s", cp); - oops++; + inform("illegal address: %s, continuing...", cp); + oops = true; } else { mp = mp->m_next; mp->m_type = W_NIL; @@ -352,7 +348,7 @@ ismymbox (struct mailname *np) } } if (oops) - advise (NULL, "please fix the %s: entry in your %s file", + inform("please fix the %s: entry in your %s file", "alternate-mailboxes", mh_profile); } @@ -360,8 +356,8 @@ ismymbox (struct mailname *np) for (mp = &mq; mp; mp = mp->m_next) { fprintf (stderr, "Local- or Alternate-Mailbox: text=\"%s\" " "mbox=\"%s\" host=\"%s\" %s\n", - mp->m_text ? mp->m_text : "", mp->m_mbox, - mp->m_host ? mp->m_host : "", + FENDNULL(mp->m_text), mp->m_mbox, + FENDNULL(mp->m_host), snprintb (buffer, sizeof(buffer), (unsigned) mp->m_type, WBITS)); } @@ -369,7 +365,7 @@ ismymbox (struct mailname *np) } if (np == NULL) /* XXX */ - return 0; + return false; /* * Don't perform this "local" test if we have a Local-Mailbox set @@ -385,11 +381,12 @@ ismymbox (struct mailname *np) case UUCPHOST: if (strcasecmp (np->m_host, SystemName())) - break; /* fall */ + break; + /* FALLTHRU */ case LOCALHOST: local_test: ; if (!strcasecmp (np->m_mbox, mq.m_mbox)) - return 1; + return true; break; default: @@ -427,7 +424,7 @@ local_test: ; } if (mp->m_nohost) - return 1; + return true; if (np->m_host == NULL || mp->m_host == NULL) continue; if ((len = strlen (cp = np->m_host)) @@ -451,8 +448,8 @@ local_test: ; continue; break; } - return 1; + return true; } - return 0; + return false; }