]> git.marmaro.de Git - mmh/commitdiff
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 a8d795f719f27aac4a1ba047930db2c91f526984..2888c57bc9e2c2a6c38c28aa3549abad5378955d 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 57cf7713ed012f4d27724930f239365548ae6d95..6b384d18917a97a9bec9bc760339e3e3120e11a6 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 239243fa53569e583d030714dff9352fbb241f9f..0b739cf98a62e319492a9f96bdd721e754387b47 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 868e603c5a506170cf275963dba9cfca62e28c42..d298c88bf250817f903b4471ed910d9a083de1f7 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 */
@@ -351,6 +352,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
 /*
  * Find the user's username and full name, and cache them.
  * Also, handle "mmailid" username masquerading controlled from the GECOS field
@@ -429,6 +458,8 @@ getuserinfo (void)
 
     fullname[sizeof(fullname) - 1] = '\0';
 
 
     fullname[sizeof(fullname) - 1] = '\0';
 
+    localmbox[0] = '\0';
+
     return;
 }
 
     return;
 }
 
index 8ee6884a2885704018c612373acd24cafa83efba..a0d4392ba2f604498511c8a3bc21552063a48638 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}"