+
+void
+modest_account_mgr_set_leave_on_server (ModestAccountMgr *self,
+ const gchar *account_name,
+ gboolean leave_on_server)
+{
+ modest_account_mgr_set_bool (self,
+ account_name,
+ MODEST_ACCOUNT_LEAVE_ON_SERVER,
+ leave_on_server,
+ FALSE);
+}
+
+gboolean
+modest_account_mgr_get_leave_on_server (ModestAccountMgr *self,
+ const gchar* account_name)
+{
+ return modest_account_mgr_get_bool (self,
+ account_name,
+ MODEST_ACCOUNT_LEAVE_ON_SERVER,
+ FALSE);
+}
+
+gint
+modest_account_mgr_get_last_updated (ModestAccountMgr *self,
+ const gchar* account_name)
+{
+ return modest_account_mgr_get_int (modest_runtime_get_account_mgr (),
+ account_name,
+ MODEST_ACCOUNT_LAST_UPDATED,
+ TRUE);
+}
+
+void
+modest_account_mgr_set_last_updated (ModestAccountMgr *self,
+ const gchar* account_name,
+ gint time)
+{
+ modest_account_mgr_set_int (self,
+ account_name,
+ MODEST_ACCOUNT_LAST_UPDATED,
+ time,
+ TRUE);
+
+ /* TODO: notify about changes */
+}
+
+gint
+modest_account_mgr_get_retrieve_limit (ModestAccountMgr *self,
+ const gchar* account_name)
+{
+ return modest_account_mgr_get_int (self,
+ account_name,
+ MODEST_ACCOUNT_LIMIT_RETRIEVE,
+ FALSE);
+}
+
+void
+modest_account_mgr_set_retrieve_limit (ModestAccountMgr *self,
+ const gchar* account_name,
+ gint limit_retrieve)
+{
+ modest_account_mgr_set_int (self,
+ account_name,
+ MODEST_ACCOUNT_LIMIT_RETRIEVE,
+ limit_retrieve,
+ FALSE /* not server account */);
+}
+
+gint
+modest_account_mgr_get_server_account_port (ModestAccountMgr *self,
+ const gchar* account_name)
+{
+ return modest_account_mgr_get_int (self,
+ account_name,
+ MODEST_ACCOUNT_PORT,
+ TRUE);
+}
+
+void
+modest_account_mgr_set_server_account_port (ModestAccountMgr *self,
+ const gchar *account_name,
+ gint port_num)
+{
+ modest_account_mgr_set_int (self,
+ account_name,
+ MODEST_ACCOUNT_PORT,
+ port_num, TRUE /* server account */);
+}
+
+gchar*
+modest_account_mgr_get_server_account_name (ModestAccountMgr *self,
+ const gchar *account_name,
+ TnyAccountType account_type)
+{
+ return modest_account_mgr_get_string (self,
+ account_name,
+ (account_type == TNY_ACCOUNT_TYPE_STORE) ?
+ MODEST_ACCOUNT_STORE_ACCOUNT :
+ MODEST_ACCOUNT_TRANSPORT_ACCOUNT,
+ FALSE);
+}
+
+static const gchar *
+get_retrieve_type_name (ModestAccountRetrieveType retrieve_type)
+{
+ switch(retrieve_type) {
+ case MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY:
+ return MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
+ break;
+ case MODEST_ACCOUNT_RETRIEVE_MESSAGES:
+ return MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES;
+ break;
+ case MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS:
+ return MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES_AND_ATTACHMENTS;
+ break;
+ default:
+ return MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
+ };
+}
+
+static ModestAccountRetrieveType
+get_retrieve_type (const gchar *name)
+{
+ if (!name || name[0] == 0)
+ return MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY;
+ if (strcmp (name, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES) == 0) {
+ return MODEST_ACCOUNT_RETRIEVE_MESSAGES;
+ } else if (strcmp (name, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES_AND_ATTACHMENTS) == 0) {
+ return MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS;
+ } else {
+ /* we fall back to headers only */
+ return MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY;
+ }
+}
+
+ModestAccountRetrieveType
+modest_account_mgr_get_retrieve_type (ModestAccountMgr *self,
+ const gchar *account_name)
+{
+ gchar *string;
+ ModestAccountRetrieveType result;
+
+ string = modest_account_mgr_get_string (self,
+ account_name,
+ MODEST_ACCOUNT_RETRIEVE,
+ FALSE /* not server account */);
+ result = get_retrieve_type (string);
+ g_free (string);
+
+ return result;
+}
+
+void
+modest_account_mgr_set_retrieve_type (ModestAccountMgr *self,
+ const gchar *account_name,
+ ModestAccountRetrieveType retrieve_type)
+{
+ modest_account_mgr_set_string (self,
+ account_name,
+ MODEST_ACCOUNT_RETRIEVE,
+ get_retrieve_type_name (retrieve_type),
+ FALSE /* not server account */);
+}
+
+
+void
+modest_account_mgr_set_user_fullname (ModestAccountMgr *self,
+ const gchar *account_name,
+ const gchar *fullname)
+{
+ modest_account_mgr_set_string (self,
+ account_name,
+ MODEST_ACCOUNT_FULLNAME,
+ fullname,
+ FALSE /* not server account */);
+}
+
+void
+modest_account_mgr_set_user_email (ModestAccountMgr *self,
+ const gchar *account_name,
+ const gchar *email)
+{
+ modest_account_mgr_set_string (self,
+ account_name,
+ MODEST_ACCOUNT_EMAIL,
+ email,
+ FALSE /* not server account */);
+}
+
+gboolean
+modest_account_mgr_account_is_multimailbox (ModestAccountMgr *mgr,
+ const gchar *account_name,
+ ModestProtocol **mmb_protocol)
+{
+ gchar *transport_account;
+ gboolean result = FALSE;
+
+ if (mmb_protocol)
+ *mmb_protocol = NULL;
+
+ transport_account = modest_account_mgr_get_server_account_name (mgr,
+ account_name,
+ TNY_ACCOUNT_TYPE_TRANSPORT);
+ if (transport_account) {
+ gchar *proto;
+ ModestProtocolRegistry *registry;
+
+ registry = modest_runtime_get_protocol_registry ();
+
+ proto = modest_account_mgr_get_string (mgr, transport_account,
+ MODEST_ACCOUNT_PROTO, TRUE);
+ if (proto != NULL) {
+ ModestProtocol *protocol =
+ modest_protocol_registry_get_protocol_by_name (registry,
+ MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS,
+ proto);
+ if (protocol &&
+ modest_protocol_registry_protocol_type_has_tag
+ (registry,
+ modest_protocol_get_type_id (protocol),
+ MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS)) {
+ if (mmb_protocol)
+ *mmb_protocol = protocol;
+ result = TRUE;
+ }
+
+ }
+ }
+
+ return result;
+}
+
+gchar *
+modest_account_mgr_get_signature_from_recipient (ModestAccountMgr *mgr,
+ const gchar *current_recipient,
+ gboolean *has_signature)
+{
+ gchar *result = NULL;
+ gchar *mailbox = NULL;
+ gchar *account_name;
+ ModestProtocol *protocol = NULL;
+
+ *has_signature = FALSE;
+
+ account_name = modest_utils_get_account_name_from_recipient (current_recipient, &mailbox);
+ if (modest_account_mgr_account_is_multimailbox (mgr, account_name, &protocol)) {
+ if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
+ result = modest_account_protocol_get_signature (MODEST_ACCOUNT_PROTOCOL (protocol),
+ account_name, mailbox,
+ has_signature);
+ }
+ }
+
+ if (result == NULL) {
+ result = modest_account_mgr_get_signature (mgr,
+ account_name, has_signature);
+ }
+ return result;
+}
+
+void
+modest_account_mgr_get_branding_from_recipient (ModestAccountMgr *mgr,
+ const gchar *current_recipient,
+ gchar **service_name,
+ const GdkPixbuf **service_icon,
+ guint64 icon_size)
+{
+ gchar *mailbox = NULL;
+ gchar *account_name;
+ ModestProtocol *protocol = NULL;
+
+ *service_name = NULL;
+ *service_icon = NULL;
+
+ account_name = modest_utils_get_account_name_from_recipient (current_recipient, &mailbox);
+ if (modest_account_mgr_account_is_multimailbox (mgr, account_name, &protocol)) {
+ if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
+ gchar *name;
+ const GdkPixbuf *icon;
+ name = modest_account_protocol_get_service_name (MODEST_ACCOUNT_PROTOCOL (protocol),
+ account_name, mailbox);
+ icon = modest_account_protocol_get_service_icon (MODEST_ACCOUNT_PROTOCOL (protocol),
+ account_name, mailbox, icon_size);
+ *service_name = name;
+ *service_icon = icon;
+ }
+ }
+
+}
+