2006-04-06 [mones] 2.1.0cvs7
[claws.git] / src / addritem.c
index c0d9d70a2433ad2be65c5dca8d5d1318f15ea76f..b6423390cd95a4e6e74d11ff38f13a6162c5883e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2003 Match Grun
+ * Copyright (C) 2001-2006 Match Grun 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.
  */
 
 /*
@@ -28,6 +28,7 @@
 #include "utils.h"
 #include "addritem.h"
 #include "mgutils.h"
+#include "codeconv.h"
 
 /**
  * Create new email address item.
@@ -270,7 +271,16 @@ void addritem_person_set_id( ItemPerson *person, const gchar *value ) {
  * \param value Name.
  */
 void addritem_person_set_first_name( ItemPerson *person, const gchar *value ) {
-       person->firstName = mgu_replace_string( person->firstName, value );
+       if (!value || g_utf8_validate(value, -1, NULL))
+               person->firstName = mgu_replace_string( person->firstName, value );
+       else {
+               gchar *out = conv_codeset_strdup(value, 
+                               conv_get_locale_charset_str_no_utf8(),
+                               CS_INTERNAL);
+               if (out)
+                       person->firstName = mgu_replace_string( person->firstName, out );
+               g_free(out);
+       }
 }
 
 /**
@@ -279,7 +289,16 @@ void addritem_person_set_first_name( ItemPerson *person, const gchar *value ) {
  * \param value name.
  */
 void addritem_person_set_last_name( ItemPerson *person, const gchar *value ) {
-       person->lastName = mgu_replace_string( person->lastName, value );
+       if (!value || g_utf8_validate(value, -1, NULL))
+               person->lastName = mgu_replace_string( person->lastName, value );
+       else {
+               gchar *out = conv_codeset_strdup(value, 
+                               conv_get_locale_charset_str_no_utf8(),
+                               CS_INTERNAL);
+               if (out)
+                       person->lastName = mgu_replace_string( person->lastName, out );
+               g_free(out);
+       }
 }
 
 /**
@@ -288,7 +307,16 @@ void addritem_person_set_last_name( ItemPerson *person, const gchar *value ) {
  * \param value name.
  */
 void addritem_person_set_nick_name( ItemPerson *person, const gchar *value ) {
-       person->nickName = mgu_replace_string( person->nickName, value );
+       if (!value || g_utf8_validate(value, -1, NULL))
+               person->nickName = mgu_replace_string( person->nickName, value );
+       else {
+               gchar *out = conv_codeset_strdup(value, 
+                               conv_get_locale_charset_str_no_utf8(),
+                               CS_INTERNAL);
+               if (out)
+                       person->nickName = mgu_replace_string( person->nickName, out );
+               g_free(out);
+       }
 }
 
 /**
@@ -297,7 +325,16 @@ void addritem_person_set_nick_name( ItemPerson *person, const gchar *value ) {
  * \param value name.
  */
 void addritem_person_set_common_name( ItemPerson *person, const gchar *value ) {
-       ADDRITEM_NAME(person) = mgu_replace_string( ADDRITEM_NAME(person), value );
+       if (!value || g_utf8_validate(value, -1, NULL))
+               ADDRITEM_NAME(person) = mgu_replace_string( ADDRITEM_NAME(person), value );
+       else {
+               gchar *out = conv_codeset_strdup(value, 
+                               conv_get_locale_charset_str_no_utf8(),
+                               CS_INTERNAL);
+               if (out)
+                       ADDRITEM_NAME(person) = mgu_replace_string( ADDRITEM_NAME(person), out );
+               g_free(out);
+       }
 }
 
 /**
@@ -1369,16 +1406,12 @@ void addritem_parse_first_last( ItemPerson *person ) {
                }
        }
 
-       if( person->firstName ) {
-               g_free( person->firstName );
-       }
+       g_free( person->firstName );
        person->firstName = fName;
        if( person->firstName )
                g_strstrip( person->firstName );
 
-       if( person->lastName ) {
-               g_free( person->lastName );
-       }
+       g_free( person->lastName );
        person->lastName = lName;
        if( person->lastName )
                g_strstrip( person->lastName );