2006-11-13 [wwp] 2.6.0cvs39
[claws.git] / src / quote_fmt_parse.y
index 5d4681438094f6527a95b6e3999dd5ce927543c7..265aac601e071076fb061837e5c0e6d86d558b01 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws Team
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail Team
  *
  * 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
@@ -45,6 +45,7 @@ bison -p quote_fmt quote_fmt.y
 int yylex(void);
 
 static MsgInfo *msginfo = NULL;
+static PrefsAccount *account = NULL;
 static gboolean *visible = NULL;
 static gboolean dry_run = FALSE;
 static gint maxsize = 0;
@@ -115,6 +116,9 @@ static void clear_buffer(void)
 {
        if (current->buffer)
                *current->buffer = '\0';
+       else
+               /* force to an empty string, as buffer should not be left unallocated */
+               add_buffer("");
        current->bufsize = 0;
 }
 
@@ -146,12 +150,22 @@ gint quote_fmt_get_cursor_pos(void)
                add_buffer(tmp); \
        }
 
+void quote_fmt_reset_vartable(void)
+{
+       if (var_table) {
+               g_hash_table_destroy(var_table);
+               var_table = NULL;
+       }
+}
+
 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
-                   const gchar *my_body, gboolean my_dry_run)
+                   const gchar *my_body, gboolean my_dry_run,
+                       PrefsAccount *compose_account)
 {
        quote_str = my_quote_str;
        body = my_body;
        msginfo = info;
+       account = compose_account;
        dry_run = my_dry_run;
        stacksize = 0;
        add_visibility(TRUE);
@@ -160,11 +174,10 @@ void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
        current = &main_expr;
        clear_buffer();
        error = 0;
-       if (var_table) {
-               g_hash_table_destroy(var_table);
-               var_table = NULL;
-       }
-       var_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
+       if (!var_table)
+               var_table = g_hash_table_new_full(g_str_hash, g_str_equal, 
+                               g_free, g_free);
 
         /*
          * force LEX initialization
@@ -472,6 +485,7 @@ static void quote_fmt_insert_user_input(const gchar *varname)
        char str[256];
 }
 
+/* tokens SHOW */
 %token SHOW_NEWSGROUPS
 %token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME SHOW_LAST_NAME
 %token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
@@ -479,12 +493,18 @@ static void quote_fmt_insert_user_input(const gchar *varname)
 %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_EXCLAMATION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
+%token SHOW_ACCOUNT_FULL_NAME SHOW_ACCOUNT_MAIL_ADDRESS SHOW_ACCOUNT_NAME SHOW_ACCOUNT_ORGANIZATION
+/* tokens QUERY */
 %token QUERY_DATE QUERY_FROM
 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
+%token QUERY_ACCOUNT_FULL_NAME QUERY_ACCOUNT_ORGANIZATION
+/* tokens QUERY_NOT */
 %token QUERY_NOT_DATE QUERY_NOT_FROM
 %token QUERY_NOT_FULLNAME QUERY_NOT_SUBJECT QUERY_NOT_TO QUERY_NOT_NEWSGROUPS
 %token QUERY_NOT_MESSAGEID QUERY_NOT_CC QUERY_NOT_REFERENCES
+%token QUERY_NOT_ACCOUNT_FULL_NAME QUERY_NOT_ACCOUNT_ORGANIZATION
+/* other tokens */
 %token INSERT_FILE INSERT_PROGRAMOUTPUT INSERT_USERINPUT
 %token OPARENT CPARENT
 %token CHARACTER
@@ -635,6 +655,26 @@ special:
        {
                quote_fmt_show_msg(msginfo, body, TRUE, FALSE, quote_str);
        }
+       | SHOW_ACCOUNT_FULL_NAME
+       {
+               if (account && account->name)
+                       INSERT(account->name);
+       }
+       | SHOW_ACCOUNT_MAIL_ADDRESS
+       {
+               if (account && account->address)
+                       INSERT(account->address);
+       }
+       | SHOW_ACCOUNT_NAME
+       {
+               if (account && account->account_name)
+                       INSERT(account->account_name);
+       }
+       | SHOW_ACCOUNT_ORGANIZATION
+       {
+               if (account && account->organization)
+                       INSERT(account->organization);
+       }
        | SHOW_BACKSLASH
        {
                INSERT("\\");
@@ -749,6 +789,22 @@ query:
                add_visibility(found == TRUE);
        }
        OPARENT quote_fmt CPARENT
+       {
+               remove_visibility();
+       }
+       | QUERY_ACCOUNT_FULL_NAME
+       {
+               add_visibility(account != NULL && account->name != NULL);
+       }
+       OPARENT quote_fmt CPARENT
+       {
+               remove_visibility();
+       }
+       | QUERY_ACCOUNT_ORGANIZATION
+       {
+               add_visibility(account != NULL && account->organization != NULL);
+       }
+       OPARENT quote_fmt CPARENT
        {
                remove_visibility();
        };
@@ -830,6 +886,22 @@ query_not:
                add_visibility(found == FALSE);
        }
        OPARENT quote_fmt CPARENT
+       {
+               remove_visibility();
+       }
+       | QUERY_NOT_ACCOUNT_FULL_NAME
+       {
+               add_visibility(account == NULL || account->name == NULL);
+       }
+       OPARENT quote_fmt CPARENT
+       {
+               remove_visibility();
+       }
+       | QUERY_NOT_ACCOUNT_ORGANIZATION
+       {
+               add_visibility(account == NULL || account->organization == NULL);
+       }
+       OPARENT quote_fmt CPARENT
        {
                remove_visibility();
        };