Fixed ismymbox() to look at Local-Mailbox as well as
[mmh] / sbr / addrsbr.c
index 7bf4673..6c9fe0e 100644 (file)
@@ -10,6 +10,7 @@
 #include <h/mh.h>
 #include <h/addrsbr.h>
 #include <h/mf.h>
+#include <h/mts.h>
 
 /* High level parsing of addresses:
 
@@ -76,15 +77,6 @@ static char err[BUFSIZ];
 static char adr[BUFSIZ];
 
 
-extern boolean  username_extension_masquerading;  /* defined in mts.c */
-
-
-/*
- * external prototypes
- */
-char *getusername (void);
-
-
 char *
 getname (char *addrs)
 {
@@ -201,6 +193,8 @@ getm (char *str, char *dfhost, int dftype, int wanthost, char *eresult)
        goto got_host;
     }
 
+    /* For alternate mailboxes, m_type gets overwritten in ismymbox ()
+       to support wild-card matching. */
     if (wanthost == AD_NHST)
        mp->m_type = !mh_strcasecmp (LocalName (0), mp->m_host)
            ? LOCALHOST : NETHOST;
@@ -296,47 +290,11 @@ auxformat (struct mailname *mp, int extras)
 char *
 getlocaladdr(void)
 {
-    int          snprintf_return;
-    char        *username, *domain;
-    static char  addr[BUFSIZ];
+    char        *username;
 
     username = getusername();
 
-    if (username_extension_masquerading) {
-       /* mts.conf contains "masquerade:[...]username_extension[...]", so tack
-          on the value of the $USERNAME_EXTENSION environment variable, if set,
-          to username. */
-       char*        extension = getenv("USERNAME_EXTENSION");
-       static char  username_with_extension[BUFSIZ];
-
-       if (extension != NULL && *extension != '\0') {
-           snprintf_return = snprintf(username_with_extension,
-                                      sizeof(username_with_extension),
-                                      "%s%s", username, extension);
-           
-           if (snprintf_return < 0 ||
-               snprintf_return >= (int) sizeof(username_with_extension))
-               adios(NULL, "snprintf() error writing username (%d chars) and"
-                     " $USERNAME_EXTENSION (%d chars) to array of BUFSIZ (%d)"
-                     " chars",
-                     strlen(username), strlen(extension), BUFSIZ);
-           
-           username = username_with_extension;
-       }
-    }
-
     return username;
-
-    domain = LocalName(0);
-
-    snprintf_return = snprintf (addr, sizeof(addr), "%s@%s", username, domain);
-
-    if (snprintf_return < 0 || snprintf_return >= (int) sizeof(addr))
-       adios(NULL, "snprintf() error writing username (%d chars), domain (%d"
-             " chars), and 1 separator char to array of BUFSIZ (%d) chars",
-             strlen(username), strlen(domain), BUFSIZ);
-    
-    return addr;
 }
 
 
@@ -400,7 +358,7 @@ ismymbox (struct mailname *np)
        if ((am = context_find ("alternate-mailboxes")) == NULL)
            am = getusername();
        else {
-           mp = &mq;
+           mp = mq.m_next ? mq.m_next : &mq;
            oops = 0;
            while ((cp = getname (am))) {
                if ((mp->m_next = getm (cp, NULL, 0, AD_NAME, NULL)) == NULL) {
@@ -427,16 +385,23 @@ ismymbox (struct mailname *np)
                            *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)
                advise (NULL, "please fix the %s: entry in your %s file",
                        "alternate-mailboxes", mh_profile);
        }
+
+       if ((cp = getenv ("MHWDEBUG")) && *cp) {
+           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 : "",
+                      snprintb (buffer, sizeof(buffer), (unsigned) mp->m_type,
+                                WBITS));
+           }
+       }
     }
 
     if (np == NULL) /* XXX */