aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-utils.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2004-01-27 20:35:26 +0800
committerMichael Zucci <zucchi@src.gnome.org>2004-01-27 20:35:26 +0800
commitce042b31b62f51282a3e66d1d0725fd5236d9096 (patch)
tree61c6c032f5d7fcdfb2ee7b7dd9cd96bd84e629ad /mail/em-utils.c
parent2cf803cfc656c511342b5d80f464fe590b3f5d9d (diff)
downloadgsoc2013-evolution-ce042b31b62f51282a3e66d1d0725fd5236d9096.tar
gsoc2013-evolution-ce042b31b62f51282a3e66d1d0725fd5236d9096.tar.gz
gsoc2013-evolution-ce042b31b62f51282a3e66d1d0725fd5236d9096.tar.bz2
gsoc2013-evolution-ce042b31b62f51282a3e66d1d0725fd5236d9096.tar.lz
gsoc2013-evolution-ce042b31b62f51282a3e66d1d0725fd5236d9096.tar.xz
gsoc2013-evolution-ce042b31b62f51282a3e66d1d0725fd5236d9096.tar.zst
gsoc2013-evolution-ce042b31b62f51282a3e66d1d0725fd5236d9096.zip
** See bug #53084 and others.
2004-01-27 Not Zed <NotZed@Ximian.com> ** See bug #53084 and others. * em-migrate.c (em_migrate): remove the vfolder_revert hack. * em-composer-utils.c (ask_confirm_for_only_bcc): removed unused vars. * mail-tools.c (mail_tool_get_local_inbox): removed, handled by mail_component_get_folder now. * mail-component.c (mail_component_*): Changed the api slightly. Using NULL as the component argument automatically implies you want the default component. (em_uri_from_camel, em_uri_to_camel): moved to em-utils.[ch]. Ok so it isn't namespaced right ... *shrug*. (mail_component_get_local_inbox): removed. (mail_component_get_folder): single entry point for getting standard folders. This is MT-Safe. (mail_component_get_folder_uri): single entry point for getting standard folder uri's. This is MT-Safe. (add_store): removed, moved to mail_component_add_store. (mail_component_load_store_by_uri): call mail_component_add_store directly rather than copying its code. (default_*_folder*): Removed, use accessor methods instead, fixed all callers. (setup_local_store): renamed to mc_setup_local_store, use proper url encoding too. make run-once and thread-safe. (MailComponentPrivate): Added a lock. (mail_control_new): exported properly to kill warnings. (mail_component_init): dont setup_local_store or add accounts here. (impl_createControls): setup local store/accounts here. (mail_component_peek): dont setup vfolder storage here. (mc_startup): internal function to startup stuff needed for gui operation. (setup_search_context): make run-once. (mail_component_peek_search_context): call setup_search_context incase it isn't setup yet. (impl_upgradeFromVersion): remove the local store setup hack. svn path=/trunk/; revision=24462
Diffstat (limited to 'mail/em-utils.c')
-rw-r--r--mail/em-utils.c136
1 files changed, 131 insertions, 5 deletions
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 016d99380a..dfce2bab15 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -55,6 +55,8 @@
static EAccount *guess_account (CamelMimeMessage *message, CamelFolder *folder);
static void emu_save_part_done (CamelMimePart *part, char *name, int done, void *data);
+#define d(x)
+
/**
* em_utils_prompt_user:
* @parent: parent window
@@ -2113,8 +2115,6 @@ em_utils_temp_save_part(GtkWidget *parent, CamelMimePart *part)
return path;
}
-extern CamelFolder *drafts_folder, *sent_folder, *outbox_folder;
-
/**
* em_utils_folder_is_drafts:
* @folder: folder
@@ -2132,7 +2132,7 @@ em_utils_folder_is_drafts(CamelFolder *folder, const char *uri)
EIterator *iter;
int is = FALSE;
- if (folder == drafts_folder)
+ if (folder == mail_component_get_folder(NULL, MAIL_COMPONENT_FOLDER_DRAFTS))
return TRUE;
if (uri == NULL)
@@ -2173,7 +2173,7 @@ em_utils_folder_is_sent(CamelFolder *folder, const char *uri)
EIterator *iter;
int is = FALSE;
- if (folder == sent_folder)
+ if (folder == mail_component_get_folder(NULL, MAIL_COMPONENT_FOLDER_SENT))
return TRUE;
if (uri == NULL)
@@ -2210,7 +2210,7 @@ gboolean
em_utils_folder_is_outbox(CamelFolder *folder, const char *uri)
{
/* <Highlander>There can be only one.</Highlander> */
- return folder == outbox_folder;
+ return folder == mail_component_get_folder(NULL, MAIL_COMPONENT_FOLDER_OUTBOX);
}
/**
@@ -2487,3 +2487,129 @@ em_utils_folder_name_from_uri (const char *uri)
return folder_name;
}
+
+extern struct _CamelSession *session;
+
+/* email: uri's are based on the account, with special cases for local
+ * stores, vfolder and local mail.
+ * e.g.
+ * imap account imap://user@host/ -> email://accountid@accountid.host/
+ * vfolder vfolder:/storage/path#folder -> email://vfolder@local/folder
+ * local local:/storage/path#folder -> email://local@local/folder
+ */
+
+char *em_uri_from_camel(const char *curi)
+{
+ CamelURL *curl;
+ EAccount *account;
+ const char *uid, *path;
+ char *euri, *tmp;
+ CamelProvider *provider;
+
+ provider = camel_session_get_provider(session, curi, NULL);
+ if (provider == NULL) {
+ d(printf("em uri from camel failed '%s'\n", curi));
+ return g_strdup(curi);
+ }
+
+ curl = camel_url_new(curi, NULL);
+ if (curl == NULL)
+ return g_strdup(curi);
+
+ if (strcmp(curl->protocol, "vfolder") == 0)
+ uid = "vfolder@local";
+ else if ((account = mail_config_get_account_by_source_url(curi)) == NULL)
+ uid = "local@local";
+ else
+ uid = account->uid;
+ path = (provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)?curl->fragment:curl->path;
+ if (path[0] == '/')
+ path++;
+
+ tmp = camel_url_encode(path, ";?");
+ euri = g_strdup_printf("email://%s/%s", uid, tmp);
+ g_free(tmp);
+
+ d(printf("em uri from camel '%s' -> '%s'\n", curi, euri));
+
+ camel_url_free(curl);
+
+ return euri;
+}
+
+char *em_uri_to_camel(const char *euri)
+{
+ EAccountList *accounts;
+ const EAccount *account;
+ EAccountService *service;
+ CamelProvider *provider;
+ CamelURL *eurl, *curl;
+ char *uid, *curi;
+
+ if (strncmp(euri, "email:", 6) != 0) {
+ d(printf("em uri to camel not euri '%s'\n", euri));
+ return g_strdup(euri);
+ }
+
+ eurl = camel_url_new(euri, NULL);
+ if (eurl == NULL)
+ return g_strdup(euri);
+
+ g_assert(eurl->host != NULL);
+
+ if (eurl->user != NULL) {
+ /* Sigh, shoul'dve used mbox@local for mailboxes, not local@local */
+ if (strcmp(eurl->host, "local") == 0
+ && (strcmp(eurl->user, "local") == 0 || strcmp(eurl->user, "vfolder") == 0)) {
+ char *base;
+
+ if (strcmp(eurl->user, "vfolder") == 0)
+ curl = camel_url_new("vfolder:", NULL);
+ else
+ curl = camel_url_new("mbox:", NULL);
+
+ base = g_strdup_printf("%s/.evolution/mail/%s", g_get_home_dir(), eurl->user);
+ camel_url_set_path(curl, base);
+ g_free(base);
+ camel_url_set_fragment(curl, eurl->path[0]=='/'?eurl->path+1:eurl->path);
+ curi = camel_url_to_string(curl, 0);
+ camel_url_free(curl);
+ camel_url_free(eurl);
+
+ d(printf("em uri to camel local '%s' -> '%s'\n", euri, curi));
+ return curi;
+ }
+
+ uid = g_strdup_printf("%s@%s", eurl->user, eurl->host);
+ } else {
+ uid = g_strdup(eurl->host);
+ }
+
+ accounts = mail_config_get_accounts();
+ account = e_account_list_find(accounts, E_ACCOUNT_FIND_UID, uid);
+ g_free(uid);
+
+ if (account == NULL) {
+ camel_url_free(eurl);
+ d(printf("em uri to camel no account '%s' -> '%s'\n", euri, euri));
+ return g_strdup(euri);
+ }
+
+ service = account->source;
+ provider = camel_session_get_provider(session, service->url, NULL);
+
+ curl = camel_url_new(service->url, NULL);
+ if (provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)
+ camel_url_set_fragment(curl, eurl->path[0]=='/'?eurl->path+1:eurl->path);
+ else
+ camel_url_set_path(curl, eurl->path);
+
+ curi = camel_url_to_string(curl, 0);
+
+ camel_url_free(eurl);
+ camel_url_free(curl);
+
+ d(printf("em uri to camel '%s' -> '%s'\n", euri, curi));
+
+ return curi;
+}