From: Ken Hornstein Date: Fri, 17 Feb 2012 20:10:06 +0000 (-0500) Subject: Sigh. Looks like we need a function after all; create a new function X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=4f9a626afed661270364f0f7982fc3767f688e05;p=mmh Sigh. Looks like we need a function after all; create a new function called %(localmbox). --- diff --git a/h/mts.h b/h/mts.h index a8d795f..2888c57 100644 --- a/h/mts.h +++ b/h/mts.h @@ -24,6 +24,7 @@ extern char *uucplfil; char *getusername(void); char *getfullname(void); +char *getlocalmbox(void); /* * Separators diff --git a/man/mh-format.man b/man/mh-format.man index 57cf771..6b384d1 100644 --- a/man/mh-format.man +++ b/man/mh-format.man @@ -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 +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 @@ -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 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 diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 239243f..0b739cf 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -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_LMBOX 11 /* special - get full local mailbox */ /* 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 }, + { "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 }, @@ -601,6 +603,10 @@ do_func(char *sp) 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; diff --git a/sbr/mts.c b/sbr/mts.c index 868e603..d298c88 100644 --- 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"; -/* 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 localmbox[BUFSIZ]; /* 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 + */ + +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. @@ -429,6 +458,8 @@ getuserinfo (void) fullname[sizeof(fullname) - 1] = '\0'; + localmbox[0] = '\0'; + return; } diff --git a/test/format/test-localmbox b/test/format/test-localmbox index 8ee6884..a0d4392 100755 --- a/test/format/test-localmbox +++ b/test/format/test-localmbox @@ -19,7 +19,7 @@ echo "Local-Mailbox: ${testname}" >> ${MH} # 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}"