1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <modest-tny-platform-factory.h>
31 #include <modest-tny-account.h>
32 #include <modest-tny-account-store.h>
33 #include <modest-tny-local-folders-account.h>
34 #include <modest-runtime.h>
35 #include <tny-simple-list.h>
36 #include <modest-tny-folder.h>
37 #include <modest-tny-outbox-account.h>
38 #include <modest-account-mgr-helpers.h>
39 #include <modest-init.h>
40 #include <tny-camel-transport-account.h>
41 #include <tny-camel-imap-store-account.h>
42 #include <tny-camel-pop-store-account.h>
43 #include <tny-folder-stats.h>
45 #ifdef MODEST_HILDON_VERSION_0
46 #include <hildon-widgets/hildon-file-system-info.h>
48 #include <hildon/hildon-file-system-info.h>
52 modest_tny_account_get_special_folder (TnyAccount *account,
53 TnyFolderType special_type)
57 TnyFolder *special_folder = NULL;
60 g_return_val_if_fail (account, NULL);
61 g_return_val_if_fail (0 <= special_type && special_type < TNY_FOLDER_TYPE_NUM,
64 TnyAccount *local_account = NULL;
66 /* The accounts have already been instantiated by
67 * modest_tny_account_store_get_accounts(), which is the
68 * TnyAccountStore::get_accounts_func() implementation,
69 * so we just get them here.
72 /* Per-account outbox folders are each in their own on-disk directory: */
73 if (special_type == TNY_FOLDER_TYPE_OUTBOX) {
74 const gchar *modest_account_name =
75 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
76 g_assert (modest_account_name);
78 gchar *account_id = g_strdup_printf (
79 MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDER_ACCOUNT_ID_PREFIX "%s",
82 local_account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
83 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
87 /* Other local folders are all in one on-disk directory: */
88 local_account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
89 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
90 MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
94 g_printerr ("modest: cannot get local account\n");
98 folders = TNY_LIST (tny_simple_list_new ());
100 /* There is no need to do this _async, as these are local folders. */
101 /* TODO: However, this seems to fail sometimes when the network is busy,
102 * returning an empty list. murrayc. */
103 tny_folder_store_get_folders (TNY_FOLDER_STORE (local_account),
104 folders, NULL, NULL);
105 iter = tny_list_create_iterator (folders);
107 while (!tny_iterator_is_done (iter)) {
109 TNY_FOLDER (tny_iterator_get_current (iter));
110 if (modest_tny_folder_get_local_folder_type (folder) == special_type) {
111 special_folder = folder;
115 g_object_unref (G_OBJECT(folder));
116 tny_iterator_next (iter);
119 g_object_unref (G_OBJECT (folders));
120 g_object_unref (G_OBJECT (iter));
121 g_object_unref (G_OBJECT (local_account));
123 return special_folder;
128 /* These seem to be listed in
129 * libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c
131 #define MODEST_ACCOUNT_OPTION_SSL "use_ssl"
132 #define MODEST_ACCOUNT_OPTION_SSL_NEVER "never"
133 /* This is a tinymail camel-lite specific option,
134 * roughly equivalent to "always" in regular camel,
135 * which is appropriate for a generic "SSL" connection option: */
136 #define MODEST_ACCOUNT_OPTION_SSL_WRAPPED "wrapped"
137 /* Not used in our UI so far: */
138 #define MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE "when-possible"
139 /* This is a tinymailcamel-lite specific option that is not in regular camel. */
140 #define MODEST_ACCOUNT_OPTION_SSL_TLS "tls"
142 /* These seem to be listed in
143 * libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-provider.c
145 #define MODEST_ACCOUNT_OPTION_USE_LSUB "use_lsub" /* Show only subscribed folders */
146 #define MODEST_ACCOUNT_OPTION_CHECK_ALL "check_all" /* Check for new messages in all folders */
149 /* Posssible values for tny_account_set_secure_auth_mech().
150 * These might be camel-specific.
151 * Really, tinymail should use an enum.
152 * camel_sasl_authtype() seems to list some possible values.
155 /* Note that evolution does not offer these for IMAP: */
156 #define MODEST_ACCOUNT_AUTH_PLAIN "PLAIN"
157 #define MODEST_ACCOUNT_AUTH_ANONYMOUS "ANONYMOUS"
159 /* Caeml's IMAP uses NULL instead for "Password".
160 * Also, not that Evolution offers "Password" for IMAP, but "Login" for SMTP.*/
161 #define MODEST_ACCOUNT_AUTH_PASSWORD "LOGIN"
162 #define MODEST_ACCOUNT_AUTH_CRAMMD5 "CRAM-MD5"
167 * modest_tny_account_new_from_server_account:
168 * @account_mgr: a valid account mgr instance
169 * @account_name: the server account name for which to create a corresponding tny account
170 * @type: the type of account to create (TNY_ACCOUNT_TYPE_STORE or TNY_ACCOUNT_TYPE_TRANSPORT)
172 * get a tnyaccount corresponding to the server_accounts (store or transport) for this account.
173 * NOTE: this function does not set the camel session or the get/forget password functions
175 * Returns: a new TnyAccount or NULL in case of error.
178 modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
179 ModestServerAccountData *account_data)
183 g_return_val_if_fail (account_mgr, NULL);
184 g_return_val_if_fail (account_data, NULL);
187 if (account_data->proto == MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN) {
188 g_printerr ("modest: '%s' does not provide a protocol\n",
189 account_data->account_name);
193 TnyAccount *tny_account = NULL;
195 switch (account_data->proto) {
196 case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
197 case MODEST_PROTOCOL_TRANSPORT_SMTP:
198 tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ()); break;
199 case MODEST_PROTOCOL_STORE_POP:
200 tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ()); break;
201 case MODEST_PROTOCOL_STORE_IMAP:
202 tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ()); break;
203 case MODEST_PROTOCOL_STORE_MAILDIR:
204 case MODEST_PROTOCOL_STORE_MBOX:
205 /* Note that this is not where we create the special local folders account.
206 * That happens in modest_tny_account_new_for_local_folders() instead.
208 tny_account = TNY_ACCOUNT(tny_camel_store_account_new()); break;
210 g_return_val_if_reached (NULL);
213 g_printerr ("modest: could not create tny account for '%s'\n",
214 account_data->account_name);
217 tny_account_set_id (tny_account, account_data->account_name);
220 const gchar* proto_name =
221 modest_protocol_info_get_transport_store_protocol_name(account_data->proto);
222 tny_account_set_proto (tny_account, proto_name);
225 /* mbox and maildir accounts use a URI instead of the rest:
226 * Note that this is not where we create the special local folders account.
227 * We do that in modest_tny_account_new_for_local_folders() instead. */
228 if (account_data->uri) {
229 tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
230 /* g_message ("DEBUG: %s: local account-url:\n %s", __FUNCTION__, account_data->uri); */
233 /* Set camel-specific options: */
235 /* Enable secure connection settings: */
236 /* printf("DEBUG: %s: security=%d\n", __FUNCTION__, account_data->security); */
237 const gchar* option_security = NULL;
238 switch (account_data->security) {
239 case MODEST_PROTOCOL_CONNECTION_NORMAL:
240 option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_NEVER;
242 case MODEST_PROTOCOL_CONNECTION_SSL:
243 /* Apparently, use of "IMAPS" (specified in our UI spec), implies
244 * use of the "wrapped" option: */
245 option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_WRAPPED;
247 case MODEST_PROTOCOL_CONNECTION_TLS:
248 option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_TLS;
250 case MODEST_PROTOCOL_CONNECTION_TLS_OP:
251 /* This is not actually in our UI: */
252 option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE;
259 tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
262 /* Secure authentication: */
263 /* printf("DEBUG: %s: secure-auth=%d\n", __FUNCTION__, account_data->secure_auth); */
264 const gchar* auth_mech_name = NULL;
265 switch (account_data->secure_auth) {
266 case MODEST_PROTOCOL_AUTH_NONE:
267 /* IMAP and POP need at least a password,
268 * which camel uses if we specify NULL.
269 * This setting should never happen anyway. */
270 if (account_data->proto == MODEST_PROTOCOL_STORE_IMAP ||
271 account_data->proto == MODEST_PROTOCOL_STORE_POP)
272 auth_mech_name = NULL;
273 else if (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SMTP)
274 auth_mech_name = MODEST_ACCOUNT_AUTH_ANONYMOUS;
276 auth_mech_name = MODEST_ACCOUNT_AUTH_PLAIN;
279 case MODEST_PROTOCOL_AUTH_PASSWORD:
280 /* Camel use a password for IMAP or POP if we specify NULL,
281 * For IMAP, at least it will report an error if we use "Password", "Login" or "Plain".
282 * (POP is know to report an error for Login too. Probably Password and Plain too.) */
283 if (account_data->proto == MODEST_PROTOCOL_STORE_IMAP)
284 auth_mech_name = NULL;
285 else if (account_data->proto == MODEST_PROTOCOL_STORE_POP)
286 auth_mech_name = NULL;
288 auth_mech_name = MODEST_ACCOUNT_AUTH_PASSWORD;
291 case MODEST_PROTOCOL_AUTH_CRAMMD5:
292 auth_mech_name = MODEST_ACCOUNT_AUTH_CRAMMD5;
296 g_warning ("%s: Unhandled secure authentication setting %d for "
297 "account=%s (%s)", __FUNCTION__, account_data->secure_auth,
298 account_data->account_name, account_data->hostname);
303 tny_account_set_secure_auth_mech (tny_account, auth_mech_name);
305 if (modest_protocol_info_protocol_is_store(account_data->proto) &&
306 (account_data->proto == MODEST_PROTOCOL_STORE_IMAP) ) {
307 /* Other connection options, needed for IMAP. */
308 tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
309 MODEST_ACCOUNT_OPTION_USE_LSUB);
310 tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
311 MODEST_ACCOUNT_OPTION_CHECK_ALL);
314 if (account_data->username)
315 tny_account_set_user (tny_account, account_data->username);
316 if (account_data->hostname)
317 tny_account_set_hostname (tny_account, account_data->hostname);
320 if (account_data->port)
321 tny_account_set_port (tny_account, account_data->port);
324 /* FIXME: for debugging.
325 * Let's keep this because it is very useful for debugging. */
326 url = tny_account_get_url_string (TNY_ACCOUNT(tny_account));
327 printf ("DEBUG %s:\n account-url: %s\n", __FUNCTION__, url);
329 /***********************/
335 modest_tny_account_new_from_server_account_name (ModestAccountMgr *account_mgr,
336 const gchar *server_account_name)
338 ModestServerAccountData *account_data =
339 modest_account_mgr_get_server_account_data (account_mgr,
340 server_account_name);
344 TnyAccount *result = modest_tny_account_new_from_server_account (
345 account_mgr, account_data);
347 modest_account_mgr_free_server_account_data (account_mgr, account_data);
353 /* we need these dummy functions, or tinymail will complain */
355 get_pass_dummy (TnyAccount *account, const gchar *prompt, gboolean *cancel)
360 forget_pass_dummy (TnyAccount *account)
362 /* intentionally left blank */
366 modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar *account_name,
368 TnySessionCamel *session,
369 TnyGetPassFunc get_pass_func,
370 TnyForgetPassFunc forget_pass_func)
372 TnyAccount *tny_account = NULL;
373 ModestAccountData *account_data = NULL;
374 ModestServerAccountData *server_data = NULL;
376 g_return_val_if_fail (account_mgr, NULL);
377 g_return_val_if_fail (account_name, NULL);
379 account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
381 g_printerr ("modest: %s: cannot get account data for account %s\n", __FUNCTION__, account_name);
385 if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account)
386 server_data = account_data->store_account;
387 else if (type == TNY_ACCOUNT_TYPE_TRANSPORT && account_data->transport_account)
388 server_data = account_data->transport_account;
390 g_printerr ("modest: no %s account defined for '%s'\n",
391 type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport",
392 account_data->display_name);
393 modest_account_mgr_free_account_data (account_mgr, account_data);
397 tny_account = modest_tny_account_new_from_server_account (account_mgr, server_data);
399 g_printerr ("modest: failed to create tny account for %s (%s)\n",
400 account_data->account_name, server_data->account_name);
401 modest_account_mgr_free_account_data (account_mgr, account_data);
405 tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
406 tny_account_set_forget_pass_func (tny_account,
407 forget_pass_func ? forget_pass_func : forget_pass_dummy);
408 tny_account_set_pass_func (tny_account,
409 get_pass_func ? get_pass_func: get_pass_dummy);
411 /* This name is what shows up in the folder view -- so for some POP/IMAP/... server
412 * account, we set its name to the account of which it is part. */
413 if (account_data->display_name)
414 tny_account_set_name (tny_account, account_data->display_name);
416 modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account, account_name);
418 modest_account_mgr_free_account_data (account_mgr, account_data);
423 /* TODO: Notify the treemodel somehow that the display name
424 * is now available. We should probably request this from the cell_data_func
425 * so we can provide a treerowreference. */
427 on_modest_file_system_info(HildonFileSystemInfoHandle *handle,
428 HildonFileSystemInfo *info,
429 const GError *error, gpointer data)
431 TnyAccount *account = TNY_ACCOUNT (data);
434 /* printf (" DEBUG: %s: error=%s\n", __FUNCTION__, error->message); */
437 const gchar *display_name = NULL;
438 if (!error && info) {
439 display_name = hildon_file_system_info_get_display_name(info);
443 /* printf ("DEBUG: %s: display name=%s\n", __FUNCTION__, display_name); */
444 tny_account_set_name (account, display_name);
450 modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySessionCamel *session, const gchar* location_filepath)
452 /* Make sure that the directories exist: */
453 modest_init_local_folders (location_filepath);
455 TnyStoreAccount *tny_account;
457 gchar *maildir, *url_string;
459 g_return_val_if_fail (account_mgr, NULL);
461 if (!location_filepath) {
462 /* A NULL filepath means that this is the special local-folders maildir
464 tny_account = TNY_STORE_ACCOUNT (modest_tny_local_folders_account_new ());
467 /* Else, for instance, a per-account outbox maildir account: */
468 tny_account = TNY_STORE_ACCOUNT (tny_camel_store_account_new ());
472 g_printerr ("modest: %s: cannot create account for local folders. filepath=%s",
473 __FUNCTION__, location_filepath);
476 tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
478 /* This path contains directories for each local folder.
479 * We have created them so that TnyCamelStoreAccount can find them
480 * and report a folder for each directory: */
481 maildir = modest_local_folder_info_get_maildir_path (location_filepath);
482 url = camel_url_new ("maildir:", NULL);
483 camel_url_set_path (url, maildir);
484 /* Needed by tinymail's DBC assertions */
485 camel_url_set_host (url, "localhost");
486 url_string = camel_url_to_string (url, 0);
488 tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
489 /* printf("DEBUG: %s:\n url=%s\n", __FUNCTION__, url_string); */
491 /* TODO: Use a more generic way of identifying memory card paths,
492 * and of marking accounts as memory card accounts, maybe
493 * via a derived TnyCamelStoreAccount ? */
494 const gboolean is_mmc =
496 (strcmp (location_filepath, MODEST_MCC1_VOLUMEPATH) == 0);
498 /* The name of memory card locations will be updated asynchronously.
499 * This is just a default: */
500 const gchar *name = is_mmc ? _("Memory Card") :
501 MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME;
502 tny_account_set_name (TNY_ACCOUNT(tny_account), name);
504 /* Get the correct display name for memory cards, asynchronously: */
505 if (location_filepath) {
506 GError *error = NULL;
507 gchar *uri = g_filename_to_uri(location_filepath, NULL, &error);
509 g_warning ("%s: g_filename_to_uri(%s) failed: %s", __FUNCTION__,
510 location_filepath, error->message);
511 g_error_free (error);
514 /* TODO: gnome_vfs_volume_get_display_name() does not return
515 * the same string. But why not? Why does hildon needs its own
518 hildon_file_system_info_async_new(uri,
519 on_modest_file_system_info, tny_account /* user_data */);
527 const gchar* id = is_mmc ? MODEST_MMC_ACCOUNT_ID :
528 MODEST_LOCAL_FOLDERS_ACCOUNT_ID;
529 tny_account_set_id (TNY_ACCOUNT(tny_account), id);
531 tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
532 tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_pass_dummy);
534 modest_tny_account_set_parent_modest_account_name_for_server_account (
535 TNY_ACCOUNT (tny_account), id);
537 camel_url_free (url);
541 return TNY_ACCOUNT(tny_account);
546 modest_tny_account_new_for_per_account_local_outbox_folder (ModestAccountMgr *account_mgr, const gchar* account_name, TnySessionCamel *session)
548 g_return_val_if_fail (account_mgr, NULL);
549 g_return_val_if_fail (account_name, NULL);
551 /* Notice that we create a ModestTnyOutboxAccount here,
552 * instead of just a TnyCamelStoreAccount,
553 * so that we can later identify this as a special account for internal use only.
555 TnyStoreAccount *tny_account = TNY_STORE_ACCOUNT (modest_tny_outbox_account_new ());
557 g_printerr ("modest: cannot create account for per-account local outbox folder.");
561 tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
563 /* Make sure that the paths exists on-disk so that TnyCamelStoreAccount can
564 * find it to create a TnyFolder for it: */
565 gchar *folder_dir = modest_per_account_local_outbox_folder_info_get_maildir_path_to_outbox_folder (account_name);
566 modest_init_one_local_folder(folder_dir);
570 /* This path should contain just one directory - "outbox": */
572 modest_per_account_local_outbox_folder_info_get_maildir_path (account_name);
574 CamelURL *url = camel_url_new ("maildir:", NULL);
575 camel_url_set_path (url, maildir);
578 /* Needed by tinymail's DBC assertions */
579 camel_url_set_host (url, "localhost");
580 gchar *url_string = camel_url_to_string (url, 0);
581 camel_url_free (url);
583 tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
584 /* printf("DEBUG: %s:\n url=%s\n", __FUNCTION__, url_string); */
587 /* This text should never been seen,
588 * because the per-account outbox accounts are not seen directly by the user.
589 * Their folders are merged and shown as one folder. */
590 tny_account_set_name (TNY_ACCOUNT(tny_account), "Per-Account Outbox");
592 gchar *account_id = g_strdup_printf (
593 MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDER_ACCOUNT_ID_PREFIX "%s",
595 tny_account_set_id (TNY_ACCOUNT(tny_account), account_id);
598 tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
599 tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_pass_dummy);
601 /* Make this think that it belongs to the modest local-folders parent account: */
602 modest_tny_account_set_parent_modest_account_name_for_server_account (
603 TNY_ACCOUNT (tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
605 return TNY_ACCOUNT(tny_account);
610 typedef gint (*TnyStatsFunc) (TnyFolderStats *stats);
612 typedef struct _RecurseFoldersHelper {
613 TnyStatsFunc function;
616 } RecurseFoldersHelper;
619 recurse_folders (TnyFolderStore *store,
620 TnyFolderStoreQuery *query,
621 RecurseFoldersHelper *helper)
624 TnyList *folders = tny_simple_list_new ();
626 tny_folder_store_get_folders (store, folders, query, NULL);
627 iter = tny_list_create_iterator (folders);
629 helper->folders += tny_list_get_length (folders);
631 while (!tny_iterator_is_done (iter)) {
632 TnyFolderStats *stats;
635 folder = TNY_FOLDER (tny_iterator_get_current (iter));
636 stats = tny_folder_get_stats (folder);
638 /* initially, we sometimes get -1 from tinymail; ignore that */
639 if (helper->function && helper->function (stats) > 0)
640 helper->sum += helper->function (stats);
642 if (TNY_IS_FOLDER_STORE (folder)) {
643 recurse_folders (TNY_FOLDER_STORE (folder), query, helper);
646 g_object_unref (folder);
647 g_object_unref (stats);
648 tny_iterator_next (iter);
650 g_object_unref (G_OBJECT (iter));
651 g_object_unref (G_OBJECT (folders));
655 modest_tny_folder_store_get_folder_count (TnyFolderStore *self)
657 RecurseFoldersHelper *helper;
660 g_return_val_if_fail (TNY_IS_FOLDER_STORE (self), -1);
663 helper = g_malloc0 (sizeof (RecurseFoldersHelper));
664 helper->function = NULL;
668 recurse_folders (self, NULL, helper);
670 retval = helper->folders;
678 modest_tny_folder_store_get_message_count (TnyFolderStore *self)
680 RecurseFoldersHelper *helper;
683 g_return_val_if_fail (TNY_IS_FOLDER_STORE (self), -1);
686 helper = g_malloc0 (sizeof (RecurseFoldersHelper));
687 helper->function = (TnyStatsFunc) tny_folder_stats_get_all_count;
690 recurse_folders (self, NULL, helper);
692 retval = helper->sum;
700 modest_tny_folder_store_get_local_size (TnyFolderStore *self)
702 RecurseFoldersHelper *helper;
705 g_return_val_if_fail (TNY_IS_FOLDER_STORE (self), -1);
708 helper = g_malloc0 (sizeof (RecurseFoldersHelper));
709 helper->function = (TnyStatsFunc) tny_folder_stats_get_local_size;
712 recurse_folders (self, NULL, helper);
714 retval = helper->sum;
721 const gchar* modest_tny_account_get_parent_modest_account_name_for_server_account (TnyAccount *self)
723 return (const gchar *)g_object_get_data (G_OBJECT (self), "modest_account");
726 void modest_tny_account_set_parent_modest_account_name_for_server_account (TnyAccount *self, const gchar* parent_modest_acount_name)
728 g_object_set_data_full (G_OBJECT(self), "modest_account",
729 (gpointer*) g_strdup (parent_modest_acount_name), g_free);