Sigh. Looks like we need a function after all; create a new function
authorKen Hornstein <kenh@pobox.com>
Fri, 17 Feb 2012 20:10:06 +0000 (15:10 -0500)
committerKen Hornstein <kenh@pobox.com>
Fri, 17 Feb 2012 20:10:06 +0000 (15:10 -0500)
called %(localmbox).

h/mts.h
man/mh-format.man
sbr/fmt_compile.c
sbr/mts.c
test/format/test-localmbox

diff --git a/h/mts.h b/h/mts.h
index a8d795f..2888c57 100644 (file)
--- a/h/mts.h
+++ b/h/mts.h
@@ -24,6 +24,7 @@ extern char *uucplfil;
 
 char *getusername(void);
 char *getfullname(void);
 
 char *getusername(void);
 char *getfullname(void);
+char *getlocalmbox(void);
 
 /*
  * Separators
 
 /*
  * Separators
index 57cf771..6b384d1 100644 (file)
@@ -263,6 +263,7 @@ timenow             integer seconds since the UNIX epoch
 me             string  the user's mailbox (username)
 myhost         string  the user's local hostname
 myname         string  the user's name
 me             string  the user's mailbox (username)
 myhost         string  the user's local hostname
 myname         string  the user's name
+localmbox      string  the complete local mailbox
 eq     literal boolean \fInum\fR == \fIarg\fR
 ne     literal boolean \fInum\fR != \fIarg\fR
 gt     literal boolean \fInum\fR > \fIarg\fR
 eq     literal boolean \fInum\fR == \fIarg\fR
 ne     literal boolean \fInum\fR != \fIarg\fR
 gt     literal boolean \fInum\fR > \fIarg\fR
@@ -323,7 +324,17 @@ is not configured.  The (\fImyname\fR\^) function will return the value of
 the
 .B SIGNATURE
 environment variable if set, otherwise will return the passwd GECOS field for
 the
 .B SIGNATURE
 environment variable if set, otherwise will return the passwd GECOS field for
-the current user.
+the current user.  The (\fIlocalmbox\fR\^) function will return the complete
+form of the local mailbox, suitable for use in a \*(lqFrom\*(rq header.
+It will return the
+.RI \*(lq Local-Mailbox \*(rq
+profile entry if it is set; if it is not, it will be equivalent to:
+.PP
+.RS 5
+.nf
+%(myname) <%(me)@%(myhost)>
+.fi
+.RE
 .PP
 The following functions require a date component as an argument:
 .PP
 .PP
 The following functions require a date component as an argument:
 .PP
index 239243f..0b739cf 100644 (file)
@@ -78,6 +78,7 @@ extern struct mailname fmt_mnull;
 #define        TF_NOP     8        /* like expr but no result            */
 #define TF_MYNAME  9        /* special - get current name of user */
 #define TF_MYHOST  10       /* special - get "local" hostname     */
 #define        TF_NOP     8        /* like expr but no result            */
 #define TF_MYNAME  9        /* special - get current name of user */
 #define TF_MYHOST  10       /* special - get "local" hostname     */
+#define TF_LMBOX   11       /* special - get full local mailbox   */
 
 /* ftable->flags */
 /* NB that TFL_PUTS is also used to decide whether the test
 
 /* ftable->flags */
 /* NB that TFL_PUTS is also used to decide whether the test
@@ -158,6 +159,7 @@ static struct ftable functable[] = {
      { "me",         TF_MYBOX, FT_LS_LIT,      0,              TFL_PUTS },
      { "myname",     TF_MYNAME,        FT_LS_LIT,      0,              TFL_PUTS },
      { "myhost",     TF_MYHOST,        FT_LS_LIT,      0,              TFL_PUTS },
      { "me",         TF_MYBOX, FT_LS_LIT,      0,              TFL_PUTS },
      { "myname",     TF_MYNAME,        FT_LS_LIT,      0,              TFL_PUTS },
      { "myhost",     TF_MYHOST,        FT_LS_LIT,      0,              TFL_PUTS },
+     { "localmbox",  TF_LMBOX, FT_LS_LIT,      0,              TFL_PUTS },
      { "plus",       TF_NUM,   FT_LV_PLUS_L,   0,              TFL_PUTN },
      { "minus",      TF_NUM,   FT_LV_MINUS_L,  0,              TFL_PUTN },
      { "divide",     TF_NUM,   FT_LV_DIVIDE_L, 0,              TFL_PUTN },
      { "plus",       TF_NUM,   FT_LV_PLUS_L,   0,              TFL_PUTN },
      { "minus",      TF_NUM,   FT_LV_MINUS_L,  0,              TFL_PUTN },
      { "divide",     TF_NUM,   FT_LV_DIVIDE_L, 0,              TFL_PUTN },
@@ -601,6 +603,10 @@ do_func(char *sp)
        LS(t->f_type, LocalName(0));
        break;
 
        LS(t->f_type, LocalName(0));
        break;
 
+    case TF_LMBOX:
+       LS(t->f_type, getlocalmbox());
+       break;
+
     case TF_NOW:
        LV(t->f_type, time((time_t *) 0));
        break;
     case TF_NOW:
        LV(t->f_type, time((time_t *) 0));
        break;
index 868e603..d298c88 100644 (file)
--- a/sbr/mts.c
+++ b/sbr/mts.c
@@ -54,9 +54,10 @@ char *uucplfil = "";
 char *mmdlm1 = "\001\001\001\001\n";
 char *mmdlm2 = "\001\001\001\001\n";
 
 char *mmdlm1 = "\001\001\001\001\n";
 char *mmdlm2 = "\001\001\001\001\n";
 
-/* Cache the username and fullname of the user */
+/* Cache the username, fullname, and mailbox of the user */
 static char username[BUFSIZ];
 static char fullname[BUFSIZ];
 static char username[BUFSIZ];
 static char fullname[BUFSIZ];
+static char localmbox[BUFSIZ];
 
 /* Variables for username masquerading: */
        boolean  draft_from_masquerading = FALSE;  /* also used from post.c */
 
 /* Variables for username masquerading: */
        boolean  draft_from_masquerading = FALSE;  /* also used from post.c */
@@ -352,6 +353,34 @@ getfullname (void)
 
 
 /*
 
 
 /*
+ * Get the full local mailbox name.  This is in the form:
+ *
+ * User Name <user@name.com>
+ */
+
+char *
+getlocalmbox (void)
+{
+    if (username[0] == '\0')
+       getuserinfo();
+
+    if (localmbox[0] == '\0') {
+       char *cp;
+
+       if ((cp = context_find("Local-Mailbox")) != NULL) {
+           strncpy(localmbox, cp, sizeof(localmbox));
+       } else {
+           snprintf(localmbox, sizeof(localmbox), "%s <%s@%s>", fullname,
+                    username, LocalName(0));
+       }
+
+       localmbox[sizeof(localmbox) - 1] = '\0';
+    }
+
+    return localmbox;
+}
+
+/*
  * Find the user's username and full name, and cache them.
  * Also, handle "mmailid" username masquerading controlled from the GECOS field
  * of the passwd file. 
  * Find the user's username and full name, and cache them.
  * Also, handle "mmailid" username masquerading controlled from the GECOS field
  * of the passwd file. 
@@ -429,6 +458,8 @@ getuserinfo (void)
 
     fullname[sizeof(fullname) - 1] = '\0';
 
 
     fullname[sizeof(fullname) - 1] = '\0';
 
+    localmbox[0] = '\0';
+
     return;
 }
 
     return;
 }
 
index 8ee6884..a0d4392 100755 (executable)
@@ -19,7 +19,7 @@ echo "Local-Mailbox: ${testname}" >> ${MH}
 
 # We can use "ap" to get the output of format commands
 
 
 # We can use "ap" to get the output of format commands
 
-testoutput=$(${MH_LIB_DIR}/ap -format "%(profile Local-Mailbox)" ignore)
+testoutput=$(${MH_LIB_DIR}/ap -format "%(localmbox)" ignore)
 
 if [ x"${testname}" != x"${testoutput}" ]; then
        echo "Expected ${testname}, got ${testoutput}"
 
 if [ x"${testname}" != x"${testoutput}" ]; then
        echo "Expected ${testname}, got ${testoutput}"