aboutsummaryrefslogtreecommitdiffstats
path: root/libemail-engine/mail-ops.c
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2012-12-05 02:32:25 +0800
committerMilan Crha <mcrha@redhat.com>2012-12-05 02:33:29 +0800
commitae6344a22b041577fdab9bf3866dbfe779dc1409 (patch)
treea2c0a2fe4d684cd8609f83c4619a50997a7421a6 /libemail-engine/mail-ops.c
parent56975aec6a4904140df94361ff9c4bbca5b1dc95 (diff)
downloadgsoc2013-evolution-ae6344a22b041577fdab9bf3866dbfe779dc1409.tar
gsoc2013-evolution-ae6344a22b041577fdab9bf3866dbfe779dc1409.tar.gz
gsoc2013-evolution-ae6344a22b041577fdab9bf3866dbfe779dc1409.tar.bz2
gsoc2013-evolution-ae6344a22b041577fdab9bf3866dbfe779dc1409.tar.lz
gsoc2013-evolution-ae6344a22b041577fdab9bf3866dbfe779dc1409.tar.xz
gsoc2013-evolution-ae6344a22b041577fdab9bf3866dbfe779dc1409.tar.zst
gsoc2013-evolution-ae6344a22b041577fdab9bf3866dbfe779dc1409.zip
Bug #315317 - Add option to expunge messages on folder leave
Diffstat (limited to 'libemail-engine/mail-ops.c')
-rw-r--r--libemail-engine/mail-ops.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/libemail-engine/mail-ops.c b/libemail-engine/mail-ops.c
index d93a17b45f..bd4b4f9676 100644
--- a/libemail-engine/mail-ops.c
+++ b/libemail-engine/mail-ops.c
@@ -1247,6 +1247,7 @@ struct _sync_folder_msg {
MailMsg base;
CamelFolder *folder;
+ gboolean test_for_expunge;
void (*done) (CamelFolder *folder, gpointer data);
gpointer data;
};
@@ -1264,8 +1265,60 @@ sync_folder_exec (struct _sync_folder_msg *m,
GCancellable *cancellable,
GError **error)
{
- camel_folder_synchronize_sync (
- m->folder, FALSE, cancellable, error);
+ gboolean expunge = FALSE;
+
+ if (m->test_for_expunge) {
+ GSettings *settings;
+ gboolean delete_junk;
+
+ settings = g_settings_new ("org.gnome.evolution.mail");
+
+ expunge = g_settings_get_boolean (settings, "trash-empty-on-exit") &&
+ g_settings_get_int (settings, "trash-empty-on-exit-days") == -1;
+ delete_junk = g_settings_get_boolean (settings, "junk-empty-on-exit") &&
+ g_settings_get_int (settings, "junk-empty-on-exit-days") == -1;
+
+ g_object_unref (settings);
+
+ /* delete junk first, if requested */
+ if (delete_junk) {
+ CamelStore *store;
+ CamelFolder *folder;
+
+ store = camel_folder_get_parent_store (m->folder);
+ folder = camel_store_get_junk_folder_sync (store, cancellable, error);
+ if (folder != NULL) {
+ GPtrArray *uids;
+ guint32 flags;
+ guint32 mask;
+ guint ii;
+
+ uids = camel_folder_get_uids (folder);
+ flags = mask = CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN;
+
+ camel_folder_freeze (folder);
+
+ for (ii = 0; ii < uids->len && !g_cancellable_is_cancelled (cancellable); ii++) {
+ const gchar *uid = uids->pdata[ii];
+ camel_folder_set_message_flags (folder, uid, flags, mask);
+ }
+
+ camel_folder_thaw (folder);
+ camel_folder_free_uids (folder, uids);
+
+ g_object_unref (folder);
+
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return;
+ }
+
+ /* error should be set already, from the get_junk_folder_sync() call */
+ if (g_cancellable_is_cancelled (cancellable))
+ return;
+ }
+ }
+
+ camel_folder_synchronize_sync (m->folder, expunge, cancellable, error);
}
static void
@@ -1292,6 +1345,7 @@ static MailMsgInfo sync_folder_info = {
void
mail_sync_folder (CamelFolder *folder,
+ gboolean test_for_expunge,
void (*done) (CamelFolder *folder,
gpointer data),
gpointer data)
@@ -1300,6 +1354,7 @@ mail_sync_folder (CamelFolder *folder,
m = mail_msg_new (&sync_folder_info);
m->folder = g_object_ref (folder);
+ m->test_for_expunge = test_for_expunge;
m->data = data;
m->done = done;