aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-local.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-06-24 18:46:36 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-06-24 18:46:36 +0800
commit9ef14bd7eb341f176b4f8ce24b1679d5ef6aee2e (patch)
tree9a0073a840156f030936bde167fecf908e77f7c2 /mail/e-mail-local.c
parent174c942e0945a2017f0c479883dce2950e42e786 (diff)
downloadgsoc2013-evolution-9ef14bd7eb341f176b4f8ce24b1679d5ef6aee2e.tar
gsoc2013-evolution-9ef14bd7eb341f176b4f8ce24b1679d5ef6aee2e.tar.gz
gsoc2013-evolution-9ef14bd7eb341f176b4f8ce24b1679d5ef6aee2e.tar.bz2
gsoc2013-evolution-9ef14bd7eb341f176b4f8ce24b1679d5ef6aee2e.tar.lz
gsoc2013-evolution-9ef14bd7eb341f176b4f8ce24b1679d5ef6aee2e.tar.xz
gsoc2013-evolution-9ef14bd7eb341f176b4f8ce24b1679d5ef6aee2e.tar.zst
gsoc2013-evolution-9ef14bd7eb341f176b4f8ce24b1679d5ef6aee2e.zip
Forgot to add new files.
Diffstat (limited to 'mail/e-mail-local.c')
-rw-r--r--mail/e-mail-local.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/mail/e-mail-local.c b/mail/e-mail-local.c
new file mode 100644
index 0000000000..0944c7da95
--- /dev/null
+++ b/mail/e-mail-local.c
@@ -0,0 +1,130 @@
+/*
+ * e-mail-local.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/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#include "e-mail-local.h"
+
+#include <glib/gi18n.h>
+
+#include "mail/mail-session.h"
+
+#define CHECK_LOCAL_FOLDER_TYPE(type) \
+ ((type) < G_N_ELEMENTS (default_local_folders))
+
+/* The array elements correspond to EMailLocalFolder. */
+static struct {
+ const gchar *display_name;
+ CamelFolder *folder;
+ gchar *folder_uri;
+} default_local_folders[] = {
+ { N_("Inbox") },
+ { N_("Drafts") },
+ { N_("Outbox") },
+ { N_("Sent") },
+ { N_("Templates") },
+ { "Inbox" } /* "always local" inbox */
+};
+
+static CamelStore *local_store;
+
+void
+e_mail_local_init (const gchar *data_dir)
+{
+ static gboolean initialized = FALSE;
+ CamelException ex;
+ CamelService *service;
+ CamelURL *url;
+ gchar *temp;
+ gint ii;
+
+ g_return_if_fail (!initialized);
+ g_return_if_fail (data_dir != NULL);
+
+ camel_exception_init (&ex);
+
+ url = camel_url_new ("mbox:", NULL);
+ temp = g_build_filename (data_dir, "local", NULL);
+ camel_url_set_path (url, temp);
+ g_free (temp);
+
+ temp = camel_url_to_string (url, 0);
+ service = camel_session_get_service (
+ session, temp, CAMEL_PROVIDER_STORE, &ex);
+ g_free (temp);
+
+ if (camel_exception_is_set (&ex))
+ goto fail;
+
+ /* Populate the rest of the default_local_folders array. */
+ for (ii = 0; ii < G_N_ELEMENTS (default_local_folders); ii++) {
+ const gchar *display_name;
+ gchar *folder_uri;
+
+ display_name = default_local_folders[ii].display_name;
+
+ /* XXX Should this URI be account relative? */
+ camel_url_set_fragment (url, display_name);
+ folder_uri = camel_url_to_string (url, 0);
+
+ default_local_folders[ii].folder_uri = folder_uri;
+ default_local_folders[ii].folder = camel_store_get_folder (
+ CAMEL_STORE (service), display_name,
+ CAMEL_STORE_FOLDER_CREATE, &ex);
+
+ camel_exception_clear (&ex);
+ }
+
+ camel_url_free (url);
+
+ camel_object_ref (service);
+ local_store = CAMEL_STORE (service);
+
+ return;
+
+fail:
+ g_warning ("Could not initialize local store/folder: %s", ex.desc);
+
+ camel_exception_clear (&ex);
+ camel_url_free (url);
+}
+
+CamelFolder *
+e_mail_local_get_folder (EMailLocalFolder type)
+{
+ g_return_val_if_fail (CHECK_LOCAL_FOLDER_TYPE (type), NULL);
+
+ return default_local_folders[type].folder;
+}
+
+const gchar *
+e_mail_local_get_folder_uri (EMailLocalFolder type)
+{
+ g_return_val_if_fail (CHECK_LOCAL_FOLDER_TYPE (type), NULL);
+
+ return default_local_folders[type].folder_uri;
+}
+
+CamelStore *
+e_mail_local_get_store (void)
+{
+ g_return_val_if_fail (CAMEL_IS_STORE (local_store), NULL);
+
+ return local_store;
+}