~hkdb/geary/bionic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright 2016 Software Freedom Conservancy Inc.
 * Copyright 2017-2018 Michael Gratton <mike@vee.net>
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

/** Describes available problem types. */
public enum Geary.ProblemType {


    /** Indicates an engine problem not covered by one of the other types. */
    GENERIC_ERROR,

    /** Indicates an error opening, using or closing the account database. */
    DATABASE_FAILURE,

    /** Indicates a problem establishing a connection. */
    CONNECTION_ERROR,

    /** Indicates a problem caused by a network operation. */
    NETWORK_ERROR,

    /** Indicates a non-network related server error. */
    SERVER_ERROR,

    /** Indicates credentials supplied for authentication were rejected. */
    AUTHENTICATION,

    /** Indicates a remote TLS certificate failed validation. */
    UNTRUSTED,

    /** Indicates an outgoing message was sent, but not saved. */
    SEND_EMAIL_SAVE_FAILED;


    /** Determines the appropriate problem type for an IOError. */
    public static ProblemType for_ioerror(IOError error) {
        if (error is IOError.CONNECTION_REFUSED ||
            error is IOError.HOST_NOT_FOUND ||
            error is IOError.HOST_UNREACHABLE ||
            error is IOError.NETWORK_UNREACHABLE) {
            return ProblemType.CONNECTION_ERROR;
        }

        if (error is IOError.CONNECTION_CLOSED ||
            error is IOError.NOT_CONNECTED) {
            return ProblemType.NETWORK_ERROR;
        }

        return ProblemType.GENERIC_ERROR;
    }

}

/**
 * Describes a error that the engine encountered, for reporting to the client.
 */
public class Geary.ProblemReport : Object {


    /** Describes the type of being reported. */
    public ProblemType problem_type { get; private set; }

    /** The exception caused the problem, if any. */
    public ErrorContext? error { get; private set; default = null; }


    public ProblemReport(ProblemType type, Error? error) {
        this.problem_type = type;
        if (error != null) {
            this.error = new ErrorContext(error);
        }
    }

    /** Returns a string representation of the report, for debugging only. */
    public string to_string() {
        return "%s: %s".printf(
            this.problem_type.to_string(),
            this.error != null
                ? this.error.format_full_error()
                : "no error reported"
        );
    }

}

/**
 * Describes an account-related error that the engine encountered.
 */
public class Geary.AccountProblemReport : ProblemReport {


    /** The account related to the problem report. */
    public AccountInformation account { get; private set; }


    public AccountProblemReport(ProblemType type, AccountInformation account, Error? error) {
        base(type, error);
        this.account = account;
    }

    /** Returns a string representation of the report, for debugging only. */
    public new string to_string() {
        return "%s: %s".printf(this.account.id, base.to_string());
    }

}

/**
 * Describes a service-related error that the engine encountered.
 */
public class Geary.ServiceProblemReport : AccountProblemReport {


    /** The service related to the problem report. */
    public ServiceInformation service { get; private set; }


    public ServiceProblemReport(ProblemType type,
                                AccountInformation account,
                                ServiceInformation service,
                                Error? error) {
        base(type, account, error);
        this.service = service;
    }

    /** Returns a string representation of the report, for debugging only. */
    public new string to_string() {
        return "%s: %s: %s: %s".printf(
            this.account.id,
            this.service.protocol.to_string(),
            this.problem_type.to_string(),
            this.error != null
                ? this.error.format_full_error()
                : "no error reported"
        );
    }

}