2006-03-26 [colin] 2.0.0cvs173
[claws.git] / src / quote_fmt_parse.y
index 791d260520b6240eb425ad3d2e1dc28b085fb39e..3399ffc05b7496e304b68ccec0c14d8c97b9ad0e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto and the Sylpheed-Claws Team
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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
@@ -14,7 +14,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 %{
@@ -27,6 +27,7 @@
 #include "procmsg.h"
 #include "procmime.h"
 #include "utils.h"
+#include "codeconv.h"
 #include "procheader.h"
 
 #include "quote_fmt.h"
@@ -42,6 +43,7 @@ int yylex(void);
 
 static MsgInfo *msginfo = NULL;
 static gboolean *visible = NULL;
+static gboolean dry_run = FALSE;
 static gint maxsize = 0;
 static gint stacksize = 0;
 
@@ -52,7 +54,7 @@ static const gchar *quote_str = NULL;
 static const gchar *body = NULL;
 static gint error = 0;
 
-static gint cursor_pos  = 0;
+static gint cursor_pos  = -1;
 
 extern int quote_fmt_firsttime;
 
@@ -116,11 +118,12 @@ gint quote_fmt_get_cursor_pos(void)
        }
 
 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
-                   const gchar *my_body)
+                   const gchar *my_body, gboolean my_dry_run)
 {
        quote_str = my_quote_str;
        body = my_body;
        msginfo = info;
+       dry_run = my_dry_run;
        stacksize = 0;
        add_visibility(TRUE);
        if (buffer != NULL)
@@ -131,7 +134,7 @@ void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
          * force LEX initialization
          */
        quote_fmt_firsttime = 1;
-       cursor_pos = 0;
+       cursor_pos = -1;
 }
 
 void quote_fmterror(char *str)
@@ -209,7 +212,24 @@ static void quote_fmt_show_date(const MsgInfo *msginfo, const gchar *format)
                        }
                }
                
-               INSERT(result);
+               if (g_utf8_validate(result, -1, NULL)) {
+                       INSERT(result);
+               } else {
+                       gchar *utf = conv_codeset_strdup(result, 
+                               conv_get_locale_charset_str_no_utf8(),
+                               CS_INTERNAL);
+                       if (utf == NULL || 
+                           !g_utf8_validate(utf, -1, NULL)) {
+                               g_free(utf);
+                               utf = g_malloc(strlen(result)*2+1);
+                               conv_localetodisp(utf, 
+                                       strlen(result)*2+1, result);
+                       }
+                       if (g_utf8_validate(utf, -1, NULL)) {
+                               INSERT(utf);
+                       }
+                       g_free(utf);
+               }
        }
 #undef STR_SIZE                        
 #undef RLEFT                   
@@ -304,7 +324,7 @@ static void quote_fmt_show_sender_initial(const MsgInfo *msginfo)
        p = msginfo->fromname;
        cur = tmp;
        while (*p) {
-               if (*p && isalnum(*p)) {
+               if (*p && g_utf8_validate(p, 1, NULL)) {
                        *cur = toupper(*p);
                                cur++;
                        len++;
@@ -379,7 +399,7 @@ static void quote_fmt_insert_program_output(const gchar *progname)
                while (fgets(buffer, sizeof(buffer), file)) {
                        INSERT(buffer);
                }
-               fclose(file);
+               pclose(file);
        }
 }
 
@@ -647,9 +667,13 @@ query:
 insert:
        INSERT_FILE OPARENT string CPARENT
        {
-               quote_fmt_insert_file($3);
+               if (!dry_run) {
+                       quote_fmt_insert_file($3);
+               }
        }
        | INSERT_PROGRAMOUTPUT OPARENT string CPARENT
        {
-               quote_fmt_insert_program_output($3);
+               if (!dry_run) {
+                       quote_fmt_insert_program_output($3);
+               }
        };