diff --git a/mail/e-mail-backend.c b/mail/e-mail-backend.c
index 3bc822c..3d6d1aa 100644
--- a/mail/e-mail-backend.c
+++ b/mail/e-mail-backend.c
@@ -233,6 +233,9 @@ mail_backend_prepare_for_quit_cb (EShell *shell,
 
 	mail_vfolder_shutdown ();
 
+	/* Cancel all pending activities. */
+	mail_cancel_all ();
+
 	if (delete_junk)
 		e_mail_store_foreach (
 			(GHFunc) mail_backend_delete_junk, backend);
@@ -242,10 +245,7 @@ mail_backend_prepare_for_quit_cb (EShell *shell,
 
 	e_mail_store_foreach ((GHFunc) mail_backend_final_sync, &sync_data);
 
-	/* Cancel all activities. */
-	mail_cancel_all ();
-
-	/* Now we poll until all activities are actually cancelled.
+	/* Now we poll until all activities are actually cancelled or finished.
 	 * Reffing the activity delays quitting; the reference count
 	 * acts like a counting semaphore. */
 	if (mail_msg_active ((guint) -1))
