Add %(unmailto) format function for List-Post headers
authormarkus schnalke <meillo@marmaro.de>
Tue, 6 Sep 2016 17:53:20 +0000 (19:53 +0200)
committermarkus schnalke <meillo@marmaro.de>
Tue, 6 Sep 2016 17:53:20 +0000 (19:53 +0200)
With the unmailto format function it is possible to extract
the address from a List-Post header, which e.g. is:
List-Post: <mailto:mmh@marmaro.de>
Applying  %(unmailto{list-post})  extracts: ``mmh@marmaro.de'',
which then can be used as recipient address for list replies.
A format file (to be used with ``repl -form repllistcomps'')
is included.

etc/Makefile.in
etc/repllistcomps [new file with mode: 0644]
h/fmt_compile.h
man/mh-format.man5
sbr/fmt_compile.c
sbr/fmt_scan.c
uip/fmtdump.c

index fd00e0d..aa0aa25 100644 (file)
@@ -32,7 +32,7 @@ STATIC_FILES = components digestcomps distcomps forwcomps \
                replcomps replgroupcomps scan.MMDDYY scan.YYYYMMDD \
                scan.nmh scan.mailx scan.nomime scan.size scan.time \
                scan.timely scan.unseen scan.meillo scan.default \
-               mhn.defaults
+               mhn.defaults repllistcomps
 
 # ========= DEPENDENCIES FOR BUILDING ==========
 
diff --git a/etc/repllistcomps b/etc/repllistcomps
new file mode 100644 (file)
index 0000000..24db8d6
--- /dev/null
@@ -0,0 +1,57 @@
+%; repllistcomps
+%;
+%; form (components) file for mailing list replies
+%;
+%; Check the following headers to create reply addresses.
+%;
+%; To: List-Post
+%;
+%; OR
+%;
+%; To: Mail-Followup-To
+%;
+%; OR
+%;
+%; To: Mail-Reply-To   (or)
+%;     Reply-To        (or)
+%;     From            (or)
+%;     Sender          (or)
+%;     Return-Path
+%;
+%; AND
+%;
+%; Cc: To              (and)
+%;     Cc              (and)
+%;     personal address
+%;
+%(lit)%(formataddr(unmailto{mail-followup-to}))\
+%<(nonnull)%(void(width))%(void(decode))%(putaddr To: )\n\
+%|\
+%(lit)%(formataddr{mail-followup-to})\
+%<(nonnull)%(void(width))%(void(decode))%(putaddr To: )\n\
+%|\
+%(lit)%(formataddr %<{mail-reply-to}%?{reply-to}%?{from}%?{sender}%?{return-path}%>)\
+%<(nonnull)%(void(width))%(void(decode))%(putaddr To: )\n%>\
+%(lit)%(formataddr{to})%(formataddr{cc})%(formataddr(me))\
+%<(nonnull)%(void(width))%(void(decode))%(putaddr Cc: )\n%>\
+%>\
+%>\
+%;
+Fcc: +sent
+Subject: %<{subject}Re: %(putstr(trim(decode{subject})))%>
+%;
+%; Make References: and In-reply-to: fields for threading.
+%; Use (trim) to eat trailing whitespace.
+%;
+%<{message-id}In-reply-to: %{message-id}\n%>\
+%<{message-id}References: \
+%<{references}%(trim{references})%(putstr) %>\
+%(trim{message-id})%(putstr)\n%>\
+Comments: In-reply-to \
+%<{from}%(void{from})%?(void{apparently-from})%|%(void{sender})%>\
+%(putstr(trim(decode)))\n\
+   message dated "%<(nodate{date})%{date}%|%(tws{date})%>."
+--------
+[%4(year{date})-%02(mon{date})-%02(mday{date}) \
+%02(hour{date}):%02(min{date})] %(decode{from})
+>
index a84efae..f034c6c 100644 (file)
 #define FT_V_MATCH       87    /* V = 1 if "str" contains literal    */
 #define FT_V_AMATCH      88    /* V = 1 if "str" starts with literal */
 
+#define FT_LS_UNMAILTO   89    /* remove "mailto:"                   */
+
 #define IF_FUNCS FT_S_NULL    /* start of "if" functions */
index f450012..703e633 100644 (file)
@@ -291,6 +291,7 @@ compval     comp    integer Set \fInum\fR to `\fBatoi\fR(\fIcomp\fR\^)'
 decode expr    string  decode \fIstr\fR as RFC-2047 (MIME-encoded)
                        component and print it
 unquote        expr    string  remove RFC-2822 quotes from \fIstr\fR
+unmailto       expr    string  remove `mailto:' and < > from \fIstr\fR
 trim   expr            trim trailing white-space from \fIstr\fR
 putstr expr            print \fIstr\fR
 putstrf        expr            print \fIstr\fR in a fixed width
index 566f620..2b32e71 100644 (file)
@@ -203,6 +203,7 @@ static struct ftable functable[] = {
        { "mymbox",     TF_COMP,    FT_LV_COMPFLAG, FT_MYMBOX, TFL_PUTN },
 
        { "unquote",    TF_EXPR,    FT_LS_UNQUOTE, 0, TFL_PUTS},
+       { "unmailto",   TF_EXPR,    FT_LS_UNMAILTO, 0, TFL_PUTS},
 
        { NULL,         0,          0, 0, 0 }
 };
index 6cfc176..9ad7b8a 100644 (file)
@@ -846,6 +846,20 @@ fmt_scan(struct format *format, char *scanl, int width, int *dat)
                        }
                        break;
 
+               case FT_LS_UNMAILTO:
+                       if (!str) {
+                               break;
+                       }
+                       str = trim(str);
+                       if (*str == '<' && str[strlen(str)-1] == '>') {
+                               str++;
+                               str[strlen(str)-1] = '\0';
+                       }
+                       if (strncmp("mailto:", str, 7)==0) {
+                               str += 7;
+                       }
+                       break;
+
                }
                fmt++;
        }
index a91333b..d75849b 100644 (file)
@@ -303,6 +303,9 @@ dumpone(struct format *fmt)
        case FT_LV_DAT:
                printf(", value dat[%d]", fmt->f_value);
                break;
+
+       case FT_LS_UNMAILTO:
+               break;
        }
        putchar('\n');
 }
@@ -420,6 +423,7 @@ f_typestr(int t)
        case FT_V_GT: return("V_GT");
        case FT_V_MATCH: return("V_MATCH");
        case FT_V_AMATCH: return("V_AMATCH");
+       case FT_LS_UNMAILTO: return("LS_UNMAILTO");
        default:
                printf(buf, "/* ??? #%d */", t);
                return(buf);