/*
* 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
*
* 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.
*/
/*
#include "utils.h"
#include "addritem.h"
#include "mgutils.h"
+#include "codeconv.h"
/**
* Create new email address item.
* \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);
+ }
}
/**
* \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);
+ }
}
/**
* \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);
+ }
}
/**
* \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);
+ }
}
/**
}
}
- 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 );