MailJDTourDownloadDocsQualityTestsCoverage

Which source lines and branches the tests execute. Lines 91.5 %, branches 75.0 % (minimum 85 % and 72 %). main @ 399ffe3d · 21 October 2026 · pipeline 7238.

GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 84.8% 145 / 0 / 171
Functions: 100.0% 13 / 0 / 13
Branches: 71.8% 163 / 0 / 227

service/ConnectionDiagnosis.cpp
Line Branch Exec Source
1 #include "ConnectionDiagnosis.h"
2 #include <QCryptographicHash>
3 #include <QLocale>
4 #include <QSslCertificate>
5
6 namespace {
7 35 Diagnosis make(const ConnectionDiagnosis::Input &input, const QString &kind, const QString &message,
8 const QString &action, const QString &actionLabel, const QString &field) {
9 35 Diagnosis result;
10 35 result.service = input.service;
11 35 result.kind = kind;
12 35 result.message = message;
13 35 result.action = action;
14 35 result.actionLabel = actionLabel;
15 35 result.field = field;
16
1/1
✓ Branch 8 → 9 taken 35 times.
35 result.detail = input.serverText.left(500);
17 35 return result;
18 ✗ }
19 35 QString hostPort(const ConnectionDiagnosis::Input &input) {
20
10/16
✓ Branch 2 → 3 taken 34 times.
✓ Branch 2 → 10 taken 1 time.
✓ Branch 7 → 8 taken 34 times.
✓ Branch 9 → 11 taken 34 times.
✓ Branch 11 → 12 taken 34 times.
✓ Branch 11 → 13 taken 1 time.
✓ Branch 13 → 14 taken 34 times.
✓ Branch 13 → 15 taken 1 time.
✓ Branch 15 → 16 taken 34 times.
✓ Branch 15 → 17 taken 1 time.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 22 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 31 not taken.
69 return input.port > 0 ? QStringLiteral("%1:%2").arg(input.host).arg(input.port) : input.host;
21 }
22 // S106-008: every verification error of the presented chain is a
23 // certificate problem (the card shows subject and SHA-256) — the former
24 // allow-list missed real chain errors such as PathLengthExceeded,
25 // CertificateSignatureFailed, InvalidPurpose or a broken validity field.
26 // Only the errors that say nothing about the certificate stay out.
27 10 bool isCertificateError(QSslError::SslError error) {
28
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 9 times.
10 switch (error) {
29 1 case QSslError::NoError:
30 case QSslError::NoSslSupport:
31 case QSslError::UnspecifiedError:
32 1 return false;
33 9 default:
34 9 return true;
35 }
36 }
37 } // namespace
38
39 18 QVariantMap Diagnosis::toMap() const {
40 54 QVariantMap map{{QStringLiteral("kind"), kind}, {QStringLiteral("service"), service},
41 54 {QStringLiteral("message"), message}, {QStringLiteral("action"), action},
42 54 {QStringLiteral("actionLabel"), actionLabel}, {QStringLiteral("field"), field},
43 54 {QStringLiteral("detail"), detail}, {QStringLiteral("helpUrl"), helpUrl},
44
2/4
✓ Branch 40 → 41 taken 162 times.
✓ Branch 40 → 42 taken 18 times.
✗ Branch 109 → 110 not taken.
✗ Branch 109 → 111 not taken.
198 {QStringLiteral("suggestedPort"), suggestedPort}};
45
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 106 taken 18 times.
18 if (!certificate.isEmpty())
46 ✗ map.insert(QStringLiteral("certificate"),
47 ✗ QVariantMap{{QStringLiteral("subject"), certificate.subject}, {QStringLiteral("issuer"), certificate.issuer},
48 ✗ {QStringLiteral("validFrom"), certificate.validFrom}, {QStringLiteral("validTo"), certificate.validTo},
49 ✗ {QStringLiteral("sha256"), certificate.sha256}});
50 18 return map;
51 180 }
52
53 14 QString ConnectionDiagnosis::serviceWord(const QString &service) {
54
2/2
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 7 times.
14 if (service == QLatin1String("imap")) return tr("incoming server");
55
1/2
✓ Branch 8 → 9 taken 7 times.
✗ Branch 8 → 10 not taken.
7 if (service == QLatin1String("smtp")) return tr("outgoing server");
56 ✗ if (service == QLatin1String("sieve")) return tr("rule server");
57 ✗ return tr("calendar and contact server");
58 }
59
60 9 int ConnectionDiagnosis::usualPort(const QString &service) {
61
2/2
✓ Branch 4 → 5 taken 6 times.
✓ Branch 4 → 6 taken 3 times.
9 if (service == QLatin1String("imap")) return 993;
62
1/2
✓ Branch 8 → 9 taken 3 times.
✗ Branch 8 → 10 not taken.
3 if (service == QLatin1String("smtp")) return 465;
63 ✗ if (service == QLatin1String("sieve")) return 4190;
64 ✗ return 443;
65 }
66
67 18 QString ConnectionDiagnosis::appPasswordProvider(const QString &addressOrHost) {
68
2/2
✓ Branch 4 → 5 taken 18 times.
✓ Branch 5 → 6 taken 18 times.
18 const QString domain = addressOrHost.section('@', -1).toLower();
69
5/10
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 21 taken 16 times.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 21 not taken.
✓ Branch 18 → 19 taken 8 times.
✓ Branch 18 → 20 taken 2 times.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
✗ Branch 93 → 94 not taken.
✗ Branch 93 → 95 not taken.
28 static const QStringList google = {"gmail.com", "googlemail.com", "imap.gmail.com", "smtp.gmail.com"};
70 static const QStringList microsoft = {"outlook.com", "hotmail.com", "live.com", "msn.com", "outlook.office365.com",
71
5/10
✓ Branch 21 → 22 taken 2 times.
✓ Branch 21 → 38 taken 16 times.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 38 not taken.
✓ Branch 35 → 36 taken 14 times.
✓ Branch 35 → 37 taken 2 times.
✗ Branch 97 → 98 not taken.
✗ Branch 97 → 99 not taken.
✗ Branch 106 → 107 not taken.
✗ Branch 106 → 108 not taken.
34 "smtp-mail.outlook.com", "smtp.office365.com"};
72
5/10
✓ Branch 38 → 39 taken 2 times.
✓ Branch 38 → 53 taken 16 times.
✓ Branch 40 → 41 taken 2 times.
✗ Branch 40 → 53 not taken.
✓ Branch 50 → 51 taken 10 times.
✓ Branch 50 → 52 taken 2 times.
✗ Branch 110 → 111 not taken.
✗ Branch 110 → 112 not taken.
✗ Branch 119 → 120 not taken.
✗ Branch 119 → 121 not taken.
30 static const QStringList apple = {"icloud.com", "me.com", "mac.com", "imap.mail.me.com", "smtp.mail.me.com"};
73
2/2
✓ Branch 54 → 55 taken 3 times.
✓ Branch 54 → 60 taken 15 times.
21 if (google.contains(domain)) return QStringLiteral("google");
74
2/2
✓ Branch 61 → 62 taken 1 time.
✓ Branch 61 → 67 taken 14 times.
16 if (microsoft.contains(domain)) return QStringLiteral("microsoft");
75
2/2
✓ Branch 68 → 69 taken 1 time.
✓ Branch 68 → 74 taken 13 times.
15 if (apple.contains(domain)) return QStringLiteral("apple");
76 13 return {};
77 24 }
78
79 5 QString ConnectionDiagnosis::appPasswordHelpUrl(const QString &provider) {
80
2/2
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 10 taken 2 times.
8 if (provider == QLatin1String("google")) return QStringLiteral("https://support.google.com/accounts/answer/185833");
81
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 18 taken 1 time.
2 if (provider == QLatin1String("microsoft"))
82 1 return QStringLiteral("https://support.microsoft.com/account-billing/5896ed9b-4263-e681-128a-a6f2979a7944");
83
1/2
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 26 not taken.
2 if (provider == QLatin1String("apple")) return QStringLiteral("https://support.apple.com/102654");
84 ✗ return {};
85 }
86
87 2 QString ConnectionDiagnosis::providerName(const QString &provider) {
88
1/2
✓ Branch 4 → 5 taken 2 times.
✗ Branch 4 → 10 not taken.
4 if (provider == QLatin1String("google")) return QStringLiteral("Google");
89 ✗ if (provider == QLatin1String("microsoft")) return QStringLiteral("Microsoft");
90 ✗ if (provider == QLatin1String("apple")) return QStringLiteral("Apple");
91 ✗ return {};
92 }
93
94 9 CertificateInfo ConnectionDiagnosis::certificateInfo(const QSslCertificate &certificate) {
95 9 CertificateInfo info;
96
3/3
✓ Branch 2 → 3 taken 9 times.
✓ Branch 3 → 4 taken 7 times.
✓ Branch 3 → 5 taken 2 times.
9 if (certificate.isNull()) return info;
97
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 9 → 10 taken 2 times.
4 info.subject = certificate.subjectInfo(QSslCertificate::CommonName).join(QStringLiteral(", "));
98
2/2
✓ Branch 15 → 16 taken 2 times.
✓ Branch 19 → 20 taken 2 times.
4 info.issuer = certificate.issuerInfo(QSslCertificate::CommonName).join(QStringLiteral(", "));
99
1/4
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 38 taken 2 times.
✗ Branch 27 → 28 not taken.
✗ Branch 31 → 32 not taken.
2 if (info.issuer.isEmpty()) info.issuer = certificate.issuerInfo(QSslCertificate::Organization).join(QStringLiteral(", "));
100
4/4
✓ Branch 38 → 39 taken 2 times.
✓ Branch 39 → 40 taken 2 times.
✓ Branch 40 → 41 taken 2 times.
✓ Branch 41 → 42 taken 2 times.
2 info.validFrom = QLocale().toString(certificate.effectiveDate().date(), QLocale::ShortFormat);
101
4/4
✓ Branch 46 → 47 taken 2 times.
✓ Branch 47 → 48 taken 2 times.
✓ Branch 48 → 49 taken 2 times.
✓ Branch 49 → 50 taken 2 times.
2 info.validTo = QLocale().toString(certificate.expiryDate().date(), QLocale::ShortFormat);
102
3/3
✓ Branch 54 → 55 taken 2 times.
✓ Branch 55 → 56 taken 2 times.
✓ Branch 56 → 57 taken 2 times.
2 const QByteArray digest = certificate.digest(QCryptographicHash::Sha256).toHex().toUpper();
103 2 QStringList pairs;
104
5/5
✓ Branch 60 → 61 taken 64 times.
✓ Branch 61 → 62 taken 64 times.
✓ Branch 62 → 63 taken 64 times.
✓ Branch 67 → 60 taken 64 times.
✓ Branch 67 → 68 taken 2 times.
66 for (int i = 0; i < digest.size(); i += 2) pairs << QString::fromLatin1(digest.mid(i, 2));
105
1/1
✓ Branch 70 → 71 taken 2 times.
2 info.sha256 = pairs.join(QLatin1Char(':'));
106 2 return info;
107 2 }
108
109 15 Diagnosis ConnectionDiagnosis::success(const QString &service) {
110 15 Diagnosis result;
111 15 result.kind = QStringLiteral("ok");
112 15 result.service = service;
113 15 return result;
114 }
115
116 9 Diagnosis ConnectionDiagnosis::certificateProblem(const Input &input, const QSslError &error) {
117 9 const QString host = input.host;
118 9 QString message;
119 9 QString action = QStringLiteral("ask-admin");
120
1/1
✓ Branch 7 → 8 taken 9 times.
9 QString label = tr("Ask your administrator");
121
4/6
✓ Branch 8 → 9 taken 9 times.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 25 not taken.
✓ Branch 9 → 32 taken 1 time.
✓ Branch 9 → 58 taken 1 time.
✓ Branch 9 → 65 taken 7 times.
9 switch (error.error()) {
122 ✗ case QSslError::CertificateExpired:
123 ✗ message = tr("The certificate of %1 expired on %2.")
124 ✗ .arg(host, QLocale().toString(error.certificate().expiryDate().date(), QLocale::LongFormat));
125 ✗ break;
126 ✗ case QSslError::CertificateNotYetValid:
127 ✗ message = tr("The certificate of %1 is not valid yet. Check the date and time of this computer.").arg(host);
128 ✗ break;
129 1 case QSslError::HostNameMismatch:
130
1/1
✓ Branch 32 → 33 taken 1 time.
1 message = tr("The certificate of %1 was issued for %2. Check the server name.")
131
4/4
✓ Branch 33 → 34 taken 1 time.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 39 → 40 taken 1 time.
2 .arg(host, error.certificate().subjectInfo(QSslCertificate::CommonName).join(QStringLiteral(", ")));
132 1 action = QStringLiteral("check-server-name");
133
1/1
✓ Branch 54 → 55 taken 1 time.
1 label = tr("Check the server name");
134 1 break;
135 1 case QSslError::SelfSignedCertificate:
136 case QSslError::SelfSignedCertificateInChain:
137
2/2
✓ Branch 58 → 59 taken 1 time.
✓ Branch 60 → 61 taken 1 time.
2 message = tr("The certificate of %1 is self-signed. MailJD only trusts certificates from a known authority.").arg(host);
138 1 break;
139 7 default:
140
2/2
✓ Branch 65 → 66 taken 7 times.
✓ Branch 67 → 68 taken 7 times.
14 message = tr("The certificate of %1 is not from a trusted authority.").arg(host);
141 7 break;
142 }
143
1/1
✓ Branch 78 → 79 taken 9 times.
18 Diagnosis result = make(input, QStringLiteral("tls-certificate"), message, action, label, QStringLiteral("host"));
144
2/2
✓ Branch 83 → 84 taken 9 times.
✓ Branch 84 → 85 taken 9 times.
9 result.certificate = certificateInfo(error.certificate());
145
3/3
✓ Branch 89 → 90 taken 7 times.
✓ Branch 89 → 94 taken 2 times.
✓ Branch 90 → 91 taken 7 times.
9 if (result.detail.isEmpty()) result.detail = error.errorString();
146 9 return result;
147 9 }
148
149 35 Diagnosis ConnectionDiagnosis::diagnose(const Input &input) {
150
1/1
✓ Branch 2 → 3 taken 35 times.
35 const QString where = hostPort(input);
151
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 23 taken 34 times.
35 if (input.offline)
152
3/3
✓ Branch 5 → 6 taken 1 time.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 13 → 14 taken 1 time.
3 return make(input, QStringLiteral("offline"), tr("You are offline."), QStringLiteral("retry"), tr("Try again"), {});
153
2/2
✓ Branch 33 → 25 taken 10 times.
✓ Branch 33 → 34 taken 25 times.
35 for (const auto &error : input.sslErrors)
154
4/4
✓ Branch 26 → 27 taken 10 times.
✓ Branch 28 → 29 taken 9 times.
✓ Branch 28 → 31 taken 1 time.
✓ Branch 29 → 30 taken 9 times.
10 if (isCertificateError(error.error())) return certificateProblem(input, error);
155
2/2
✓ Branch 34 → 35 taken 4 times.
✓ Branch 34 → 60 taken 21 times.
25 if (input.tlsUnavailable)
156 8 return make(input, QStringLiteral("tls-missing"),
157
2/2
✓ Branch 42 → 43 taken 4 times.
✓ Branch 44 → 45 taken 4 times.
12 tr("%1 does not offer an encrypted connection. MailJD does not send passwords unencrypted.").arg(where),
158
2/2
✓ Branch 38 → 39 taken 4 times.
✓ Branch 48 → 49 taken 4 times.
16 QStringLiteral("change-security"), tr("Change server details"), QStringLiteral("security"));
159
2/2
✓ Branch 60 → 61 taken 3 times.
✓ Branch 60 → 81 taken 18 times.
21 if (input.rateLimited) {
160 9 Diagnosis result = make(input, QStringLiteral("rate-limited"),
161
1/1
✓ Branch 66 → 67 taken 3 times.
6 tr("The server refuses new logins for a while. Try again in a few minutes."),
162
2/2
✓ Branch 62 → 63 taken 3 times.
✓ Branch 70 → 71 taken 3 times.
12 QStringLiteral("retry"), tr("Try again"), {});
163 3 result.suggestedPort = 0;
164 3 return result;
165 3 }
166
2/2
✓ Branch 81 → 82 taken 11 times.
✓ Branch 81 → 152 taken 7 times.
18 if (input.authRejected) {
167
2/3
✗ Branch 83 → 84 not taken.
✓ Branch 83 → 85 taken 11 times.
✓ Branch 86 → 87 taken 11 times.
11 const QString provider = appPasswordProvider(input.account.isEmpty() ? input.host : input.account);
168
2/2
✓ Branch 88 → 89 taken 1 time.
✓ Branch 88 → 120 taken 10 times.
11 if (!provider.isEmpty()) {
169 2 Diagnosis result = make(input, QStringLiteral("auth-app-password"),
170
1/1
✓ Branch 96 → 97 taken 1 time.
1 tr("%1 does not accept your normal password here. Create an app password and enter it instead.")
171
2/2
✓ Branch 98 → 99 taken 1 time.
✓ Branch 99 → 100 taken 1 time.
2 .arg(providerName(provider)),
172
2/2
✓ Branch 92 → 93 taken 1 time.
✓ Branch 103 → 104 taken 1 time.
4 QStringLiteral("app-password-help"), tr("How to create one"), QStringLiteral("password"));
173
1/1
✓ Branch 114 → 115 taken 1 time.
1 result.helpUrl = appPasswordHelpUrl(provider);
174 1 return result;
175 1 }
176
1/3
✗ Branch 121 → 122 not taken.
✓ Branch 121 → 123 taken 10 times.
✗ Branch 122 → 124 not taken.
10 const QString who = input.account.isEmpty() ? tr("this account") : input.account;
177 20 return make(input, QStringLiteral("auth"),
178
3/3
✓ Branch 131 → 132 taken 10 times.
✓ Branch 132 → 133 taken 10 times.
✓ Branch 133 → 134 taken 10 times.
20 tr("The %1 did not accept the password for %2.").arg(serviceWord(input.service), who),
179
2/2
✓ Branch 127 → 128 taken 10 times.
✓ Branch 137 → 138 taken 10 times.
40 QStringLiteral("retry"), tr("Try again"), QStringLiteral("password"));
180 11 }
181
2/2
✓ Branch 152 → 153 taken 3 times.
✓ Branch 152 → 189 taken 4 times.
7 if (input.protocolMismatch) {
182 6 Diagnosis result = make(input, QStringLiteral("protocol"),
183
3/3
✓ Branch 163 → 164 taken 3 times.
✓ Branch 164 → 165 taken 3 times.
✓ Branch 165 → 166 taken 3 times.
6 tr("%1 is not a %2. Port %3 is usual.").arg(where, serviceWord(input.service))
184
1/1
✓ Branch 168 → 169 taken 3 times.
6 .arg(usualPort(input.service)),
185
3/3
✓ Branch 156 → 157 taken 3 times.
✓ Branch 159 → 160 taken 3 times.
✓ Branch 172 → 173 taken 3 times.
15 QStringLiteral("use-port"), tr("Use port %1").arg(usualPort(input.service)), QStringLiteral("port"));
186 3 result.suggestedPort = usualPort(input.service);
187 3 return result;
188 3 }
189
2/2
✓ Branch 189 → 190 taken 3 times.
✓ Branch 189 → 268 taken 1 time.
4 if (input.socketFailed) {
190
2/4
✓ Branch 190 → 191 taken 1 time.
✓ Branch 190 → 216 taken 2 times.
✗ Branch 190 → 241 not taken.
✗ Branch 190 → 266 not taken.
3 switch (input.socketError) {
191 1 case QAbstractSocket::HostNotFoundError:
192
2/2
✓ Branch 198 → 199 taken 1 time.
✓ Branch 200 → 201 taken 1 time.
4 return make(input, QStringLiteral("host-not-found"), tr("The server %1 does not exist. Check the name.").arg(input.host),
193
2/2
✓ Branch 194 → 195 taken 1 time.
✓ Branch 204 → 205 taken 1 time.
4 QStringLiteral("change-server"), tr("Change server"), QStringLiteral("host"));
194 2 case QAbstractSocket::ConnectionRefusedError:
195 case QAbstractSocket::SocketTimeoutError:
196 case QAbstractSocket::NetworkError:
197 case QAbstractSocket::RemoteHostClosedError:
198 8 return make(input, QStringLiteral("unreachable"),
199
1/1
✓ Branch 221 → 222 taken 2 times.
2 tr("%1 does not answer on port %2. The server may be down, or a firewall blocks the connection.")
200
2/2
✓ Branch 223 → 224 taken 2 times.
✓ Branch 225 → 226 taken 2 times.
6 .arg(input.host).arg(input.port),
201
2/2
✓ Branch 217 → 218 taken 2 times.
✓ Branch 229 → 230 taken 2 times.
8 QStringLiteral("retry"), tr("Try again"), {});
202 ✗ case QAbstractSocket::SslHandshakeFailedError:
203 ✗ return make(input, QStringLiteral("tls-missing"),
204 ✗ tr("%1 does not offer an encrypted connection. MailJD does not send passwords unencrypted.").arg(where),
205 ✗ QStringLiteral("change-security"), tr("Change server details"), QStringLiteral("security"));
206 ✗ default:
207 ✗ break;
208 }
209 }
210
1/1
✓ Branch 273 → 274 taken 1 time.
5 return make(input, QStringLiteral("server"), tr("The server reported a problem."), QStringLiteral("retry"),
211
2/2
✓ Branch 269 → 270 taken 1 time.
✓ Branch 277 → 278 taken 1 time.
3 tr("Try again"), {});
212 35 }
213