2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with the program; if not, see <http://www.gnu.org/licenses/>
17 * Michael Zucchi <notzed@ximian.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
29 #include <glib/gi18n.h>
31 #include "libevolution-utils/e-alert-dialog.h"
33 #include "libemail-utils/mail-mt.h"
34 #include "libemail-engine/mail-folder-cache.h"
35 #include "libemail-engine/e-mail-folder-utils.h"
36 #include "libemail-engine/e-mail-session.h"
37 #include "libemail-engine/e-mail-utils.h"
38 #include "libemail-engine/mail-ops.h"
39 #include "libemail-engine/mail-tools.h"
41 #include <libemail-utils/em-vfolder-context.h>
42 #include <libemail-utils/em-vfolder-rule.h>
43 #include "mail-vfolder.h"
45 #define d(x) /* (printf("%s:%s: ", G_STRLOC, G_STRFUNC), (x))*/
47 /* Note: Once we completely move mail to EDS, this context wont be available for UI.
48 * and vfoldertypes.xml should be moved here really. */
49 EMVFolderContext
*context
; /* context remains open all time */
51 /* lock for accessing shared resources (below) */
52 G_LOCK_DEFINE_STATIC (vfolder
);
54 static GHashTable
*vfolder_hash
;
55 /* This is a slightly hacky solution to shutting down, we poll this variable in various
56 * loops, and just quit processing if it is set. */
57 static volatile gint vfolder_shutdown
; /* are we shutting down? */
59 static void rule_changed (EFilterRule
*rule
, CamelFolder
*folder
);
61 /* ********************************************************************** */
66 EMailSession
*session
;
70 GList
*sources_folder
;
74 vfolder_setup_desc (struct _setup_msg
*m
)
76 return g_strdup_printf (
77 _("Setting up Search Folder: %s"),
78 camel_folder_get_full_name (m
->folder
));
82 vfolder_setup_exec (struct _setup_msg
*m
,
83 GCancellable
*cancellable
,
86 GList
*l
, *list
= NULL
;
89 camel_vee_folder_set_expression ((CamelVeeFolder
*) m
->folder
, m
->query
);
92 while (l
&& !vfolder_shutdown
) {
93 d(printf(" Adding uri: %s\n", (gchar
*)l
->data
));
95 /* FIXME Not passing a GCancellable or GError here. */
96 folder
= e_mail_session_uri_to_folder_sync (
97 m
->session
, l
->data
, 0, NULL
, NULL
);
99 list
= g_list_append (list
, folder
);
103 l
= m
->sources_folder
;
104 while (l
&& !vfolder_shutdown
) {
105 g_object_ref (l
->data
);
106 list
= g_list_append (list
, l
->data
);
110 if (!vfolder_shutdown
)
111 camel_vee_folder_set_folders ((CamelVeeFolder
*) m
->folder
, list
);
115 g_object_unref (l
->data
);
122 vfolder_setup_done (struct _setup_msg
*m
)
127 vfolder_setup_free (struct _setup_msg
*m
)
131 g_object_unref (m
->session
);
132 g_object_unref (m
->folder
);
140 g_list_free (m
->sources_uri
);
142 l
= m
->sources_folder
;
144 g_object_unref (l
->data
);
147 g_list_free (m
->sources_folder
);
150 static MailMsgInfo vfolder_setup_info
= {
151 sizeof (struct _setup_msg
),
152 (MailMsgDescFunc
) vfolder_setup_desc
,
153 (MailMsgExecFunc
) vfolder_setup_exec
,
154 (MailMsgDoneFunc
) vfolder_setup_done
,
155 (MailMsgFreeFunc
) vfolder_setup_free
158 /* sources_uri should be camel uri's */
160 vfolder_setup (EMailSession
*session
,
164 GList
*sources_folder
)
166 struct _setup_msg
*m
;
169 m
= mail_msg_new (&vfolder_setup_info
);
170 m
->session
= g_object_ref (session
);
171 m
->folder
= g_object_ref (folder
);
172 m
->query
= g_strdup (query
);
173 m
->sources_uri
= sources_uri
;
174 m
->sources_folder
= sources_folder
;
177 mail_msg_slow_ordered_push (m
);
182 /* ********************************************************************** */
187 EMailSession
*session
;
194 vfolder_adduri_desc (struct _adduri_msg
*m
)
197 CamelService
*service
;
198 const gchar
*display_name
;
203 success
= e_mail_folder_uri_parse (
204 CAMEL_SESSION (m
->session
), m
->uri
,
205 &store
, &folder_name
, NULL
);
210 service
= CAMEL_SERVICE (store
);
211 display_name
= camel_service_get_display_name (service
);
213 description
= g_strdup_printf (
214 _("Updating Search Folders for '%s' - %s"),
215 display_name
, folder_name
);
217 g_object_unref (store
);
218 g_free (folder_name
);
224 vfolder_adduri_exec (struct _adduri_msg
*m
,
225 GCancellable
*cancellable
,
229 CamelFolder
*folder
= NULL
;
230 MailFolderCache
*folder_cache
;
232 if (vfolder_shutdown
)
235 folder_cache
= e_mail_session_get_folder_cache (m
->session
);
237 /* we dont try lookup the cache if we are removing it, its no longer there */
240 !mail_folder_cache_get_folder_from_uri (folder_cache
, m
->uri
, NULL
)) {
242 "Folder '%s' disappeared while I was "
243 "adding/removing it to/from my vfolder", m
->uri
);
247 /* always pick fresh folders - they are
248 * from CamelStore's folders bag anyway */
249 folder
= e_mail_session_uri_to_folder_sync (
250 m
->session
, m
->uri
, 0, cancellable
, error
);
252 if (folder
!= NULL
) {
254 while (l
&& !vfolder_shutdown
) {
256 camel_vee_folder_remove_folder (
257 CAMEL_VEE_FOLDER (l
->data
), folder
);
259 camel_vee_folder_add_folder ((CamelVeeFolder
*) l
->data
, folder
);
262 g_object_unref (folder
);
267 vfolder_adduri_done (struct _adduri_msg
*m
)
272 vfolder_adduri_free (struct _adduri_msg
*m
)
274 g_object_unref (m
->session
);
275 g_list_foreach (m
->folders
, (GFunc
) g_object_unref
, NULL
);
276 g_list_free (m
->folders
);
280 static MailMsgInfo vfolder_adduri_info
= {
281 sizeof (struct _adduri_msg
),
282 (MailMsgDescFunc
) vfolder_adduri_desc
,
283 (MailMsgExecFunc
) vfolder_adduri_exec
,
284 (MailMsgDoneFunc
) vfolder_adduri_done
,
285 (MailMsgFreeFunc
) vfolder_adduri_free
288 /* uri should be a camel uri */
290 vfolder_adduri (EMailSession
*session
,
295 struct _adduri_msg
*m
;
298 m
= mail_msg_new (&vfolder_adduri_info
);
299 m
->session
= g_object_ref (session
);
300 m
->folders
= folders
;
301 m
->uri
= g_strdup (uri
);
305 mail_msg_slow_ordered_push (m
);
310 /* ********************************************************************** */
312 /* so special we never use it */
314 folder_is_spethal (CamelStore
*store
,
315 const gchar
*folder_name
)
317 /* This is a bit of a hack, but really the only way it can be done
320 if (store
->flags
& CAMEL_STORE_VTRASH
)
321 if (g_strcmp0 (folder_name
, CAMEL_VTRASH_NAME
) == 0)
324 if (store
->flags
& CAMEL_STORE_VJUNK
)
325 if (g_strcmp0 (folder_name
, CAMEL_VJUNK_NAME
) == 0)
332 * mail_vfolder_add_folder:
333 * @store: a #CamelStore
334 * @folder: a folder name
335 * @remove: whether the folder should be removed or added
337 * Called when a new folder becomes (un)available. If @store is not a
338 * CamelVeeStore, the folder is added/removed from the list of cached source
339 * folders. Then each vfolder rule is checked to see if the specified folder
340 * matches a source of the rule. It builds a list of vfolders that use (or
341 * would use) the specified folder as a source. It then adds (or removes)
342 * this folder to (from) those vfolders via camel_vee_folder_add/
343 * remove_folder() but does not modify the actual filters or write changes
346 * NOTE: This function must be called from the main thread.
349 mail_vfolder_add_folder (CamelStore
*store
,
350 const gchar
*folder_name
,
353 CamelService
*service
;
354 CamelSession
*session
;
358 CamelProvider
*provider
;
359 GList
*folders
= NULL
;
363 g_return_if_fail (CAMEL_IS_STORE (store
));
364 g_return_if_fail (folder_name
!= NULL
);
366 service
= CAMEL_SERVICE (store
);
367 session
= camel_service_get_session (service
);
368 provider
= camel_service_get_provider (service
);
370 remote
= (provider
->flags
& CAMEL_PROVIDER_IS_REMOTE
) != 0;
372 if (folder_is_spethal (store
, folder_name
))
375 g_return_if_fail (mail_in_main_thread ());
377 uri
= e_mail_folder_uri_build (store
, folder_name
);
385 while ((rule
= e_rule_context_next_rule ((ERuleContext
*) context
, rule
, NULL
))) {
389 d(printf("invalid rule (%p): rule->name is set to NULL\n", rule
));
392 /* Don't auto-add any sent/drafts folders etc,
393 * they must be explictly listed as a source. */
395 && !CAMEL_IS_VEE_STORE (store
)
396 && ((((EMVFolderRule
*) rule
)->with
==
397 EM_VFOLDER_RULE_WITH_LOCAL
&& !remote
)
398 || (((EMVFolderRule
*) rule
)->with
==
399 EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE
&& remote
)
400 || (((EMVFolderRule
*) rule
)->with
==
401 EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE
)))
405 while (!found
&& (source
= em_vfolder_rule_next_source (
406 (EMVFolderRule
*) rule
, source
))) {
407 found
= e_mail_folder_uri_equal (session
, uri
, source
);
411 vf
= g_hash_table_lookup (vfolder_hash
, rule
->name
);
413 g_warning ("vf is NULL for %s\n", rule
->name
);
417 folders
= g_list_prepend (folders
, vf
);
426 E_MAIL_SESSION (session
),
427 uri
, folders
, remove
);
433 * mail_vfolder_delete_folder:
434 * @store: a #CamelStore
435 * @folder_name: a folder name
437 * Looks through all vfolder rules to see if @folder_name is listed as a
438 * source for any vfolder rules. If the folder is found in the source for
439 * any rule, it is removed and the user is alerted to the fact that the
440 * vfolder rules have been updated. The new vfolder rules are written
443 * XXX: It doesn't appear that the changes to the vfolder rules are sent
444 * down to the camel level, however. So the actual vfolders will not change
445 * behavior until evolution is restarted (?)
447 * NOTE: This function must be called from the main thread.
450 mail_vfolder_delete_folder (CamelStore
*store
,
451 const gchar
*folder_name
)
453 ERuleContext
*rule_context
;
455 CamelService
*service
;
456 CamelSession
*session
;
463 g_return_if_fail (CAMEL_IS_STORE (store
));
464 g_return_if_fail (folder_name
!= NULL
);
466 if (folder_is_spethal (store
, folder_name
))
469 d(printf ("Deleting uri to check: %s\n", uri
));
471 g_return_if_fail (mail_in_main_thread ());
473 service
= CAMEL_SERVICE (store
);
474 session
= camel_service_get_session (service
);
476 uri
= e_mail_folder_uri_build (store
, folder_name
);
479 changed
= g_string_new ("");
486 rule_context
= E_RULE_CONTEXT (context
);
488 /* see if any rules directly reference this removed uri */
490 while ((rule
= e_rule_context_next_rule (rule_context
, rule
, NULL
))) {
491 EMVFolderRule
*vf_rule
= EM_VFOLDER_RULE (rule
);
497 while ((source
= em_vfolder_rule_next_source (vf_rule
, source
))) {
498 /* Remove all sources that match, ignore changed events though
499 * because the adduri call above does the work async */
500 if (e_mail_folder_uri_equal (session
, uri
, source
)) {
501 vf
= g_hash_table_lookup (
502 vfolder_hash
, rule
->name
);
505 g_warning ("vf is NULL for %s\n", rule
->name
);
509 g_signal_handlers_disconnect_matched (
510 rule
, G_SIGNAL_MATCH_FUNC
|
511 G_SIGNAL_MATCH_DATA
, 0, 0, NULL
,
514 em_vfolder_rule_remove_source (vf_rule
, source
);
518 G_CALLBACK (rule_changed
), vf
);
520 if (changed_count
== 0) {
521 g_string_append (changed
, rule
->name
);
523 if (changed_count
== 1) {
524 g_string_prepend (changed
, " ");
525 g_string_append (changed
, "\n");
527 g_string_append_printf (
541 if (changed_count
> 0) {
542 EAlertSink
*alert_sink
;
543 const gchar
*config_dir
;
546 alert_sink
= mail_msg_get_alert_sink ();
548 info
= g_strdup_printf (ngettext (
549 /* Translators: The first %s is name of the affected
550 * search folder(s), the second %s is the URI of the
551 * removed folder. For more than one search folder is
552 * each of them on a separate line, with four spaces
553 * in front of its name, without quotes. */
554 "The Search Folder \"%s\" has been modified to "
555 "account for the deleted folder\n\"%s\".",
556 "The following Search Folders\n%s have been modified "
557 "to account for the deleted folder\n\"%s\".",
558 changed_count
), changed
->str
, uri
);
560 alert_sink
, "mail:vfolder-updated", info
, NULL
);
563 config_dir
= mail_session_get_config_dir ();
564 user
= g_build_filename (config_dir
, "vfolders.xml", NULL
);
565 e_rule_context_save ((ERuleContext
*) context
, user
);
569 g_string_free (changed
, TRUE
);
574 /* called when a uri is renamed in a store */
576 mail_vfolder_rename_folder (CamelStore
*store
,
577 const gchar
*old_folder_name
,
578 const gchar
*new_folder_name
)
580 ERuleContext
*rule_context
;
584 CamelService
*service
;
585 CamelSession
*session
;
590 d(printf("vfolder rename uri: %s to %s\n", cfrom
, cto
));
595 if (folder_is_spethal (store
, old_folder_name
))
598 if (folder_is_spethal (store
, new_folder_name
))
601 g_return_if_fail (mail_in_main_thread ());
603 service
= CAMEL_SERVICE (store
);
604 session
= camel_service_get_session (service
);
606 old_uri
= e_mail_folder_uri_build (store
, old_folder_name
);
607 new_uri
= e_mail_folder_uri_build (store
, new_folder_name
);
611 rule_context
= E_RULE_CONTEXT (context
);
613 /* see if any rules directly reference this removed uri */
615 while ((rule
= e_rule_context_next_rule (rule_context
, rule
, NULL
))) {
616 EMVFolderRule
*vf_rule
= EM_VFOLDER_RULE (rule
);
619 while ((source
= em_vfolder_rule_next_source (vf_rule
, source
))) {
620 /* Remove all sources that match, ignore changed events though
621 * because the adduri call above does the work async */
622 if (e_mail_folder_uri_equal (session
, old_uri
, source
)) {
623 vf
= g_hash_table_lookup (vfolder_hash
, rule
->name
);
625 g_warning ("vf is NULL for %s\n", rule
->name
);
629 g_signal_handlers_disconnect_matched (
630 rule
, G_SIGNAL_MATCH_FUNC
|
631 G_SIGNAL_MATCH_DATA
, 0, 0, NULL
,
634 em_vfolder_rule_remove_source (vf_rule
, source
);
635 em_vfolder_rule_add_source (vf_rule
, new_uri
);
639 G_CALLBACK (rule_changed
), vf
);
650 const gchar
*config_dir
;
653 d(printf("Vfolders updated from renamed folder\n"));
654 config_dir
= mail_session_get_config_dir ();
655 user
= g_build_filename (config_dir
, "vfolders.xml", NULL
);
656 e_rule_context_save ((ERuleContext
*) context
, user
);
664 /* ********************************************************************** */
666 static void context_rule_added (ERuleContext
*ctx
, EFilterRule
*rule
, EMailSession
*session
);
669 rule_add_sources (EMailSession
*session
,
671 GList
**sources_folderp
,
672 GList
**sources_urip
)
674 GList
*sources_folder
= *sources_folderp
;
675 GList
*sources_uri
= *sources_urip
;
676 MailFolderCache
*folder_cache
;
679 folder_cache
= e_mail_session_get_folder_cache (session
);
681 head
= g_queue_peek_head_link (queue
);
682 for (link
= head
; link
!= NULL
; link
= g_list_next (link
)) {
683 const gchar
*uri
= link
->data
;
685 /* always pick fresh folders - they are
686 * from CamelStore's folders bag anyway */
687 if (mail_folder_cache_get_folder_from_uri (folder_cache
, uri
, NULL
)) {
688 sources_uri
= g_list_append (sources_uri
, g_strdup (uri
));
692 *sources_folderp
= sources_folder
;
693 *sources_urip
= sources_uri
;
696 static EMailSession
*
697 get_session (CamelFolder
*folder
)
701 store
= camel_folder_get_parent_store (folder
);
703 return (EMailSession
*) camel_service_get_session (CAMEL_SERVICE (store
));
707 rule_changed (EFilterRule
*rule
,
710 EMailSession
*session
;
711 CamelService
*service
;
712 GList
*sources_uri
= NULL
;
713 GList
*sources_folder
= NULL
;
715 const gchar
*full_name
;
717 full_name
= camel_folder_get_full_name (folder
);
718 session
= get_session (folder
);
720 service
= camel_session_get_service (
721 CAMEL_SESSION (session
), E_MAIL_SESSION_VFOLDER_UID
);
722 g_return_if_fail (CAMEL_IS_SERVICE (service
));
724 /* If the folder has changed name, then
725 * add it, then remove the old manually. */
726 if (strcmp (full_name
, rule
->name
) != 0) {
733 if (g_hash_table_lookup_extended (
734 vfolder_hash
, full_name
, &key
, &oldfolder
)) {
735 g_hash_table_remove (vfolder_hash
, key
);
737 g_hash_table_insert (
738 vfolder_hash
, g_strdup (rule
->name
), folder
);
743 "couldn't find a vfolder rule "
744 "in our table? %s", full_name
);
747 oldname
= g_strdup (full_name
);
748 /* FIXME Not passing a GCancellable or GError. */
749 camel_store_rename_folder_sync (
750 CAMEL_STORE (service
),
751 oldname
, rule
->name
, NULL
, NULL
);
755 d(printf("Filter rule changed? for folder '%s'!!\n", folder
->name
));
757 /* find any (currently available) folders, and add them to the ones to open */
759 session
, &((EMVFolderRule
*) rule
)->sources
,
760 &sources_folder
, &sources_uri
);
764 if (((EMVFolderRule
*) rule
)->with
==
765 EM_VFOLDER_RULE_WITH_LOCAL
||
766 ((EMVFolderRule
*) rule
)->with
==
767 EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE
) {
769 MailFolderCache
*cache
;
770 GQueue queue
= G_QUEUE_INIT
;
772 cache
= e_mail_session_get_folder_cache (session
);
773 mail_folder_cache_get_local_folder_uris (cache
, &queue
);
776 session
, &queue
, &sources_folder
, &sources_uri
);
778 while (!g_queue_is_empty (&queue
))
779 g_free (g_queue_pop_head (&queue
));
782 if (((EMVFolderRule
*) rule
)->with
==
783 EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE
||
784 ((EMVFolderRule
*) rule
)->with
==
785 EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE
) {
787 MailFolderCache
*cache
;
788 GQueue queue
= G_QUEUE_INIT
;
790 cache
= e_mail_session_get_folder_cache (session
);
791 mail_folder_cache_get_remote_folder_uris (cache
, &queue
);
794 session
, &queue
, &sources_folder
, &sources_uri
);
796 while (!g_queue_is_empty (&queue
))
797 g_free (g_queue_pop_head (&queue
));
802 query
= g_string_new("");
803 e_filter_rule_build_code (rule
, query
);
805 vfolder_setup (session
, folder
, query
->str
, sources_uri
, sources_folder
);
807 g_string_free (query
, TRUE
);
811 context_rule_added (ERuleContext
*ctx
,
813 EMailSession
*session
)
816 CamelService
*service
;
818 d(printf("rule added: %s\n", rule
->name
));
820 service
= camel_session_get_service (
821 CAMEL_SESSION (session
), E_MAIL_SESSION_VFOLDER_UID
);
822 g_return_if_fail (CAMEL_IS_SERVICE (service
));
824 /* this always runs quickly */
825 /* FIXME Not passing a GCancellable or GError. */
826 folder
= camel_store_get_folder_sync (
827 CAMEL_STORE (service
), rule
->name
, 0, NULL
, NULL
);
831 G_CALLBACK (rule_changed
), folder
);
834 g_hash_table_insert (vfolder_hash
, g_strdup (rule
->name
), folder
);
837 rule_changed (rule
, folder
);
842 context_rule_removed (ERuleContext
*ctx
,
844 EMailSession
*session
)
846 CamelService
*service
;
847 gpointer key
, folder
= NULL
;
849 d(printf("rule removed; %s\n", rule
->name
));
851 service
= camel_session_get_service (
852 CAMEL_SESSION (session
), E_MAIL_SESSION_VFOLDER_UID
);
853 g_return_if_fail (CAMEL_IS_SERVICE (service
));
855 /* TODO: remove from folder info cache? */
858 if (g_hash_table_lookup_extended (vfolder_hash
, rule
->name
, &key
, &folder
)) {
859 g_hash_table_remove (vfolder_hash
, key
);
864 /* FIXME Not passing a GCancellable or GError. */
865 camel_store_delete_folder_sync (
866 CAMEL_STORE (service
), rule
->name
, NULL
, NULL
);
867 /* this must be unref'd after its deleted */
869 g_object_unref ((CamelFolder
*) folder
);
873 store_folder_deleted_cb (CamelStore
*store
,
874 CamelFolderInfo
*info
)
879 d(printf("Folder deleted: %s\n", info
->name
));
882 /* Warning not thread safe, but might be enough */
886 /* delete it from our list */
887 rule
= e_rule_context_find_rule ((ERuleContext
*) context
, info
->full_name
, NULL
);
889 const gchar
*config_dir
;
891 /* We need to stop listening to removed events,
892 * otherwise we'll try and remove it again. */
893 g_signal_handlers_disconnect_matched (
894 context
, G_SIGNAL_MATCH_FUNC
| G_SIGNAL_MATCH_DATA
,
895 0, 0, NULL
, context_rule_removed
, context
);
896 e_rule_context_remove_rule ((ERuleContext
*) context
, rule
);
897 g_object_unref (rule
);
899 context
, "rule_removed",
900 G_CALLBACK (context_rule_removed
), context
);
902 config_dir
= mail_session_get_config_dir ();
903 user
= g_build_filename (config_dir
, "vfolders.xml", NULL
);
904 e_rule_context_save ((ERuleContext
*) context
, user
);
908 "Cannot find rule for deleted vfolder '%s'",
916 store_folder_renamed_cb (CamelStore
*store
,
917 const gchar
*old_name
,
918 CamelFolderInfo
*info
)
923 gpointer key
, folder
;
925 /* This should be more-or-less thread-safe */
927 d(printf("Folder renamed to '%s' from '%s'\n", info
->full_name
, old_name
));
929 /* Folder is already renamed? */
931 d(printf("Changing folder name in hash table to '%s'\n", info
->full_name
));
932 if (g_hash_table_lookup_extended (vfolder_hash
, old_name
, &key
, &folder
)) {
933 const gchar
*config_dir
;
935 g_hash_table_remove (vfolder_hash
, key
);
937 g_hash_table_insert (vfolder_hash
, g_strdup (info
->full_name
), folder
);
939 rule
= e_rule_context_find_rule ((ERuleContext
*) context
, old_name
, NULL
);
942 g_warning ("Rule shouldn't be NULL\n");
946 g_signal_handlers_disconnect_matched (
947 rule
, G_SIGNAL_MATCH_FUNC
| G_SIGNAL_MATCH_DATA
,
948 0, 0, NULL
, rule_changed
, folder
);
949 e_filter_rule_set_name (rule
, info
->full_name
);
952 G_CALLBACK (rule_changed
), folder
);
954 config_dir
= mail_session_get_config_dir ();
955 user
= g_build_filename (config_dir
, "vfolders.xml", NULL
);
956 e_rule_context_save ((ERuleContext
*) context
, user
);
962 g_warning("couldn't find a vfolder rule in our table? %s", info
->full_name
);
967 folder_available_cb (MailFolderCache
*cache
,
969 const gchar
*folder_name
)
971 mail_vfolder_add_folder (store
, folder_name
, FALSE
);
975 folder_unavailable_cb (MailFolderCache
*cache
,
977 const gchar
*folder_name
)
979 mail_vfolder_add_folder (store
, folder_name
, TRUE
);
983 folder_deleted_cb (MailFolderCache
*cache
,
985 const gchar
*folder_name
)
987 mail_vfolder_delete_folder (store
, folder_name
);
991 folder_renamed_cb (MailFolderCache
*cache
,
993 const gchar
*old_folder_name
,
994 const gchar
*new_folder_name
,
997 mail_vfolder_rename_folder (store
, old_folder_name
, new_folder_name
);
1001 vfolder_load_storage (EMailSession
*session
)
1003 /* lock for loading storage, it is safe to call it more than once */
1004 G_LOCK_DEFINE_STATIC (vfolder_hash
);
1006 CamelStore
*vfolder_store
;
1007 const gchar
*config_dir
;
1010 MailFolderCache
*folder_cache
;
1012 GSettings
*settings
;
1014 G_LOCK (vfolder_hash
);
1017 /* we have already initialized */
1018 G_UNLOCK (vfolder_hash
);
1022 vfolder_hash
= g_hash_table_new (g_str_hash
, g_str_equal
);
1024 G_UNLOCK (vfolder_hash
);
1026 config_dir
= mail_session_get_config_dir ();
1027 vfolder_store
= e_mail_session_get_vfolder_store (E_MAIL_SESSION (session
));
1030 vfolder_store
, "folder-deleted",
1031 G_CALLBACK (store_folder_deleted_cb
), NULL
);
1034 vfolder_store
, "folder-renamed",
1035 G_CALLBACK (store_folder_renamed_cb
), NULL
);
1037 /* load our rules */
1038 user
= g_build_filename (config_dir
, "vfolders.xml", NULL
);
1039 /* This needs editor context which is only in the mail/. But really to run here we dont need editor context.
1040 * So till we split this to EDS, we would let mail/ create this and later one it is any ways two separate
1042 context
= e_mail_session_create_vfolder_context (session
);
1044 xmlfile
= g_build_filename (EVOLUTION_PRIVDATADIR
, "vfoldertypes.xml", NULL
);
1045 if (e_rule_context_load ((ERuleContext
*) context
,
1046 xmlfile
, user
) != 0) {
1047 g_warning("cannot load vfolders: %s\n", ((ERuleContext
*)context
)->error
);
1053 context
, "rule_added",
1054 G_CALLBACK (context_rule_added
), session
);
1056 context
, "rule_removed",
1057 G_CALLBACK (context_rule_removed
), session
);
1059 /* and setup the rules we have */
1061 while ((rule
= e_rule_context_next_rule ((ERuleContext
*) context
, rule
, NULL
))) {
1063 d(printf("rule added: %s\n", rule
->name
));
1064 context_rule_added ((ERuleContext
*) context
, rule
, session
);
1066 d(printf("invalid rule (%p) encountered: rule->name is NULL\n", rule
));
1070 /* reenable the feature if required */
1071 settings
= g_settings_new ("org.gnome.evolution.mail");
1072 g_settings_set_boolean (settings
, "enable-vfolders", TRUE
);
1073 g_object_unref (settings
);
1075 folder_cache
= e_mail_session_get_folder_cache (session
);
1078 folder_cache
, "folder-available",
1079 G_CALLBACK (folder_available_cb
), NULL
);
1081 folder_cache
, "folder-unavailable",
1082 G_CALLBACK (folder_unavailable_cb
), NULL
);
1084 folder_cache
, "folder-deleted",
1085 G_CALLBACK (folder_deleted_cb
), NULL
);
1087 folder_cache
, "folder-renamed",
1088 G_CALLBACK (folder_renamed_cb
), NULL
);
1092 vfolder_foreach_cb (gpointer key
,
1096 CamelFolder
*folder
= CAMEL_FOLDER (data
);
1099 g_object_unref (folder
);
1105 mail_vfolder_shutdown (void)
1107 vfolder_shutdown
= 1;
1110 g_hash_table_foreach (vfolder_hash
, vfolder_foreach_cb
, NULL
);
1111 g_hash_table_destroy (vfolder_hash
);
1112 vfolder_hash
= NULL
;
1116 g_object_unref (context
);