~ubuntu-branches/ubuntu/saucy/geary/saucy-updates

« back to all changes in this revision

Viewing changes to src/engine/imap-engine/replay-ops/imap-engine-expunge-email.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-10-10 17:40:37 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20131010174037-5p5o4dlsoewek2kg
Tags: 0.4.0-0ubuntu1
New stable version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2012-2013 Yorba Foundation
2
 
 *
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.
5
 
 */
6
 
 
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;
13
 
    
14
 
    public ExpungeEmail(GenericFolder engine, Gee.List<ImapDB.EmailIdentifier> to_remove,
15
 
        Cancellable? cancellable = null) {
16
 
        base("ExpungeEmail");
17
 
        
18
 
        this.engine = engine;
19
 
        
20
 
        this.to_remove.add_all(to_remove);
21
 
        this.cancellable = cancellable;
22
 
    }
23
 
    
24
 
    public override void notify_remote_removed_ids(Gee.Collection<ImapDB.EmailIdentifier> ids) {
25
 
        if (removed_ids != null)
26
 
            removed_ids.remove_all(ids);
27
 
    }
28
 
    
29
 
    public override async ReplayOperation.Status replay_local_async() throws Error {
30
 
        if (to_remove.size <= 0)
31
 
            return ReplayOperation.Status.COMPLETED;
32
 
        
33
 
        int remote_count;
34
 
        int last_seen_remote_count;
35
 
        original_count = engine.get_remote_counts(out remote_count, out last_seen_remote_count);
36
 
        
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;
40
 
        
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;
44
 
        
45
 
        engine.notify_email_removed(removed_ids);
46
 
        
47
 
        engine.notify_email_count_changed(Numeric.int_floor(original_count - removed_ids.size, 0),
48
 
            Geary.Folder.CountChangeReason.REMOVED);
49
 
        
50
 
        return ReplayOperation.Status.CONTINUE;
51
 
    }
52
 
    
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()),
60
 
                cancellable);
61
 
        }
62
 
        
63
 
        return ReplayOperation.Status.COMPLETED;
64
 
    }
65
 
    
66
 
    public override async void backout_local_async() throws Error {
67
 
        yield engine.local_folder.mark_removed_async(removed_ids, false, cancellable);
68
 
        
69
 
        engine.notify_email_inserted(removed_ids);
70
 
        engine.notify_email_count_changed(original_count, Geary.Folder.CountChangeReason.INSERTED);
71
 
    }
72
 
    
73
 
    public override string describe_state() {
74
 
        return "to_remove=%d".printf(to_remove.size);
75
 
    }
76
 
}
77