* src/quote_fmt.c
[claws.git] / src / quote_fmt_parse.y
index 42122f992493e5bb634bdc5d02d2eb20b25c2704..041e88833e9507ee8975b345103efe362e78084b 100644 (file)
@@ -29,7 +29,8 @@ static gint stacksize = 0;
 static gchar *buffer = NULL;
 static gint bufmax = 0;
 static gint bufsize = 0;
-static gchar *quote_str = NULL;
+static const gchar *quote_str = NULL;
+static const gchar *body = NULL;
 static gint error = 0;
 
 static void add_visibility(gboolean val)
@@ -50,7 +51,7 @@ static void remove_visibility(void)
        stacksize--;
 }
 
-static void add_buffer(gchar *s)
+static void add_buffer(const gchar *s)
 {
        gint len;
 
@@ -93,9 +94,11 @@ gchar *quote_fmt_get_buffer(void)
                add_buffer(tmp); \
        }
 
-void quote_fmt_init(MsgInfo *info, gchar *my_quote_str)
+void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
+                   const gchar *my_body)
 {
        quote_str = my_quote_str;
+       body = my_body;
        msginfo = info;
        stacksize = 0;
        add_visibility(TRUE);
@@ -124,6 +127,7 @@ static int isseparator(char ch)
 
 %union {
        char chr;
+       char str[256];
 }
 
 %token SHOW_NEWSGROUPS
@@ -132,10 +136,11 @@ static int isseparator(char ch)
 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
 %token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
-%token SHOW_EOL SHOW_QUESTION_MARK SHOW_OPARENT SHOW_CPARENT
+%token SHOW_EOL SHOW_QUESTION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
 %token QUERY_DATE QUERY_FROM
 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
+%token INSERT_FILE INSERT_PROGRAMOUTPUT
 %token OPARENT CPARENT
 %token CHARACTER
 
@@ -143,29 +148,43 @@ static int isseparator(char ch)
 
 %token <chr> CHARACTER
 %type <chr> character
+%type <str> string
 
 %%
 
 quote_fmt:
-       character_or_special_or_query_list;
+       character_or_special_or_insert_or_query_list;
 
-character_or_special_or_query_list:
-       character_or_special_or_query character_or_special_or_query_list
-       | character_or_special_or_query ;
+character_or_special_or_insert_or_query_list:
+       character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
+       | character_or_special_or_insert_or_query ;
 
-character_or_special_or_query:
-       special ;
+character_or_special_or_insert_or_query:
+       special
        | character
        {
                INSERT_CHARACTER($1);
        }
        | query ;
-
+       | insert ;
 
 character:
        CHARACTER
        ;
 
+string:
+       CHARACTER
+       {
+               $$[0] = $1;
+               $$[1] = '\0';
+       }
+       | string CHARACTER
+       {
+               strcpy($$, $1);
+               $$[strlen($$) + 1] = '\0';
+               $$[strlen($$)] = $2;
+       };
+
 special:
        SHOW_NEWSGROUPS
        {
@@ -265,8 +284,12 @@ special:
                        gchar buf[BUFFSIZE];
                        FILE *fp;
 
-                       if ((fp = procmime_get_first_text_content(msginfo))
-                           == NULL)
+                       if (body)
+                               fp = str_open_as_stream(body);
+                       else
+                               fp = procmime_get_first_text_content(msginfo);
+
+                       if (fp == NULL)
                                g_warning(_("Can't get text part\n"));
                        else {
                                while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -283,8 +306,12 @@ special:
                        gchar buf[BUFFSIZE];
                        FILE *fp;
 
-                       if ((fp = procmime_get_first_text_content(msginfo))
-                           == NULL)
+                       if (body)
+                               fp = str_open_as_stream(body);
+                       else
+                               fp = procmime_get_first_text_content(msginfo);
+
+                       if (fp == NULL)
                                g_warning(_("Can't get text part\n"));
                        else {
                                while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -303,8 +330,12 @@ special:
                        gchar buf[BUFFSIZE];
                        FILE *fp;
 
-                       if ((fp = procmime_get_first_text_content(msginfo))
-                           == NULL)
+                       if (body)
+                               fp = str_open_as_stream(body);
+                       else
+                               fp = procmime_get_first_text_content(msginfo);
+
+                       if (fp == NULL)
                                g_warning(_("Can't get text part\n"));
                        else {
                                while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -323,8 +354,12 @@ special:
                        gchar buf[BUFFSIZE];
                        FILE *fp;
 
-                       if ((fp = procmime_get_first_text_content(msginfo))
-                           == NULL)
+                       if (body)
+                               fp = str_open_as_stream(body);
+                       else
+                               fp = procmime_get_first_text_content(msginfo);
+
+                       if (fp == NULL)
                                g_warning(_("Can't get text part\n"));
                        else {
                                while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -355,6 +390,10 @@ special:
        {
                INSERT("?");
        }
+       | SHOW_PIPE
+       {
+               INSERT("|");
+       }
        | SHOW_OPARENT
        {
                INSERT("{");
@@ -437,3 +476,33 @@ query:
        {
                remove_visibility();
        };
+
+insert:
+       INSERT_FILE OPARENT string CPARENT
+       {
+               {
+                       FILE *file;
+                       char buffer[256];
+                       
+                       if(file = fopen($3, "r")) {
+                               while(fgets(buffer, sizeof(buffer), file)) {
+                                       INSERT(buffer);
+                               }
+                               fclose(file);
+                       }
+               }
+       }
+       | INSERT_PROGRAMOUTPUT OPARENT string CPARENT
+       {
+               {
+                       FILE *file;
+                       char buffer[256];
+
+                       if(file = popen($3, "r")) {
+                               while(fgets(buffer, sizeof(buffer), file)) {
+                                       INSERT(buffer);
+                               }
+                               fclose(file);
+                       }
+               }
+       };