]> diplodocus.org Git - nmh/commitdiff
Added getmymbox function escape.
authorDavid Levine <levinedl@acm.org>
Sun, 26 Oct 2014 15:41:04 +0000 (10:41 -0500)
committerDavid Levine <levinedl@acm.org>
Sun, 26 Oct 2014 15:41:04 +0000 (10:41 -0500)
docs/pending-release-notes
h/fmt_compile.h
man/mh-format.man
sbr/fmt_compile.c
sbr/fmt_scan.c
test/format/test-mymbox
uip/fmtdump.c
uip/fmttest.c

index 07c073a..1f46d79 100644 (file)
@@ -24,6 +24,7 @@ NEW FEATURES
   obsolete support programs that should be removed.
 - When building from source, configure will derive ${prefix} from an existing
   nmh installation if it finds one in your $PATH.
+- Added getmymbox function escape.
 
 -----------------
 OBSOLETE FEATURES
index b0c12c0..bda2e61 100644 (file)
@@ -73,7 +73,7 @@
 #define FT_LV_HOSTTYPE  63      /* set "value" to addr host type       */
 #define FT_LV_INGRPF    64      /* set "value" to addr in-group flag   */
 #define FT_LS_UNQUOTE   65      /* remove RFC 2822 quotes from "str"   */
-#define FT_LV_NOHOSTF   66     /* set "value" to addr no-host flag */
+#define FT_LV_NOHOSTF   66      /* set "value" to addr no-host flag */
 
 /* Date Coercion */
 #define FT_LOCALDATE    67      /* Coerce date to local timezone */
 #define FT_FORMATADDR   71      /* let external routine format addr    */
 #define FT_CONCATADDR   72      /* formataddr w/out duplicate removal  */
 #define FT_MYMBOX       73      /* do "mymbox" test on comp            */
+#define FT_GETMYMBOX    74      /* do "mymbox" test on comp, ret str   */
 
 /* conditionals & control flow (must be last) */
-#define FT_SAVESTR      74      /* save current str reg               */
-#define FT_DONE         75      /* stop formatting                    */
-#define FT_PAUSE        76      /* pause                              */
-#define FT_NOP          77      /* nop                                */
-#define FT_GOTO         78      /* (relative) goto                    */
-#define FT_IF_S_NULL    79      /* test if "str" null                 */
-#define FT_IF_S         80      /* test if "str" non-null             */
-#define FT_IF_V_EQ      81      /* test if "value" = literal          */
-#define FT_IF_V_NE      82      /* test if "value" != literal         */
-#define FT_IF_V_GT      83      /* test if "value" > literal          */
-#define FT_IF_MATCH     84      /* test if "str" contains literal     */
-#define FT_IF_AMATCH    85      /* test if "str" starts with literal  */
-#define FT_S_NULL       86      /* V = 1 if "str" null                */
-#define FT_S_NONNULL    87      /* V = 1 if "str" non-null            */
-#define FT_V_EQ         88      /* V = 1 if "value" = literal         */
-#define FT_V_NE         89      /* V = 1 if "value" != literal        */
-#define FT_V_GT         90      /* V = 1 if "value" > literal         */
-#define FT_V_MATCH      91      /* V = 1 if "str" contains literal    */
-#define FT_V_AMATCH     92      /* V = 1 if "str" starts with literal */
+#define FT_SAVESTR      75      /* save current str reg               */
+#define FT_DONE         76      /* stop formatting                    */
+#define FT_PAUSE        77      /* pause                              */
+#define FT_NOP          78      /* nop                                */
+#define FT_GOTO         79      /* (relative) goto                    */
+#define FT_IF_S_NULL    80      /* test if "str" null                 */
+#define FT_IF_S         81      /* test if "str" non-null             */
+#define FT_IF_V_EQ      82      /* test if "value" = literal          */
+#define FT_IF_V_NE      83      /* test if "value" != literal         */
+#define FT_IF_V_GT      84      /* test if "value" > literal          */
+#define FT_IF_MATCH     85      /* test if "str" contains literal     */
+#define FT_IF_AMATCH    86      /* test if "str" starts with literal  */
+#define FT_S_NULL       87      /* V = 1 if "str" null                */
+#define FT_S_NONNULL    88      /* V = 1 if "str" non-null            */
+#define FT_V_EQ         89      /* V = 1 if "value" = literal         */
+#define FT_V_NE         90      /* V = 1 if "value" != literal        */
+#define FT_V_GT         91      /* V = 1 if "value" > literal         */
+#define FT_V_MATCH      92      /* V = 1 if "str" contains literal    */
+#define FT_V_AMATCH     93      /* V = 1 if "str" starts with literal */
 
 #define IF_FUNCS FT_S_NULL      /* start of "if" functions */
index c3e277a..87dee2f 100644 (file)
@@ -395,7 +395,9 @@ addr        addr    string  mbox@host or host!mbox rendering*
 pers   addr    string  the personal name*
 note   addr    string  commentary text*
 mbox   addr    string  the local mailbox*
-mymbox addr    integer List has the user's address? (0 or 1)
+mymbox addr    integer list has the user's address? (0 or 1)
+getmymbox      addr    string  the user's (first) address,
+                       without personal name
 host   addr    string  the host domain*
 nohost addr    integer no host was present (0 or 1)*
 type   addr    integer host type* (0=local,1=network,
index 21acb5c..3f3db64 100644 (file)
@@ -223,6 +223,7 @@ static struct ftable functable[] = {
      { "friendly",   TF_COMP,  FT_LS_FRIENDLY, FT_PARSEADDR,   TFL_PUTS },
 
      { "mymbox",     TF_COMP,  FT_LV_COMPFLAG, FT_MYMBOX,      TFL_PUTN },
+     { "getmymbox",  TF_COMP,  FT_LS_ADDR,     FT_GETMYMBOX,   TFL_PUTS },
 
      { "unquote",    TF_EXPR,  FT_LS_UNQUOTE,  0,              TFL_PUTS },
 
@@ -573,6 +574,7 @@ do_name(char *sp, int preprocess)
        break;
 
     case FT_MYMBOX:
+    case FT_GETMYMBOX:
        if (!primed) {
            ismymbox ((struct mailname *) 0);
            primed++;
index 99b8344..759a81f 100644 (file)
@@ -1062,6 +1062,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
            break;
 
        case FT_MYMBOX:
+       case FT_GETMYMBOX:
            /*
             * if there's no component, we say true.  Otherwise we
             * say "true" only if we can parse the address and it
@@ -1073,24 +1074,36 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
            if ((sp = comp->c_text) && (sp = getname(sp)) &&
                (mn = getm (sp, NULL, 0, NULL, 0))) {
                comp->c_mn = mn;
-               if (ismymbox(mn))
+               if (ismymbox(mn)) {
                    comp->c_flags |= CF_TRUE;
-               else
+                   /* Set str for use with FT_GETMYMBOX.  It will be
+                      run through FT_LS_ADDR, which will strip off
+                      any pers name. */
+                    str = mn->m_text;
+               } else {
                    comp->c_flags &= ~CF_TRUE;
+                }
                while ((sp = getname(sp)))
                    if ((comp->c_flags & CF_TRUE) == 0 &&
                        (mn = getm (sp, NULL, 0, NULL, 0)))
                        if (ismymbox(mn))
                            comp->c_flags |= CF_TRUE;
+               comp->c_flags |= CF_PARSED;
            } else {
                while (getname(""))             /* XXX */
                    ;
                if (comp->c_text == 0)
                    comp->c_flags |= CF_TRUE;
-               else
+               else {
                    comp->c_flags &= ~CF_TRUE;
+                }
                comp->c_mn = &fmt_mnull;
            }
+           if ((comp->c_flags & CF_TRUE) == 0  &&
+               fmt->f_type == FT_GETMYMBOX) {
+               /* Fool FT_LS_ADDR into not producing an address. */
+               comp->c_mn = &fmt_mnull; comp->c_text = NULL;
+           }
            break;
        }
 
index 753f92e..8816cb6 100755 (executable)
@@ -31,9 +31,9 @@ myname="Random User <random@user.something.com>"
 
 #### Remove existing Local-Mailbox: profile component, if any.  Then
 #### add one.
-grep -v 'Local-Mailbox: ' ${MH} > ${MH}.new
-mv -f ${MH}.new ${MH}
-echo "Local-Mailbox: ${myname}" >> ${MH}
+grep -v 'Local-Mailbox: ' "$MH" > "$MH".new
+mv -f "$MH".new "$MH"
+echo "Local-Mailbox: ${myname}" >> "$MH"
 
 run_test "echo \
          `run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
@@ -50,4 +50,17 @@ run_test "echo \
          `run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${myname}"`" \
          1 "Local-Mailbox with Alternate-Mailbox test"
 
+# check getmymbox, without match
+run_test 'fmttest -message -format %(getmymbox{from}) first' ''
+
+grep -v 'Alternate-Mailboxes: ' "$MH" > "$MH".new
+mv -f "$MH".new "$MH"
+cat >>"$MH" <<EOF
+Alternate-Mailboxes: test1@example.com
+EOF
+
+# check getmymbox, with match
+run_test 'fmttest -message -format %(getmymbox{from}) first' \
+         'test1@example.com'
+
 exit $failed
index 86dbfef..7879431 100644 (file)
@@ -210,6 +210,7 @@ dumpone(struct format *fmt)
        case FT_LS_FRIENDLY:
        case FT_PARSEADDR:
        case FT_MYMBOX:
+       case FT_GETMYMBOX:
                printf(", c_name ");
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
@@ -413,6 +414,7 @@ f_typestr(int t)
        case FT_FORMATADDR: return("FORMATADDR");
        case FT_CONCATADDR: return("CONCATADDR");
        case FT_MYMBOX: return("MYMBOX");
+       case FT_GETMYMBOX: return("GETMYMBOX");
        case FT_SAVESTR: return("SAVESTR");
 #ifdef FT_PAUSE
        case FT_PAUSE: return ("PAUSE");
index b2d513e..f5fe246 100644 (file)
@@ -846,6 +846,7 @@ dumpone(struct format *fmt)
        case FT_LS_FRIENDLY:
        case FT_PARSEADDR:
        case FT_MYMBOX:
+       case FT_GETMYMBOX:
                printf(", c_name ");
                litputs(fmt->f_comp->c_name);
                if (fmt->f_comp->c_type)
@@ -1086,6 +1087,7 @@ f_typestr(int t)
        case FT_FORMATADDR: return("FORMATADDR");
        case FT_CONCATADDR: return("CONCATADDR");
        case FT_MYMBOX: return("MYMBOX");
+       case FT_GETMYMBOX: return("GETMYMBOX");
 #ifdef FT_ADDTOSEQ
        case FT_ADDTOSEQ: return("ADDTOSEQ");
 #endif