1/* Copyright 2016 Software Freedom Conservancy Inc.
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
7public class Geary.Smtp.Response {
8    public ResponseCode code { get; private set; }
9    public ResponseLine first_line { get; private set; }
10    public Gee.List<ResponseLine> lines { get; private set; }
11
12    public Response(Gee.List<ResponseLine> lines) {
13        assert(lines.size > 0);
14
15        code = lines[0].code;
16        first_line = lines[0];
17        this.lines = lines.read_only_view;
18    }
19
20    [NoReturn]
21    public void throw_error(string msg) throws SmtpError {
22        throw new SmtpError.SERVER_ERROR("%s: %s", msg, first_line.to_string());
23    }
24
25    public string to_string() {
26        StringBuilder builder = new StringBuilder();
27
28        foreach (ResponseLine line in lines) {
29            builder.append(line.to_string());
30            builder.append("\n");
31        }
32
33        return builder.str;
34    }
35}
36
37