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.
8
* A generic collection of {@link Flags}.
11
public abstract class Geary.Imap.Flags : Geary.MessageData.AbstractMessageData, Geary.Imap.MessageData,
12
Gee.Hashable<Geary.Imap.Flags> {
13
public int size { get { return list.size; } }
15
protected Gee.Set<Flag> list;
17
protected Flags(Gee.Collection<Flag> flags) {
18
list = new Gee.HashSet<Flag>();
22
public bool contains(Flag flag) {
23
return list.contains(flag);
26
public Gee.Set<Flag> get_all() {
27
return list.read_only_view;
31
* Returns the flags in serialized form, which is each flag separated by a space (legal in
32
* IMAP, as flags must be atoms and atoms prohibit spaces).
34
public virtual string serialize() {
39
* Returns a {@link ListParameter} representation of these flags.
41
* If empty, this returns an empty ListParameter.
43
public virtual Parameter to_parameter() {
44
ListParameter listp = new ListParameter();
45
foreach (Flag flag in list) {
47
listp.add(flag.to_parameter());
48
} catch (ImapError ierr) {
49
// drop on floor with warning
50
message("Unable to parameterize flag \"%s\": %s", flag.to_string(), ierr.message);
57
public bool equal_to(Geary.Imap.Flags other) {
61
if (other.size != size)
64
return Geary.traverse<Flag>(list).all(f => other.contains(f));
67
public override string to_string() {
68
StringBuilder builder = new StringBuilder();
69
foreach (Flag flag in list) {
70
if (!String.is_empty(builder.str))
71
builder.append_c(' ');
73
builder.append(flag.value);
80
return Ascii.stri_hash(to_string());