2005-11-07 [colin] 1.9.99cvs17
[claws.git] / src / addritem.c
index 8a9adbf1edc65194b3eececc53840416241a43e4..0c2c3df6b9021d62a08565cc8371e2c1839c44b6 100644 (file)
@@ -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.
  */
 
 /*
 #include <stdio.h>
 #include <string.h>
 
+#include "utils.h"
 #include "addritem.h"
 #include "mgutils.h"
+#include "codeconv.h"
 
 /**
  * Create new email address item.
@@ -269,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);
+       }
 }
 
 /**
@@ -278,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);
+       }
 }
 
 /**
@@ -287,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);
+       }
 }
 
 /**
@@ -296,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);
+       }
 }
 
 /**
@@ -845,6 +883,29 @@ ItemEMail *addritem_group_remove_email( ItemGroup *group, ItemEMail *email ) {
        return NULL;
 }
 
+/**
+ * Remove person object for specified group.
+ * \param  group Group from which to remove address.
+ * \param  email EMail to remove
+ * \return EMail object, or <i>NULL if email not found in group. Note that
+ *         this object is referenced (linked) to a group and should *NOT*
+ *         be freed. An E-Mail object object should only be freed after
+ *         removing from a person.
+ */
+ItemPerson *addritem_folder_remove_person( ItemFolder *group, ItemPerson *person ) {
+       if( group && person ) {
+               GList *node = group->listPerson;
+               while( node ) {
+                       if( node->data == person ) {
+                               group->listPerson = g_list_remove( group->listPerson, person );
+                               return person;
+                       }
+                       node = g_list_next( node );
+               }
+       }
+       return NULL;
+}
+
 /**
  * Remove email address of specified ID for specified group.
  * \param  group Group from which to remove address.