Carl Mummert: add unquote() function for removing quotes from RFC-2822 headers
authorOliver Kiddle <okiddle@yahoo.co.uk>
Wed, 18 May 2005 12:50:45 +0000 (12:50 +0000)
committerOliver Kiddle <okiddle@yahoo.co.uk>
Wed, 18 May 2005 12:50:45 +0000 (12:50 +0000)
ChangeLog
h/fmt_compile.h
man/mh-format.man
sbr/fmt_compile.c
sbr/fmt_scan.c

index ce64ad3..0a0d477 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-05-18  Oliver Kiddle  <okiddle@yahoo.co.uk>
+
+       * Carl Mummert: h/fmt_compile.h, man/mh-format.man,
+       sbr/fmt_compile.c, sbr/fmt_scan.c: add unquote() function for
+       removing quotes from RFC-2822 encoded headers
+
 2005-02-23  Oliver Kiddle  <okiddle@yahoo.co.uk>
 
        * use iconv to convert RFC-2047 encoded headers to the
 2005-02-23  Oliver Kiddle  <okiddle@yahoo.co.uk>
 
        * use iconv to convert RFC-2047 encoded headers to the
index f911504..eb79751 100644 (file)
 #define FT_LS_FRIENDLY 58      /* set "str" to "friendly" format addr */
 #define FT_LV_HOSTTYPE 59      /* set "value" to addr host type       */
 #define FT_LV_INGRPF   60      /* set "value" to addr in-group flag   */
 #define FT_LS_FRIENDLY 58      /* set "str" to "friendly" format addr */
 #define FT_LV_HOSTTYPE 59      /* set "value" to addr host type       */
 #define FT_LV_INGRPF   60      /* set "value" to addr in-group flag   */
-#define FT_LV_NOHOSTF  61      /* set "value" to addr no-host flag    */
+#define FT_LS_UNQUOTE  61      /* remove RFC 2822 quotes from "str"   */
+#define FT_LV_NOHOSTF  62      /* set "value" to addr no-host flag */
 
 /* Date Coercion */
 
 /* Date Coercion */
-#define FT_LOCALDATE   62      /* Coerce date to local timezone */
-#define FT_GMTDATE     63      /* Coerce date to gmt            */
+#define FT_LOCALDATE   63      /* Coerce date to local timezone */
+#define FT_GMTDATE     64      /* Coerce date to gmt            */
 
 /* pre-format processing */
 
 /* pre-format processing */
-#define FT_PARSEDATE   64      /* parse comp into a date (tws) struct */
-#define FT_PARSEADDR   65      /* parse comp into a mailaddr struct   */
-#define FT_FORMATADDR  66      /* let external routine format addr    */
-#define FT_MYMBOX      67      /* do "mymbox" test on comp            */
+#define FT_PARSEDATE   65      /* parse comp into a date (tws) struct */
+#define FT_PARSEADDR   66      /* parse comp into a mailaddr struct   */
+#define FT_FORMATADDR  67      /* let external routine format addr    */
+#define FT_MYMBOX      68      /* do "mymbox" test on comp            */
 
 /* misc. */            /* ADDTOSEQ only works if you include "options LBL" */
 
 /* misc. */            /* ADDTOSEQ only works if you include "options LBL" */
-#define FT_ADDTOSEQ    68      /* add current msg to a sequence       */
+#define FT_ADDTOSEQ    69      /* add current msg to a sequence       */
 
 /* conditionals & control flow (must be last) */
 
 /* conditionals & control flow (must be last) */
-#define FT_SAVESTR     69      /* save current str reg               */
-#define FT_DONE                70      /* stop formatting                    */
-#define FT_PAUSE       71      /* pause                              */
-#define FT_NOP         72      /* nop                                */
-#define FT_GOTO                73      /* (relative) goto                    */
-#define FT_IF_S_NULL   74      /* test if "str" null                 */
-#define FT_IF_S                75      /* test if "str" non-null             */
-#define FT_IF_V_EQ     76      /* test if "value" = literal          */
-#define FT_IF_V_NE     77      /* test if "value" != literal         */
-#define FT_IF_V_GT     78      /* test if "value" > literal          */
-#define FT_IF_MATCH    79      /* test if "str" contains literal     */
-#define FT_IF_AMATCH   80      /* test if "str" starts with literal  */
-#define FT_S_NULL      81      /* V = 1 if "str" null                */
-#define FT_S_NONNULL   82      /* V = 1 if "str" non-null            */
-#define FT_V_EQ                83      /* V = 1 if "value" = literal         */
-#define FT_V_NE                84      /* V = 1 if "value" != literal        */
-#define FT_V_GT                85      /* V = 1 if "value" > literal         */
-#define FT_V_MATCH     86      /* V = 1 if "str" contains literal    */
-#define FT_V_AMATCH    87      /* V = 1 if "str" starts with literal */
+#define FT_SAVESTR     70      /* save current str reg               */
+#define FT_DONE                71      /* stop formatting                    */
+#define FT_PAUSE       72      /* pause                              */
+#define FT_NOP         73      /* nop                                */
+#define FT_GOTO                74      /* (relative) goto                    */
+#define FT_IF_S_NULL   75      /* test if "str" null                 */
+#define FT_IF_S                76      /* test if "str" non-null             */
+#define FT_IF_V_EQ     77      /* test if "value" = literal          */
+#define FT_IF_V_NE     78      /* test if "value" != literal         */
+#define FT_IF_V_GT     79      /* test if "value" > literal          */
+#define FT_IF_MATCH    80      /* test if "str" contains literal     */
+#define FT_IF_AMATCH   81      /* test if "str" starts with literal  */
+#define FT_S_NULL      82      /* V = 1 if "str" null                */
+#define FT_S_NONNULL   83      /* V = 1 if "str" non-null            */
+#define FT_V_EQ                84      /* V = 1 if "value" = literal         */
+#define FT_V_NE                85      /* V = 1 if "value" != literal        */
+#define FT_V_GT                86      /* V = 1 if "value" > literal         */
+#define FT_V_MATCH     87      /* V = 1 if "str" contains literal    */
+#define FT_V_AMATCH    88      /* V = 1 if "str" starts with literal */
 
 #define IF_FUNCS FT_S_NULL     /* start of "if" functions */
 
 #define IF_FUNCS FT_S_NULL     /* start of "if" functions */
index 2fdae4b..d7ceccc 100644 (file)
@@ -282,6 +282,7 @@ compval     comp    integer Set \fInum\fR to \*(lq\fBatoi\fR(\fIcomp\fR\^)\*(rq
 .\" decodecomp comp    string  Set \fIstr\fR to RFC-2047 decoded component text
 decode expr    string  decode \fIstr\fR as RFC-2047 (MIME-encoded) 
                        component
 .\" decodecomp comp    string  Set \fIstr\fR to RFC-2047 decoded component text
 decode expr    string  decode \fIstr\fR as RFC-2047 (MIME-encoded) 
                        component
+unquote        expr    string  remove RFC-2822 quotes 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
 trim   expr            trim trailing white-space from \fIstr\fR
 putstr expr            print \fIstr\fR
 putstrf        expr            print \fIstr\fR in a fixed width
index a478acb..798f1f6 100644 (file)
@@ -149,6 +149,8 @@ static struct ftable functable[] = {
      { "mymbox",     TF_COMP,  FT_LV_COMPFLAG, FT_MYMBOX,      TFL_PUTN },
      { "addtoseq",   TF_STR,   FT_ADDTOSEQ,    0,              0 },
 
      { "mymbox",     TF_COMP,  FT_LV_COMPFLAG, FT_MYMBOX,      TFL_PUTN },
      { "addtoseq",   TF_STR,   FT_ADDTOSEQ,    0,              0 },
 
+     { "unquote",   TF_EXPR,   FT_LS_UNQUOTE,  0,              TFL_PUTS},
+
      { NULL,         0,                0,              0,              0 }
 };
 
      { NULL,         0,                0,              0,              0 }
 };
 
index 357484b..7558eca 100644 (file)
@@ -682,6 +682,38 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat)
                  }
                }
            }
                  }
                }
            }
+           break;  
+
+
+               /* UNQUOTEs RFC-2822 quoted-string and quoted-pair */
+       case FT_LS_UNQUOTE:
+           if (str) {          
+               int m;
+               strncpy(buffer, str, sizeof(buffer));
+               str = buffer;
+       
+               /* we will parse from buffer to buffer2 */
+               n = 0; /* n is the input position in str */
+               m = 0; /* m is the ouput position in buffer2 */
+
+               while ( str[n] != '\0') {
+                   switch ( str[n] ) {
+                       case '\\':
+                           n++;
+                           if ( str[n] != '\0') 
+                               buffer2[m++] = str[n++];
+                           break;
+                       case '"':
+                           n++;
+                           break;
+                       default:
+                           buffer2[m++] = str[n++];
+                           break;
+                       }                
+               }
+               buffer2[m] = '\0';
+               str = buffer2;
+            }
            break;
 
        case FT_LOCALDATE:
            break;
 
        case FT_LOCALDATE: