1
/* Copyright 2012-2013 Yorba Foundation
3
* This software is licensed under the GNU Lesser General Public License
4
* (version 2.1 or later). See the COPYING file in this distribution.
7
private class Geary.ImapEngine.ExpungeEmail : Geary.ImapEngine.SendReplayOperation {
8
private GenericFolder engine;
9
private Gee.List<ImapDB.EmailIdentifier> to_remove = new Gee.ArrayList<ImapDB.EmailIdentifier>();
10
private Cancellable? cancellable;
11
private Gee.Set<ImapDB.EmailIdentifier>? removed_ids = null;
12
private int original_count = 0;
14
public ExpungeEmail(GenericFolder engine, Gee.List<ImapDB.EmailIdentifier> to_remove,
15
Cancellable? cancellable = null) {
20
this.to_remove.add_all(to_remove);
21
this.cancellable = cancellable;
24
public override void notify_remote_removed_ids(Gee.Collection<ImapDB.EmailIdentifier> ids) {
25
if (removed_ids != null)
26
removed_ids.remove_all(ids);
29
public override async ReplayOperation.Status replay_local_async() throws Error {
30
if (to_remove.size <= 0)
31
return ReplayOperation.Status.COMPLETED;
34
int last_seen_remote_count;
35
original_count = engine.get_remote_counts(out remote_count, out last_seen_remote_count);
37
// because this value is only used for reporting count changes, offer best-possible service
38
if (original_count < 0)
39
original_count = to_remove.size;
41
removed_ids = yield engine.local_folder.mark_removed_async(to_remove, true, cancellable);
42
if (removed_ids == null || removed_ids.size == 0)
43
return ReplayOperation.Status.COMPLETED;
45
engine.notify_email_removed(removed_ids);
47
engine.notify_email_count_changed(Numeric.int_floor(original_count - removed_ids.size, 0),
48
Geary.Folder.CountChangeReason.REMOVED);
50
return ReplayOperation.Status.CONTINUE;
53
public override async ReplayOperation.Status replay_remote_async() throws Error {
54
// Remove from server. Note that this causes the receive replay queue to kick into
55
// action, removing the e-mail but *NOT* firing a signal; the "remove marker" indicates
56
// that the signal has already been fired.
57
if (removed_ids.size > 0) {
58
yield engine.remote_folder.remove_email_async(
59
new Imap.MessageSet.uid_sparse(ImapDB.EmailIdentifier.to_uids(removed_ids).to_array()),
63
return ReplayOperation.Status.COMPLETED;
66
public override async void backout_local_async() throws Error {
67
yield engine.local_folder.mark_removed_async(removed_ids, false, cancellable);
69
engine.notify_email_inserted(removed_ids);
70
engine.notify_email_count_changed(original_count, Geary.Folder.CountChangeReason.INSERTED);
73
public override string describe_state() {
74
return "to_remove=%d".printf(to_remove.size);