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 response code and additional information that optionally accompanies a {@link StatusResponse}.
10
* See [[http://tools.ietf.org/html/rfc3501#section-7.1]] for more information.
13
public class Geary.Imap.ResponseCode : Geary.Imap.ListParameter {
14
public ResponseCode() {
17
public ResponseCodeType get_response_code_type() throws ImapError {
18
return new ResponseCodeType.from_parameter(get_as_string(0));
22
* Converts the {@link ResponseCode} into a UIDNEXT {@link UID}, if possible.
24
* @throws ImapError.INVALID if not UIDNEXT.
26
public UID get_uid_next() throws ImapError {
27
if (!get_response_code_type().is_value(ResponseCodeType.UIDNEXT))
28
throw new ImapError.INVALID("Not UIDNEXT: %s", to_string());
30
return new UID.checked(get_as_string(1).as_int64());
34
* Converts the {@link ResponseCode} into a {@link UIDValidity}, if possible.
36
* @throws ImapError.INVALID if not UIDVALIDITY.
38
public UIDValidity get_uid_validity() throws ImapError {
39
if (!get_response_code_type().is_value(ResponseCodeType.UIDVALIDITY))
40
throw new ImapError.INVALID("Not UIDVALIDITY: %s", to_string());
42
return new UIDValidity.checked(get_as_string(1).as_int64());
46
* Converts the {@link ResponseCode} into an UNSEEN value, if possible.
48
* @throws ImapError.INVALID if not UNSEEN.
50
public int get_unseen() throws ImapError {
51
if (!get_response_code_type().is_value(ResponseCodeType.UNSEEN))
52
throw new ImapError.INVALID("Not UNSEEN: %s", to_string());
54
return get_as_string(1).as_int32(0, int.MAX);
58
* Converts the {@link ResponseCode} into PERMANENTFLAGS {@link MessageFlags}, if possible.
60
* @throws ImapError.INVALID if not PERMANENTFLAGS.
62
public MessageFlags get_permanent_flags() throws ImapError {
63
if (!get_response_code_type().is_value(ResponseCodeType.PERMANENT_FLAGS))
64
throw new ImapError.INVALID("Not PERMANENTFLAGS: %s", to_string());
66
return MessageFlags.from_list(get_as_list(1));
70
* Parses the {@link ResponseCode} into {@link Capabilities}, if possible.
72
* Since Capabilities are revised with various {@link ClientSession} states, this method accepts
73
* a ref to an int that will be incremented after handed to the Capabilities constructor. This
74
* can be used to track the revision of capabilities seen on the connection.
76
* @throws ImapError.INVALID if Capability was not specified.
78
public Capabilities get_capabilities(ref int next_revision) throws ImapError {
79
if (!get_response_code_type().is_value(ResponseCodeType.CAPABILITY))
80
throw new ImapError.INVALID("Not CAPABILITY response code: %s", to_string());
82
Capabilities capabilities = new Capabilities(next_revision++);
83
for (int ctr = 1; ctr < size; ctr++) {
84
StringParameter? param = get_if_string(ctr);
86
capabilities.add_parameter(param);
93
* Parses the {@link ResponseCode} into UIDPLUS' COPYUID response, if possible.
95
* Note that the {@link UID}s are returned from the server in the order the messages
98
* See [[http://tools.ietf.org/html/rfc4315#section-3]]
100
* @throws ImapError.INVALID if not COPYUID.
102
public void get_copyuid(out UIDValidity uidvalidity, out Gee.List<UID>? source_uids,
103
out Gee.List<UID>? destination_uids) throws ImapError {
104
if (!get_response_code_type().is_value(ResponseCodeType.COPYUID))
105
throw new ImapError.INVALID("Not COPYUID response code: %s", to_string());
107
uidvalidity = new UIDValidity.checked(get_as_number(1).as_int64());
108
source_uids = MessageSet.uid_parse(get_as_string(2).ascii);
109
destination_uids = MessageSet.uid_parse(get_as_string(3).ascii);
112
public override string to_string() {
113
return "[%s]".printf(stringize_list());
116
public override void serialize(Serializer ser, GLib.Cancellable cancellable)
118
ser.push_ascii('[', cancellable);
119
serialize_list(ser, cancellable);
120
ser.push_ascii(']', cancellable);