X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/9514ca81bd12a47df977822efc14ff285bd5bc10..3c54bbb247ffc8fa094d754099c0b009e79d484d:/sbr/addrsbr.c?ds=inline diff --git a/sbr/addrsbr.c b/sbr/addrsbr.c index 68bb6dec..9b2973a3 100644 --- a/sbr/addrsbr.c +++ b/sbr/addrsbr.c @@ -5,11 +5,17 @@ * 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: @@ -77,7 +83,8 @@ static char adr[BUFSIZ]; static int eai = 0; void -enable_eai() { +enable_eai(void) +{ eai = 1; } @@ -89,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; } @@ -204,20 +211,18 @@ 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(mp); } -#define empty(s) ((s) ? (s) : "") - char * auxformat (struct mailname *mp, int extras) { @@ -225,15 +230,13 @@ auxformat (struct mailname *mp, int extras) 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); @@ -249,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; } @@ -273,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; @@ -284,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 @@ -296,16 +297,16 @@ ismymbox (struct mailname *np) if ((am = context_find ("local-mailbox"))) { - localmailbox++; + localmailbox = true; if ((cp = getname(am)) == NULL) { inform("Unable to find address in local-mailbox, continuing..."); - return 0; + return false; } if ((mq.m_next = getm (cp, NULL, 0, NULL, 0)) == NULL) { inform("invalid entry in local-mailbox: %s, continuing...", cp); - return 0; + return false; } /* Sigh, it turns out that the address parser gets messed up @@ -318,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) { inform("illegal address: %s, continuing...", cp); - oops++; + oops = true; } else { mp = mp->m_next; mp->m_type = W_NIL; @@ -355,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)); } @@ -364,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,7 +386,7 @@ ismymbox (struct mailname *np) case LOCALHOST: local_test: ; if (!strcasecmp (np->m_mbox, mq.m_mbox)) - return 1; + return true; break; default: @@ -423,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)) @@ -447,8 +448,8 @@ local_test: ; continue; break; } - return 1; + return true; } - return 0; + return false; }