* account options should *not* include spaces... according to
[modest] / src / modest-tny-account.c
index d2a9f20..cd8df76 100644 (file)
@@ -110,10 +110,11 @@ modest_tny_account_get_special_folder (TnyAccount *account,
  * camel_sasl_authtype() seems to list some possible values.
  */
  
- /* Note that evolution does not offer this for IMAP: */
+/* Note that evolution does not offer these for IMAP: */
 #define MODEST_ACCOUNT_AUTH_PLAIN "PLAIN"
+#define MODEST_ACCOUNT_AUTH_ANONYMOUS "ANONYMOUS"
 
-/* IMAP uses NULL instead.
+/* Caeml's IMAP uses NULL instead for "Password".
  * Also, not that Evolution offers "Password" for IMAP, but "Login" for SMTP.*/
 #define MODEST_ACCOUNT_AUTH_PASSWORD "LOGIN" 
 #define MODEST_ACCOUNT_AUTH_CRAMMD5 "CRAM-MD5"
@@ -134,6 +135,8 @@ static TnyAccount*
 modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
                                            ModestServerAccountData *account_data)
 {      
+       gchar *url;
+
        g_return_val_if_fail (account_mgr, NULL);
        g_return_val_if_fail (account_data, NULL);
 
@@ -168,7 +171,8 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
        tny_account_set_id (tny_account, account_data->account_name);
 
        /* Proto */
-       const gchar* proto_name = modest_protocol_info_get_transport_store_protocol_name(account_data->proto);
+       const gchar* proto_name =
+               modest_protocol_info_get_transport_store_protocol_name(account_data->proto);
        tny_account_set_proto (tny_account, proto_name);
 
               
@@ -182,25 +186,23 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
                const gchar* option_security = NULL;
                switch (account_data->security) {
                case MODEST_PROTOCOL_CONNECTION_NORMAL:
-                       option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_NEVER;
+                       option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_NEVER;
                        break;
                case MODEST_PROTOCOL_CONNECTION_SSL:
                case MODEST_PROTOCOL_CONNECTION_TLS:
-                       option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_ALWAYS;;
+                       option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_ALWAYS;;
                        break;
                case MODEST_PROTOCOL_CONNECTION_TLS_OP:
-                       option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE;
+                       option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE;
                        break;
                default:
                        break;
                }
                
-               if(option_security) {
+               if(option_security)
                        tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
                                                      option_security);
-               }
                
-
                const gchar* auth_mech_name = NULL;
                switch (account_data->secure_auth) {
                case MODEST_PROTOCOL_AUTH_NONE:
@@ -209,6 +211,8 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
                         * This setting should never happen anyway. */
                        if (account_data->proto == MODEST_PROTOCOL_STORE_IMAP)
                                auth_mech_name = NULL;
+                       else if (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SMTP)
+                               auth_mech_name = MODEST_ACCOUNT_AUTH_ANONYMOUS;
                        else
                                auth_mech_name = MODEST_ACCOUNT_AUTH_PLAIN;
                        break;
@@ -224,25 +228,26 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
                        
                case MODEST_PROTOCOL_AUTH_CRAMMD5:
                        auth_mech_name = MODEST_ACCOUNT_AUTH_CRAMMD5;
+                       break;
                        
                default:
                        g_warning ("%s: Unhandled secure authentication setting %d for "
-                               "account=%s", __FUNCTION__, account_data->secure_auth, account_data->account_name);
+                               "account=%s (%s)", __FUNCTION__, account_data->secure_auth,
+                                  account_data->account_name, account_data->hostname);
                        break;
                }
                
-               if(auth_mech_name) {
+               if(auth_mech_name) 
                        tny_account_set_secure_auth_mech (tny_account, auth_mech_name);
-               }
                
                if (modest_protocol_info_protocol_is_store(account_data->proto)) {
                        /* Other connection options. Some options are only valid for IMAP
                           accounts but it's OK for just now since POP is still not
                           supported */
                        tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
-                                                                     MODEST_ACCOUNT_OPTION_USE_LSUB);
+                                                     MODEST_ACCOUNT_OPTION_USE_LSUB);
                        tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
-                                                                     MODEST_ACCOUNT_OPTION_CHECK_ALL);
+                                                     MODEST_ACCOUNT_OPTION_CHECK_ALL);
                }
                
                if (account_data->username) 
@@ -254,7 +259,12 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
                if (account_data->port)
                        tny_account_set_port (tny_account, account_data->port);
        }
-       
+
+       /* FIXME: for debugging */
+       url = tny_account_get_url_string (TNY_ACCOUNT(tny_account));
+       g_message ("modest: account-url: %s", url);
+       g_free (url);
+       /***********************/
        
        return tny_account;
 }
@@ -327,6 +337,7 @@ modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar
                                (gpointer*) g_strdup (account_name), g_free);
        
        modest_account_mgr_free_account_data (account_mgr, account_data);
+
        return tny_account;
 }
 
@@ -392,15 +403,15 @@ recurse_folders (TnyFolderStore *store,
 
        helper->folders += tny_list_get_length (folders);
 
-       while (!tny_iterator_is_done (iter))
-       {
+       while (!tny_iterator_is_done (iter)) {
                TnyFolderStats *stats;
                TnyFolder *folder;
 
                folder = TNY_FOLDER (tny_iterator_get_current (iter));
                stats = tny_folder_get_stats (folder);
 
-               if (helper->function)
+               /* initially, we sometimes get -1 from tinymail; ignore that */
+               if (helper->function && helper->function (stats) > 0)
                        helper->sum += helper->function (stats);
 
                recurse_folders (TNY_FOLDER_STORE (folder), query, helper);
@@ -443,7 +454,7 @@ modest_tny_account_get_message_count (TnyAccount *self)
        gint retval;
 
        g_return_val_if_fail (TNY_IS_ACCOUNT (self), -1);
-
+       
        /* Create helper */
        helper = g_malloc0 (sizeof (RecurseFoldersHelper));
        helper->function = (TnyStatsFunc) tny_folder_stats_get_all_count;