aboutsummaryrefslogtreecommitdiffstats
path: root/em-format/e-mail-part-list.c
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2012-06-06 21:27:19 +0800
committerDan Vrátil <dvratil@redhat.com>2012-06-06 21:27:19 +0800
commit5b8340563c271fb684a88c6e5bb6dd3bfb629058 (patch)
treec1c7d606fb4ce9fd2fe459a9226bfb9125423991 /em-format/e-mail-part-list.c
parent26a4f24188fd89dbabaff192bec9c54af8fe5a80 (diff)
downloadgsoc2013-evolution-5b8340563c271fb684a88c6e5bb6dd3bfb629058.tar
gsoc2013-evolution-5b8340563c271fb684a88c6e5bb6dd3bfb629058.tar.gz
gsoc2013-evolution-5b8340563c271fb684a88c6e5bb6dd3bfb629058.tar.bz2
gsoc2013-evolution-5b8340563c271fb684a88c6e5bb6dd3bfb629058.tar.lz
gsoc2013-evolution-5b8340563c271fb684a88c6e5bb6dd3bfb629058.tar.xz
gsoc2013-evolution-5b8340563c271fb684a88c6e5bb6dd3bfb629058.tar.zst
gsoc2013-evolution-5b8340563c271fb684a88c6e5bb6dd3bfb629058.zip
Mail formatter rewrite
All mail-parsing and formatting code has been moved to em-format. Parsing is handeled by EMailParser class, formatting by EMailFormatter. Both classes have registry which hold extensions - simple classes that do actual parsing and formatting. Each supported mime-type has it's own parser and formatter extension class.
Diffstat (limited to 'em-format/e-mail-part-list.c')
-rw-r--r--em-format/e-mail-part-list.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/em-format/e-mail-part-list.c b/em-format/e-mail-part-list.c
new file mode 100644
index 0000000000..743834beef
--- /dev/null
+++ b/em-format/e-mail-part-list.c
@@ -0,0 +1,130 @@
+/*
+ * e-mail-part-list.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include <camel/camel.h>
+
+#include "e-mail-part-list.h"
+
+G_DEFINE_TYPE (EMailPartList, e_mail_part_list, G_TYPE_OBJECT)
+
+static void
+unref_mail_part (gpointer user_data)
+{
+ if (user_data)
+ e_mail_part_unref (user_data);
+}
+
+static void
+e_mail_part_list_finalize (GObject *object)
+{
+ EMailPartList *part_list = E_MAIL_PART_LIST (object);
+
+ g_clear_object (&part_list->folder);
+ g_clear_object (&part_list->message);
+
+ if (part_list->list) {
+ g_slist_free_full (part_list->list, unref_mail_part);
+ part_list->list = NULL;
+ }
+
+ if (part_list->message_uid) {
+ g_free (part_list->message_uid);
+ part_list->message_uid = NULL;
+ }
+
+ G_OBJECT_CLASS (e_mail_part_list_parent_class)->finalize (object);
+}
+
+static void
+e_mail_part_list_class_init (EMailPartListClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = e_mail_part_list_finalize;
+}
+
+static void
+e_mail_part_list_init (EMailPartList *part_list)
+{
+
+}
+
+EMailPartList *
+e_mail_part_list_new ()
+{
+ return g_object_new (E_TYPE_MAIL_PART_LIST, NULL);
+}
+
+EMailPart *
+e_mail_part_list_find_part (EMailPartList *part_list,
+ const gchar *id)
+{
+ GSList *iter;
+ gboolean by_cid;
+
+ g_return_val_if_fail (E_IS_MAIL_PART_LIST (part_list), NULL);
+ g_return_val_if_fail (id && *id, NULL);
+
+ by_cid = (g_str_has_prefix (id, "cid:") || g_str_has_prefix (id, "CID:"));
+
+ for (iter = part_list->list; iter; iter = iter->next) {
+
+ EMailPart *part = iter->data;
+ if (!part)
+ continue;
+
+ if ((by_cid && (g_strcmp0 (part->cid, id) == 0)) ||
+ (!by_cid && (g_strcmp0 (part->id, id) == 0)))
+ return part;
+ }
+
+ return NULL;
+}
+
+/**
+ * e_mail_part_list_get_iter:
+ * @part_list: a #GSList of #EMailPart
+ * @id: id of #EMailPart to lookup
+ *
+ * Returns iter of an #EMailPart within the @part_list.
+ *
+ * Return Value: a #GSList sublist. The list is owned by #EMailPartList and
+ * must not be freed or altered.
+ */
+GSList *
+e_mail_part_list_get_iter (GSList *list,
+ const gchar *id)
+{
+ GSList *iter;
+
+ g_return_val_if_fail (list != NULL, NULL);
+ g_return_val_if_fail (id && *id, NULL);
+
+ for (iter = list; iter; iter = iter->next) {
+
+ EMailPart *part = iter->data;
+ if (!part)
+ continue;
+
+ if (g_strcmp0 (part->id, id) == 0)
+ return iter;
+ }
+
+ return NULL;
+}