2007-05-28 Murray Cumming <murrayc@murrayc.com>
[modest] / src / modest-tny-account.c
index c6617fb..fda4366 100644 (file)
@@ -65,13 +65,17 @@ modest_tny_account_get_special_folder (TnyAccount *account,
         
        /* Per-account outbox folders are each in their own on-disk directory: */
        if (special_type == TNY_FOLDER_TYPE_OUTBOX) {
+               const gchar *modest_account_name = 
+                       modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+               g_assert (modest_account_name);
+
                gchar *account_id = g_strdup_printf (
                        MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDER_ACCOUNT_ID_PREFIX "%s", 
-                       tny_account_get_id (account));
+                       modest_account_name);
                
-                       local_account = modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store(),
+               local_account = modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store(),
                                                                        account_id);
-                       g_free (account_id);
+               g_free (account_id);
        } else {
                /* Other local folders are all in one on-disk directory: */
                local_account = modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store(),
@@ -85,7 +89,9 @@ modest_tny_account_get_special_folder (TnyAccount *account,
 
        folders = TNY_LIST (tny_simple_list_new ());
 
-       /* no need to do this _async, as these are local folders */
+       /* There is no need to do this _async, as these are local folders. */
+       /* TODO: However, this seems to fail sometimes when the network is busy, 
+        * returning an empty list. murrayc. */
        tny_folder_store_get_folders (TNY_FOLDER_STORE (local_account),
                                      folders, NULL, NULL);
        iter = tny_list_create_iterator (folders);
@@ -205,9 +211,8 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
         * Note that this is not where we create the special local folders account.
         * We do that in modest_tny_account_new_for_local_folders() instead. */
        if (account_data->uri)  {
-               /* printf("DEBUG: %s: Using URI=%s\n", __FUNCTION__, account_data->uri); */
                tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
-               g_message ("%s: local account-url: %s", __FUNCTION__, account_data->uri);
+               g_message ("DEBUG: %s: local account-url:\n  %s", __FUNCTION__, account_data->uri);
        }
        else {
                /* Set camel-specific options: */
@@ -298,10 +303,19 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
 
        /* FIXME: for debugging */
        url = tny_account_get_url_string (TNY_ACCOUNT(tny_account));
-       g_message ("modest: account-url: %s", url);
+       g_message ("modest: %s:\n  account-url: %s", __FUNCTION__, url);
        g_free (url);
        /***********************/
        
+       /* For transport accounts, now is a good time to create the send queues, 
+        * so that the send queues start trying as soon as possible to send any 
+        * messages that are already in their outboxes: */
+       if ( (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SENDMAIL) ||
+            (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SMTP) ) {
+               /* modest_runtime_get_send_queue() instantiates and stores the send queue: */
+               modest_runtime_get_send_queue( TNY_TRANSPORT_ACCOUNT (tny_account));
+       }
+       
        return tny_account;
 }
 
@@ -404,7 +418,7 @@ modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySess
        url_string = camel_url_to_string (url, 0);
        
        tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
-       printf("DEBUG: %s: local folders url=%s\n", __FUNCTION__, url_string);
+       printf("DEBUG: %s:\n  url=%s\n", __FUNCTION__, url_string);
 
        tny_account_set_name (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME); 
        tny_account_set_id (TNY_ACCOUNT(tny_account), MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID); 
@@ -423,11 +437,10 @@ modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySess
 
 
 TnyAccount*
-modest_tny_account_new_for_per_account_local_outbox_folder (ModestAccountMgr *account_mgr, TnyAccount *account, TnySessionCamel *session)
+modest_tny_account_new_for_per_account_local_outbox_folder (ModestAccountMgr *account_mgr, const gchar* account_name, TnySessionCamel *session)
 {
        g_return_val_if_fail (account_mgr, NULL);
-       g_return_val_if_fail (account, NULL);
-       g_return_val_if_fail (tny_account_get_account_type (account) == TNY_ACCOUNT_TYPE_TRANSPORT, NULL);
+       g_return_val_if_fail (account_name, NULL);
        
        /* Notice that we create a ModestTnyOutboxAccount here, 
         * instead of just a TnyCamelStoreAccount,
@@ -443,14 +456,14 @@ modest_tny_account_new_for_per_account_local_outbox_folder (ModestAccountMgr *ac
        
        /* Make sure that the paths exists on-disk so that TnyCamelStoreAccount can 
         * find it to create a TnyFolder for it: */
-       gchar *folder_dir = modest_per_account_local_outbox_folder_info_get_maildir_path_to_outbox_folder (account); 
+       gchar *folder_dir = modest_per_account_local_outbox_folder_info_get_maildir_path_to_outbox_folder (account_name); 
        modest_init_one_local_folder(folder_dir);
        g_free (folder_dir);
        folder_dir = NULL;
 
        /* This path should contain just one directory - "outbox": */
        gchar *maildir = 
-               modest_per_account_local_outbox_folder_info_get_maildir_path (account);
+               modest_per_account_local_outbox_folder_info_get_maildir_path (account_name);
                        
        CamelURL *url = camel_url_new ("maildir:", NULL);
        camel_url_set_path (url, maildir);
@@ -462,7 +475,7 @@ modest_tny_account_new_for_per_account_local_outbox_folder (ModestAccountMgr *ac
        camel_url_free (url);
        
        tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
-       printf("DEBUG: %s: local outbox folder account url=%s\n", __FUNCTION__, url_string);
+       printf("DEBUG: %s:\n  url=%s\n", __FUNCTION__, url_string);
        g_free (url_string);
 
        /* This text should never been seen,
@@ -472,7 +485,7 @@ modest_tny_account_new_for_per_account_local_outbox_folder (ModestAccountMgr *ac
        
        gchar *account_id = g_strdup_printf (
                MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDER_ACCOUNT_ID_PREFIX "%s", 
-               tny_account_get_id (account));
+               account_name);
        tny_account_set_id (TNY_ACCOUNT(tny_account), account_id);
        g_free (account_id);
        
@@ -583,7 +596,7 @@ modest_tny_folder_store_get_local_size (TnyFolderStore *self)
        RecurseFoldersHelper *helper;
        gint retval;
 
-       g_return_val_if_fail (TNY_IS_ACCOUNT (self), -1);
+       g_return_val_if_fail (TNY_IS_FOLDER_STORE (self), -1);
 
        /* Create helper */
        helper = g_malloc0 (sizeof (RecurseFoldersHelper));