modest_init_local_folders (void)
{
int i;
- gchar *path;
+ gchar *maildir_path;
static const gchar* maildirs[] = {
"cur", "new", "tmp"
};
- path = g_build_filename (g_get_home_dir(), ".modest", NULL);
-
- if (g_access (path, W_OK) != 0) {
- g_printerr ("modest: cannot write into %s\n", path);
- g_free (path);
- return FALSE;
- }
+ maildir_path = modest_local_folder_info_get_maildir_path ();
for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
int j;
for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
gchar *dir;
- dir = g_build_filename (path, "local_folders",
+ dir = g_build_filename (maildir_path,
modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]),
maildirs[j],
NULL);
if (g_mkdir_with_parents (dir, 0755) < 0) {
g_printerr ("modest: failed to create %s\n", dir);
g_free (dir);
+ g_free (maildir_path);
return FALSE;
}
g_free(dir);
}
}
- g_free (path);
+ g_free (maildir_path);
return TRUE;
}
/*
* functions to initialize various parts of the modest system
*/
-
G_BEGIN_DECLS
/**
*/
gboolean modest_init_local_folders (void);
+
G_END_DECLS
#endif /*__MODEST_INIT_H__*/
}
+gchar *
+modest_local_folder_info_get_maildir_path (void)
+{
+ return g_build_filename (g_get_home_dir(), ".modest",
+ "local_folders", NULL);
+}
+
const gchar* modest_local_folder_info_get_type_name (ModestLocalFolderType type);
/**
- * modest_local_folder_get_type_display_name
+ * modest_local_folder_info_get_type_display_name
* @type: the type of the local folder
*
* get the localized display name for some local folder
const gchar* modest_local_folder_info_get_type_display_name (ModestLocalFolderType type);
+/**
+ * modest_local_folder_info_get_maildir_path
+ * @type: the type of the local folder
+ *
+ * get the path to the Maildir where the local folders are stored
+ *
+ * Returns: the local_folders Maildir path as a newly allocated
+ * string, which must be freed by the caller.
+ *
+ */
+gchar *modest_local_folder_info_get_maildir_path (void);
+
+
G_END_DECLS
#endif /* __MODEST_LOCAL_FOLDER_INFO_H__ */
#include <tny-camel-pop-store-account.h>
#include <modest-marshal.h>
#include <modest-protocol-info.h>
+#include <modest-local-folder-info.h>
#include "modest-account-mgr.h"
#include "modest-tny-account-store.h"
#include "modest-tny-platform-factory.h"
typedef struct _ModestTnyAccountStorePrivate ModestTnyAccountStorePrivate;
struct _ModestTnyAccountStorePrivate {
+
gchar *cache_dir;
+
GHashTable *password_hash;
TnyDevice *device;
TnyPlatformFactory *platform_fact;
MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
priv->cache_dir = NULL;
+
priv->platform_fact = NULL;
priv->tny_session_camel = NULL;
priv->device = NULL;
}
+/* create a pseudo-account for our local folders */
+static TnyAccount*
+get_local_folder_account (ModestTnyAccountStore *self)
+{
+ TnyStoreAccount *tny_account;
+ CamelURL *url;
+ gchar *maildir, *url_string;
+ ModestTnyAccountStorePrivate *priv;
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ tny_account = tny_camel_store_account_new ();
+ if (!tny_account) {
+ g_printerr ("modest: cannot create account for local folders");
+ return NULL;
+ }
+
+ maildir = modest_local_folder_info_get_maildir_path ();
+
+ url = camel_url_new ("maildir:", NULL);
+ camel_url_set_path (url, maildir);
+
+ url_string = camel_url_to_string (url, 0);
+ tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
+
+ tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account),
+ priv->tny_session_camel);
+
+ tny_account_set_name (TNY_ACCOUNT(tny_account), _("Local folders"));
+
+ camel_url_free (url);
+ g_free (maildir);
+ g_free (url_string);
+
+ return TNY_ACCOUNT(tny_account);
+}
+
+
static TnyAccount*
get_tny_account_from_account (ModestTnyAccountStore *self, ModestAccountData *account_data,
TnyGetAccountsRequestType type)
ModestTnyAccountStorePrivate *priv;
GSList *accounts, *cursor;
ModestAccountMgr *account_mgr;
+ TnyAccount *local_folder_account;
g_return_if_fail (iface);
g_return_if_fail (TNY_IS_LIST(list));
modest_account_mgr_free_account_data (account_mgr, account_data);
}
g_slist_free (accounts);
+
+ /* also, add the local folder pseudo-account */
+ local_folder_account = get_local_folder_account (MODEST_TNY_ACCOUNT_STORE(self));
+ if (!local_folder_account)
+ g_printerr ("modest: failed to add local folders account\n");
+ else
+ tny_list_prepend (list, G_OBJECT(local_folder_account));
+
tny_session_camel_set_account_store (priv->tny_session_camel, iface);
}
modest_tny_account_store_set_get_pass_func (ModestTnyAccountStore *self,
ModestTnyGetPassFunc func)
{
- g_warning (__FUNCTION__);
+ g_message (__FUNCTION__);
return; /* not implemented, we use signals */
}
+
TnySessionCamel*
tny_account_store_get_session (TnyAccountStore *self)
{
*/
ModestTnyAccountStore* modest_tny_account_store_new (ModestAccountMgr *account_mgr);
-
/**
* tny_account_store_get_session
* @self: a TnyAccountStore instance
#include <modest-tny-folder.h>
-typedef struct {
- ModestLocalFolderType type;
- const gchar *name;
- const gchar *display_name;
-} ModestLocalFolder;
-
-const ModestLocalFolder ModestLocalFolderMap[] = {
- { MODEST_LOCAL_FOLDER_TYPE_JUNK, "junk", N_("junk")},
- { MODEST_LOCAL_FOLDER_TYPE_TRASH, "trash", N_("trash")},
- { MODEST_LOCAL_FOLDER_TYPE_DRAFTS, "drafts", N_("drafts")},
- { MODEST_LOCAL_FOLDER_TYPE_SENT, "sent", N_("sent")},
- { MODEST_LOCAL_FOLDER_TYPE_OUTBOX, "outbox", N_("outbox")},
- { MODEST_LOCAL_FOLDER_TYPE_ARCHIVE, "archive", N_("archive")}
-};
-
-
-ModestLocalFolderType
-modest_tny_folder_get_local_folder_type (const gchar *name)
-{
- int i;
-
- g_return_val_if_fail (name, MODEST_LOCAL_FOLDER_TYPE_UNKNOWN);
-
- for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
- if (strcmp (ModestLocalFolderMap[i].name, name) == 0)
- return ModestLocalFolderMap[i].type;
- }
- return MODEST_LOCAL_FOLDER_TYPE_UNKNOWN;
-}
-
-const gchar*
-modest_tny_folder_get_local_folder_type_name (ModestLocalFolderType type)
-{
- int i = 0;
- g_return_val_if_fail (type > MODEST_LOCAL_FOLDER_TYPE_UNKNOWN &&
- type < MODEST_LOCAL_FOLDER_TYPE_NUM, NULL);
-
- for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
- if (ModestLocalFolderMap[i].type == type)
- return ModestLocalFolderMap[i].name;
- }
- return NULL;
-}
-
-
-const gchar*
-modest_tny_folder_get_local_folder_type_display_name (ModestLocalFolderType type)
-{
- int i = 0;
- g_return_val_if_fail (type > MODEST_LOCAL_FOLDER_TYPE_UNKNOWN &&
- type < MODEST_LOCAL_FOLDER_TYPE_NUM, NULL);
-
- for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
- if (ModestLocalFolderMap[i].type == type)
- return ModestLocalFolderMap[i].display_name;
- }
- return NULL;
-}
-
-
-
-
TnyFolderType
modest_tny_folder_guess_folder_type_from_name (const gchar* name)
{
MODEST_FOLDER_RULES_FOLDER_DELETABLE
} ModestTnyFolderRules;
-typedef enum {
- MODEST_LOCAL_FOLDER_TYPE_UNKNOWN,
-
- MODEST_LOCAL_FOLDER_TYPE_DRAFTS,
- MODEST_LOCAL_FOLDER_TYPE_SENT,
- MODEST_LOCAL_FOLDER_TYPE_OUTBOX,
- MODEST_LOCAL_FOLDER_TYPE_ARCHIVE,
- MODEST_LOCAL_FOLDER_TYPE_JUNK,
- MODEST_LOCAL_FOLDER_TYPE_TRASH,
-
- MODEST_LOCAL_FOLDER_TYPE_NUM
-} ModestLocalFolderType;
-
-
/**
* modest_tny_folder_guess_type:
* @folder: a valid tnymail folder
*/
ModestTnyFolderRules modest_tny_folder_get_rules (const TnyFolder *folder);
-
-/* some class-function (ie. don't require TnyFolder* */
-ModestLocalFolderType modest_tny_folder_get_local_folder_type (const gchar *name);
-const gchar* modest_tny_folder_get_local_folder_type_name (ModestLocalFolderType type);
-const gchar* modest_tny_folder_get_local_folder_type_display_name (ModestLocalFolderType type);
-
-
-
G_END_DECLS
#endif /* __MODEST_TNY_FOLDER_H__*/
**/
ModestMailOperationQueue* modest_tny_platform_factory_get_mail_operation_queue_instance (ModestTnyPlatformFactory *fact);
+
G_END_DECLS
#endif /* __MODEST_TNY_PLATFORM_FACTORY_H__ */