2007-10-17 [wwp] 3.0.2cvs79
[claws.git] / src / quote_fmt_parse.y
index 4fc60904ba737e9d20a26c3c4cefe40b2ee36353..06ec182c7f0e01dd71e247bbc600cecee2be7801 100644 (file)
@@ -4,7 +4,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 %{
@@ -47,12 +47,15 @@ int yylex(void);
 
 static MsgInfo *msginfo = NULL;
 static PrefsAccount *account = NULL;
+#ifdef USE_ASPELL
 static gchar default_dictionary[BUFFSIZE];
+#endif
 static gboolean *visible = NULL;
 static gboolean dry_run = FALSE;
 static gint maxsize = 0;
 static gint stacksize = 0;
 static GHashTable *var_table = NULL;
+static GList *attachments = NULL;
 
 typedef struct st_buffer
 {
@@ -136,6 +139,17 @@ gchar *quote_fmt_get_buffer(void)
                return current->buffer;
 }
 
+GList *quote_fmt_get_attachments_list(void)
+{
+       fprintf(stderr, "+ get attachment list %p\n", attachments);
+       return attachments;
+}
+
+gint quote_fmt_get_line(void)
+{
+       return line;
+}
+
 gint quote_fmt_get_cursor_pos(void)
 {
        return cursor_pos;      
@@ -159,22 +173,41 @@ void quote_fmt_reset_vartable(void)
                g_hash_table_destroy(var_table);
                var_table = NULL;
        }
+       if (attachments) {
+               fprintf(stderr, "+ freeing attachment list\n");
+               GList *cur = attachments;
+               while (cur) {
+                       fprintf(stderr, "-> %s\n", (gchar*)cur->data);
+                       g_free(cur->data);
+                       cur = g_list_next(cur);
+               }
+               g_list_free(attachments);
+               attachments = NULL;
+       }
 }
 
+#ifdef USE_ASPELL
 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
                    const gchar *my_body, gboolean my_dry_run,
                        PrefsAccount *compose_account,
                        GtkAspell *compose_gtkaspell)
+#else
+void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
+                   const gchar *my_body, gboolean my_dry_run,
+                       PrefsAccount *compose_account)
+#endif
 {
-       gchar *dict = gtkaspell_get_default_dictionary(compose_gtkaspell);
        quote_str = my_quote_str;
        body = my_body;
        msginfo = info;
        account = compose_account;
+#ifdef USE_ASPELL
+       gchar *dict = gtkaspell_get_default_dictionary(compose_gtkaspell);
        if (dict)
                strncpy2(default_dictionary, dict, sizeof(default_dictionary));
        else
                *default_dictionary = '\0';
+#endif
        dry_run = my_dry_run;
        stacksize = 0;
        add_visibility(TRUE);
@@ -411,7 +444,7 @@ static void quote_fmt_show_msg(MsgInfo *msginfo, const gchar *body,
        if (body)
                fp = str_open_as_stream(body);
        else {
-               if (procmime_msginfo_is_encrypted(msginfo))
+               if (MSG_IS_ENCRYPTED(msginfo->flags))
                        fp = procmime_get_first_encrypted_text_content(msginfo);
                else
                        fp = procmime_get_first_text_content(msginfo);
@@ -488,6 +521,12 @@ static void quote_fmt_insert_user_input(const gchar *varname)
        g_free(text);
 }
 
+static void quote_fmt_attach_file(const gchar *filename)
+{
+       fprintf(stderr, "+ adding attachment %s\n", filename);
+       attachments = g_list_append(attachments, g_strdup(filename));
+}
+
 static gchar *quote_fmt_complete_address(const gchar *addr)
 {
        gint count;
@@ -543,7 +582,7 @@ static gchar *quote_fmt_complete_address(const gchar *addr)
 %token SHOW_EOL SHOW_QUESTION_MARK SHOW_EXCLAMATION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
 %token SHOW_ACCOUNT_FULL_NAME SHOW_ACCOUNT_MAIL_ADDRESS SHOW_ACCOUNT_NAME SHOW_ACCOUNT_ORGANIZATION
 %token SHOW_ACCOUNT_DICT
-%token SHOW_DICT
+%token SHOW_DICT SHOW_TAGS
 %token SHOW_ADDRESSBOOK_COMPLETION_FOR_CC
 %token SHOW_ADDRESSBOOK_COMPLETION_FOR_FROM
 %token SHOW_ADDRESSBOOK_COMPLETION_FOR_TO
@@ -567,6 +606,7 @@ static gchar *quote_fmt_complete_address(const gchar *addr)
 %token QUERY_NOT_TO_FOUND_IN_ADDRESSBOOK
 /* other tokens */
 %token INSERT_FILE INSERT_PROGRAMOUTPUT INSERT_USERINPUT
+%token ATTACH_FILE
 %token OPARENT CPARENT
 %token CHARACTER
 %token SHOW_DATE_EXPR
@@ -598,7 +638,8 @@ character_or_special_or_insert_or_query:
        character_or_special
        | query
        | query_not
-       | insert ;
+       | insert
+       | attach ;
 
 character_or_special:
        special
@@ -747,15 +788,27 @@ special:
        }
        | SHOW_ACCOUNT_DICT
        {
+#ifdef USE_ASPELL
                if (account && account->enable_default_dictionary) {
                        gchar *dictname = g_path_get_basename(account->default_dictionary);
                        INSERT(dictname);
                        g_free(dictname);
                }
+#endif
        }
        | SHOW_DICT
        {
+#ifdef USE_ASPELL
                INSERT(default_dictionary);
+#endif
+       }
+       | SHOW_TAGS
+       {
+               gchar *tags = procmsg_msginfo_get_tags_str(msginfo);
+               if (tags) {
+                       INSERT(tags);
+               }
+               g_free(tags);
        }
        | SHOW_BACKSLASH
        {
@@ -791,7 +844,10 @@ special:
        }
        | SET_CURSOR_POS
        {
-               cursor_pos = current->bufsize;
+               if (current->buffer)
+                       cursor_pos = g_utf8_strlen(current->buffer, -1);
+               else
+                       cursor_pos = 0;
        }
        | SHOW_ADDRESSBOOK_COMPLETION_FOR_CC
        {
@@ -916,8 +972,12 @@ query:
        }
        | QUERY_ACCOUNT_DICT
        {
+#ifdef USE_ASPELL
                add_visibility(account != NULL && account->enable_default_dictionary == TRUE &&
                                account->default_dictionary != NULL && *account->default_dictionary != '\0');
+#else
+               add_visibility(FALSE);
+#endif
        }
        OPARENT quote_fmt CPARENT
        {
@@ -925,7 +985,11 @@ query:
        }
        | QUERY_DICT
        {
+#ifdef USE_ASPELL
                add_visibility(*default_dictionary != '\0');
+#else
+               add_visibility(FALSE);
+#endif
        }
        OPARENT quote_fmt CPARENT
        {
@@ -1060,8 +1124,12 @@ query_not:
        }
        | QUERY_NOT_ACCOUNT_DICT
        {
+#ifdef USE_ASPELL
                add_visibility(account == NULL || account->enable_default_dictionary == FALSE
                                || *account->default_dictionary == '\0');
+#else
+               add_visibility(FALSE);
+#endif
        }
        OPARENT quote_fmt CPARENT
        {
@@ -1069,7 +1137,11 @@ query_not:
        }
        | QUERY_NOT_DICT
        {
+#ifdef USE_ASPELL
                add_visibility(*default_dictionary == '\0');
+#else
+               add_visibility(FALSE);
+#endif
        }
        OPARENT quote_fmt CPARENT
        {
@@ -1143,3 +1215,17 @@ insert:
                        quote_fmt_insert_user_input(sub_expr.buffer);
                }
        };
+
+attach:
+       ATTACH_FILE
+       {
+               current = &sub_expr;
+               clear_buffer();
+       }
+       OPARENT sub_expr CPARENT
+       {
+               current = &main_expr;
+               if (!dry_run) {
+                       quote_fmt_attach_file(sub_expr.buffer);
+               }
+       };