The idea of your changes is good. On the first look, your code looks good as well. Just one thing: Please use shorter identifiers.
meillo [2016-09-08 13:03] kact...@gnu.org > > From: Dmitry Bogatov <kact...@gnu.org> > > Move initialization of alternate mailnames list into separate > function. > --- > sbr/addrsbr.c | 151 > +++++++++++++++++++++++++--------------------------------- > 1 file changed, 65 insertions(+), 86 deletions(-) > > diff --git a/sbr/addrsbr.c b/sbr/addrsbr.c > index db5b42e..d1c454b 100644 > --- a/sbr/addrsbr.c > +++ b/sbr/addrsbr.c > @@ -229,6 +229,68 @@ adrformat(struct mailname *mp) > #define W_HOST (W_HBEG | W_HEND) > #define WBITS "\020\01MBEG\02MEND\03HBEG\04HEND" > > +static void > +fill_mailname_type(struct mailname *mp) > +{ > + char *cp = mp->m_mbox + strlen(mp->m_mbox) - 1; /* last symbol */ > + > + if (*cp == '*') { > + mp->m_type |= W_MEND; > + *cp = '\0'; > + } > + if (*mp->m_mbox == '*') { > + mp->m_type |= W_MBEG; > + mp->m_mbox++; > + } > + if (mp->m_host) { > + char *cp2 = mp->m_host + strlen(mp->m_host) - 1; /* last symbol > */ > + if (*cp2 == '*') { > + mp->m_type |= W_HEND; > + *cp2 = '\0'; > + } > + if (*mp->m_host == '*') { > + mp->m_type |= W_HBEG; > + mp->m_host++; > + } > + } > +} > + > +static struct mailname** > +append_alternate_mailboxes(struct mailname **mp, char *data) > +{ > + char *cp; > + while ((cp = getname(data))) { > + struct mailname *next = getm(cp, NULL, 0, AD_NAME, NULL); > + if (!next) { > + advise(NULL, "invalid address in profile: %s", cp); > + } > + *mp = next; > + (*mp)->m_type = W_NIL; > + fill_mailname_type(*mp); > + > + mp = &(*mp)->m_next; > + } > + return mp; > +} > + > +static const struct mailname* > +get_alternate_mailboxes() > +{ > + static struct mailname *mq = NULL; > + > + if (!mq) { > + struct mailname **mp = &mq; > + char *alt; > + > + alt = context_find("alternate-mailboxes"); > + mp = append_alternate_mailboxes(mp, alt); > + > + alt = context_find("Default-From"); > + mp = append_alternate_mailboxes(mp, alt); > + } > + return mq; > +} > + > /* > ** Check if this is my address > */ > @@ -236,93 +298,11 @@ adrformat(struct mailname *mp) > int > ismymbox(struct mailname *np) > { > - int oops; > int len, i; > char *cp; > char *pp; > char buffer[BUFSIZ]; > - struct mailname *mp; > - static char *am = NULL; > - static struct mailname mq; > - > - /* > - ** If this is the first call, initialize > - ** list of alternate mailboxes. > - */ > - if (am == NULL) { > - mq.m_next = NULL; > - mq.m_mbox = getusername(); > - mp = &mq; > - if ((am = context_find("alternate-mailboxes")) == NULL) { > - am = getusername(); > - } else { > - oops = 0; > - while ((cp = getname(am))) { > - if ((mp->m_next = getm(cp, NULL, 0, AD_NAME, > NULL)) == NULL) { > - admonish(NULL, "illegal address: %s", > cp); > - oops++; > - } else { > - mp = mp->m_next; > - mp->m_type = W_NIL; > - if (*mp->m_mbox == '*') { > - mp->m_type |= W_MBEG; > - mp->m_mbox++; > - } > - if (*(cp = mp->m_mbox + > strlen(mp->m_mbox) - 1) == '*') { > - mp->m_type |= W_MEND; > - *cp = '\0'; > - } > - if (mp->m_host) { > - if (*mp->m_host == '*') { > - mp->m_type |= W_HBEG; > - mp->m_host++; > - } > - if (*(cp = mp->m_host + > strlen(mp->m_host) - 1) == '*') { > - mp->m_type |= W_HEND; > - *cp = '\0'; > - } > - } > - if ((cp = getenv("MHWDEBUG")) && *cp) { > - fprintf(stderr, "mbox=\"%s\" > host=\"%s\" %s\n", > - mp->m_mbox, mp->m_host, > - snprintb(buffer, > sizeof(buffer), (unsigned) mp->m_type, WBITS)); > - } > - } > - } > - if (oops != 0) { > - advise(NULL, "please fix the profile entry %s", > - "alternate-mailboxes"); > - } > - } > - > - if ((cp = context_find("Default-From")) != NULL) { > - int i = 0; > - char *cp2; > - oops = 0; > - > - while ((cp2 = getname(cp)) != NULL) { > - i++; > - if ((mp->m_next = getm(cp2, NULL, 0, AD_NAME, > NULL)) == NULL) { > - admonish(NULL, "illegal address: %s", > cp); > - oops++; > - } else { > - mp = mp->m_next; > - if ((cp = getenv("MHWDEBUG")) && *cp) { > - fprintf(stderr, "mbox=\"%s\" > host=\"%s\" %s\n", > - mp->m_mbox, mp->m_host, > - snprintb(buffer, > sizeof(buffer), (unsigned) mp->m_type, WBITS)); > - } > - } > - > - } > - > - if (oops != 0 || i < 1) { > - advise(NULL, "please fix the profile entry %s", > - "Default-From"); > - } > - > - } > - } > + const struct mailname *mp; > > if (np == NULL) /* XXX */ > return 0; > @@ -336,7 +316,7 @@ ismymbox(struct mailname *np) > > case LOCALHOST: > local_test: ; > - if (!mh_strcasecmp(np->m_mbox, mq.m_mbox)) > + if (!mh_strcasecmp(np->m_mbox, getusername())) > return 1; > break; > > @@ -348,8 +328,7 @@ local_test: ; > ** Now scan through list of alternate > ** mailboxes, and check for a match. > */ > - for (mp = &mq; mp->m_next;) { > - mp = mp->m_next; > + for (mp = get_alternate_mailboxes(); mp; mp = mp->m_next) { > if (!np->m_mbox) > continue; > if ((len = strlen(cp = np->m_mbox)) > -- > I may be not subscribed. Please, keep me in carbon copy. > > >