#endif
}
+GSList
+*solipa_mail_get_addresses_from_string (const gchar *addresses)
+{
+ GSList *lst_ret;
+
+ gchar *_addrs;
+
+ gchar **addrs_parts;
+ gchar **addr_parts;
+ gchar *addr;
+ guint n_addrs_parts;
+ guint n_addr_parts;
+ guint i;
+
+ GHashTable *ht;
+
+ g_return_val_if_fail (addresses != NULL, NULL);
+
+ _addrs = g_strstrip (g_strdup (addresses));
+
+ g_return_val_if_fail (g_strcmp0 (_addrs, "") != 0, NULL);
+
+ lst_ret = NULL;
+
+ addrs_parts = g_strsplit_set (_addrs, ",;", -1);
+ n_addrs_parts = g_strv_length (addrs_parts);
+ for (i = 0; i < n_addrs_parts; i++)
+ {
+ addr_parts = g_strsplit_set (addrs_parts[i], "<>", -1);
+ n_addr_parts = g_strv_length (addr_parts);
+ if (n_addr_parts > 0)
+ {
+ ht = g_hash_table_new (g_str_hash, g_str_equal);
+ if (n_addr_parts == 1 || n_addr_parts == 2)
+ {
+ /* TODO test address */
+ addr = g_strstrip (g_strjoinv (NULL, g_strsplit_set (addr_parts[0], "<>", -1)));
+ g_hash_table_insert (ht, "address", addr);
+ }
+ else if (n_addr_parts == 3)
+ {
+ g_hash_table_insert (ht, "name", g_strstrip (g_strjoinv (NULL, g_strsplit (addr_parts[0], "\"", -1))));
+ /* TODO test address */
+ addr = g_strstrip (g_strjoinv (NULL, g_strsplit_set (addr_parts[1], "<>", -1)));
+ g_hash_table_insert (ht, "address", addr);
+ }
+ lst_ret = g_slist_append (lst_ret, (gpointer)ht);
+ }
+ }
+
+ g_strfreev (addrs_parts);
+
+ return lst_ret;
+}
+
/* PRIVATE */
static void
solipa_mail_set_property (GObject *object,
/*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
void solipa_mail_send (SolipaMail *mail, const gchar *url);
+GSList *solipa_mail_get_addresses_from_string (const gchar *addresses);
+
G_END_DECLS
--- /dev/null
+/*
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ */
+
+#include <mail.h>
+
+int
+main (int argc, char **argv)
+{
+ GSList *lst;
+ GHashTable *ht;
+ gchar *name;
+ gchar *address;
+
+ g_type_init ();
+
+ if (argc != 2) return 0;
+
+ lst = solipa_mail_get_addresses_from_string (argv[1]);
+
+ while (lst != NULL)
+ {
+ ht = (GHashTable *)lst->data;
+ name = g_hash_table_lookup (ht, "name");
+ address = g_hash_table_lookup (ht, "address");
+
+ g_message ("%s: name %s address %s",
+ argv[1],
+ name,
+ address);
+
+ lst = g_slist_next (lst);
+ }
+
+ return 0;
+}