1
/* Copyright 2016 Software Freedom Conservancy Inc.
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.ImapDB.EmailIdentifier : Geary.EmailIdentifier {
8
public int64 message_id { get; private set; }
9
public Imap.UID? uid { get; private set; }
11
public EmailIdentifier(int64 message_id, Imap.UID? uid) {
12
assert(message_id != Db.INVALID_ROWID);
14
base (message_id.to_string());
16
this.message_id = message_id;
20
// Used when a new message comes off the wire and doesn't have a rowid associated with it (yet)
21
// Requires a UID in order to find or create such an association
22
public EmailIdentifier.no_message_id(Imap.UID uid) {
23
base (Db.INVALID_ROWID.to_string());
25
message_id = Db.INVALID_ROWID;
29
// Used to promote an id created with no_message_id to one that has a
30
// message id. Warning: this causes the hash value to change, so if you
31
// have any EmailIdentifiers in a hashed data structure, this will cause
32
// you not to be able to find them.
33
public void promote_with_message_id(int64 message_id) {
34
assert(this.message_id == Db.INVALID_ROWID);
36
unique = message_id.to_string();
37
this.message_id = message_id;
40
public bool has_uid() {
41
return (uid != null) && uid.is_valid();
44
public override int natural_sort_comparator(Geary.EmailIdentifier o) {
45
ImapDB.EmailIdentifier? other = o as ImapDB.EmailIdentifier;
52
if (other.uid == null)
55
return uid.compare_to(other.uid);
58
public override string to_string() {
59
return "[%s/%s]".printf(message_id.to_string(), (uid == null ? "null" : uid.to_string()));
62
public static Gee.Set<Imap.UID> to_uids(Gee.Collection<ImapDB.EmailIdentifier> ids) {
63
Gee.HashSet<Imap.UID> uids = new Gee.HashSet<Imap.UID>();
64
foreach (ImapDB.EmailIdentifier id in ids) {