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: 73.6% 215 / 0 / 292
Functions: 64.1% 25 / 0 / 39
Branches: 49.3% 263 / 0 / 534

presentation/AccountSetupSession.cpp
Line Branch Exec Source
1 #include "AccountSetupSession.h"
2 #include "DavAccountSettings.h"
3 #include "DavCollectionDiscovery.h"
4 #include "QuickAccountSettings.h"
5 #include "app/core/AccountSession.h"
6 #include "data/CalendarModels.h"
7 #include "data/ContactModels.h"
8 #include "service/CalDavClient.h"
9 #include "service/CardDavClient.h"
10 #include <QLoggingCategory>
11 #include <QRegularExpression>
12 #include <QTimer>
13 #include <QUrl>
14 #include <memory>
15
16 Q_DECLARE_LOGGING_CATEGORY(lcSettings)
17
18 namespace {
19 // RFC 6764 via the DAV clients: CalDAV first, then CardDAV on the same URL.
20 // F-23: reports authRequired when the host answered 401, so the session can
21 // ask before the mail login is sent to a derived host.
22 795 AccountSetupSession::DavProbe defaultDavProbe() {
23 795 return [](QObject *owner, const QString &serverUrl, const QString &username, const QByteArray &password,
24 std::function<void(bool, QList<CalendarInfo>, QList<AddressBookInfo>, bool)> done) {
25 ✗ auto *calendars = new CalDavClient(serverUrl, username, QString::fromUtf8(password), owner);
26 ✗ auto *books = new CardDavClient(serverUrl, username, QString::fromUtf8(password), owner);
27 ✗ auto state = std::make_shared<QList<CalendarInfo>>();
28 ✗ auto finished = std::make_shared<bool>(false);
29 ✗ const auto report = [done, finished](bool ok, QList<CalendarInfo> c, QList<AddressBookInfo> b,
30 bool authRequired = false) {
31 ✗ if (*finished) return;
32 ✗ *finished = true;
33 ✗ done(ok, c, b, authRequired);
34 ✗ };
35 ✗ QObject::connect(calendars, &CalDavClient::calendarsDiscovered, owner, [books, state](const QList<CalendarInfo> &found) {
36 ✗ *state = found;
37 ✗ books->discoverAddressBooks();
38 ✗ });
39 ✗ QObject::connect(calendars, &CalDavClient::syncFailed, owner, [calendars, report](const QString &) {
40 ✗ report(false, {}, {}, calendars->lastNetworkError() ==
41 QNetworkReply::AuthenticationRequiredError);
42 ✗ });
43 ✗ QObject::connect(books, &CardDavClient::addressBooksDiscovered, owner,
44 ✗ [report, state](const QList<AddressBookInfo> &found) { report(true, *state, found); });
45 ✗ QObject::connect(books, &CardDavClient::syncFailed, owner, [books, report, state](const QString &) {
46 ✗ report(!state->isEmpty(), *state, {},
47 ✗ books->lastNetworkError() == QNetworkReply::AuthenticationRequiredError);
48 ✗ });
49 ✗ QTimer::singleShot(10000, owner, [report] { report(false, {}, {}); });
50 ✗ calendars->discoverCalendars();
51 795 };
52 }
53
54 2 QString contentKind(const QStringList &components) {
55
7/8
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 9 taken 1 time.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 10 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 1 time.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 15 taken 1 time.
3 const bool events = components.isEmpty() || components.contains(QStringLiteral("VEVENT"));
56 2 const bool tasks = components.contains(QStringLiteral("VTODO"));
57
3/4
✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 28 not taken.
✓ Branch 22 → 23 taken 1 time.
✓ Branch 22 → 28 taken 1 time.
3 if (events && tasks) return QStringLiteral("both");
58
3/6
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 32 taken 1 time.
✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 38 not taken.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 1 time.
3 return tasks ? QStringLiteral("tasks") : QStringLiteral("calendar");
59 }
60 } // namespace
61
62 795 AccountSetupSession::AccountSetupSession(QuickAccountSettings *settings, AccountSession *accounts, QObject *parent)
63
1/1
✓ Branch 4 → 5 taken 795 times.
795 : QObject(parent), m_settings(settings), m_accounts(accounts), m_check(accounts), m_davProbe(defaultDavProbe()),
64
1/1
✓ Branch 3 → 4 taken 795 times.
3180 m_saver([settings](const QVariantMap &fields) { return settings->saveAccountAsync(fields); }) {
65
1/1
✓ Branch 30 → 31 taken 795 times.
795 connect(&m_discovery, &MailServerDiscovery::sourcesChanged, this, &AccountSetupSession::changed);
66
1/1
✓ Branch 32 → 33 taken 795 times.
795 connect(&m_discovery, &MailServerDiscovery::finished, this, &AccountSetupSession::discoveryFinished);
67
1/1
✓ Branch 34 → 35 taken 795 times.
795 connect(&m_check, &AccountServiceCheck::changed, this, &AccountSetupSession::changed);
68
1/1
✓ Branch 36 → 37 taken 795 times.
795 connect(&m_check, &AccountServiceCheck::finished, this, [this](const QString &id, const QVariantMap &result) {
69
1/2
✓ Branch 3 → 4 taken 7 times.
✗ Branch 3 → 5 not taken.
7 if (id == m_checkId) checked(result);
70 7 });
71 795 connect(m_settings, &QuickAccountSettings::accountSaveFinished, this,
72
3/3
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 5 taken 2 times.
✓ Branch 38 → 39 taken 795 times.
801 [this](const QString &id, const QVariantMap &result) { if (id == m_saveId) saved(result); });
73 795 }
74
75 795 AccountSetupSession::~AccountSetupSession() { m_password.fill('\0'); }
76
77 ✗ bool AccountSetupSession::busy() const {
78 ✗ return m_state == QLatin1String("discovering") || m_state == QLatin1String("testing") ||
79 ✗ m_state == QLatin1String("saving") || m_davState == QLatin1String("searching");
80 }
81
82 38 void AccountSetupSession::setState(const QString &state, const QString &message) {
83 38 m_state = state;
84 38 m_message = message;
85
6/6
✓ Branch 4 → 5 taken 38 times.
✓ Branch 8 → 9 taken 38 times.
✓ Branch 9 → 10 taken 38 times.
✓ Branch 10 → 11 taken 38 times.
✓ Branch 14 → 6 taken 38 times.
✓ Branch 14 → 15 taken 38 times.
76 qCInfo(lcSettings) << "setup step" << state;
86 38 emit changed();
87 38 }
88
89 3 QVariantMap AccountSetupSession::providerHint(const QString &address) const {
90
2/2
✓ Branch 2 → 3 taken 3 times.
✓ Branch 3 → 4 taken 3 times.
3 const QString provider = ConnectionDiagnosis::appPasswordProvider(address.trimmed());
91
2/2
✓ Branch 6 → 7 taken 2 times.
✓ Branch 6 → 8 taken 1 time.
3 if (provider.isEmpty()) return {};
92
1/1
✓ Branch 15 → 16 taken 1 time.
3 return {{QStringLiteral("provider"), provider}, {QStringLiteral("name"), ConnectionDiagnosis::providerName(provider)},
93
3/5
✓ Branch 20 → 21 taken 1 time.
✓ Branch 24 → 25 taken 3 times.
✓ Branch 24 → 26 taken 1 time.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
6 {QStringLiteral("helpUrl"), ConnectionDiagnosis::appPasswordHelpUrl(provider)}};
94 7 }
95
96 11 QString AccountSetupSession::begin(const QString &name, const QString &address, const QString &password) {
97
4/7
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 15 taken 10 times.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 15 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 105 → 106 not taken.
✗ Branch 105 → 107 not taken.
12 static const QRegularExpression valid(QStringLiteral("^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$"));
98
1/1
✓ Branch 15 → 16 taken 11 times.
11 const QString trimmed = address.trimmed();
99
5/5
✓ Branch 17 → 18 taken 11 times.
✓ Branch 18 → 19 taken 11 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 23 taken 10 times.
✓ Branch 21 → 22 taken 1 time.
11 if (!valid.match(trimmed).hasMatch()) return tr("Enter an email address such as name@example.org.");
100
1/2
✓ Branch 23 → 24 taken 10 times.
✗ Branch 23 → 55 not taken.
10 if (m_accounts)
101
4/4
✓ Branch 25 → 26 taken 10 times.
✓ Branch 26 → 27 taken 10 times.
✓ Branch 48 → 28 taken 10 times.
✓ Branch 48 → 49 taken 9 times.
19 for (const auto &entry : m_accounts->configurationMetadata())
102
5/5
✓ Branch 29 → 30 taken 10 times.
✓ Branch 34 → 35 taken 10 times.
✓ Branch 35 → 36 taken 10 times.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 46 taken 9 times.
20 if (entry.toMap().value(QStringLiteral("email")).toString().compare(trimmed, Qt::CaseInsensitive) == 0)
103
3/3
✓ Branch 44 → 45 taken 1 time.
✓ Branch 51 → 52 taken 9 times.
✓ Branch 51 → 54 taken 1 time.
10 return tr("This address is already set up.");
104
3/3
✓ Branch 56 → 57 taken 1 time.
✓ Branch 56 → 59 taken 8 times.
✓ Branch 57 → 58 taken 1 time.
9 if (password.isEmpty()) return tr("Enter the password.");
105
1/1
✓ Branch 59 → 60 taken 8 times.
8 cancel();
106
5/5
✓ Branch 60 → 61 taken 8 times.
✓ Branch 62 → 63 taken 4 times.
✓ Branch 62 → 66 taken 4 times.
✓ Branch 65 → 67 taken 4 times.
✓ Branch 66 → 67 taken 4 times.
12 m_name = name.trimmed().isEmpty() ? trimmed.section('@', 0, 0) : name.trimmed();
107 8 m_address = trimmed;
108
1/1
✓ Branch 71 → 72 taken 8 times.
8 m_password = password.toUtf8();
109
1/1
✓ Branch 74 → 75 taken 8 times.
8 m_servers.clear();
110
1/1
✓ Branch 75 → 76 taken 8 times.
8 m_incoming.clear();
111
1/1
✓ Branch 76 → 77 taken 8 times.
8 m_outgoing.clear();
112 8 m_skipOutgoing = false;
113 8 m_accountId.clear();
114 8 m_davState = QStringLiteral("idle");
115
1/1
✓ Branch 84 → 85 taken 8 times.
8 m_collections.clear();
116
1/1
✓ Branch 89 → 90 taken 8 times.
16 setState(QStringLiteral("discovering"));
117
1/1
✓ Branch 93 → 94 taken 8 times.
8 m_discovery.start(trimmed);
118 8 return {};
119 11 }
120
121 ✗ void AccountSetupSession::lookupIspdb() {
122 ✗ setState(QStringLiteral("discovering"));
123 ✗ m_discovery.lookupIspdb();
124 ✗ }
125
126 8 void AccountSetupSession::discoveryFinished(bool found) {
127
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 8 times.
8 if (m_state != QLatin1String("discovering")) return;
128 8 const auto best = m_discovery.best();
129 24 m_servers = {{QStringLiteral("imapHost"), best.imap.host}, {QStringLiteral("imapPort"), best.imap.port},
130
4/6
✓ Branch 19 → 20 taken 7 times.
✓ Branch 19 → 21 taken 1 time.
✓ Branch 85 → 86 taken 1 time.
✓ Branch 85 → 87 taken 7 times.
✗ Branch 192 → 193 not taken.
✗ Branch 192 → 194 not taken.
17 {QStringLiteral("imapSecurity"), best.imap.valid() ? best.imap.security : QStringLiteral("ssl")},
131 16 {QStringLiteral("smtpHost"), best.smtp.host},
132
2/2
✓ Branch 33 → 34 taken 7 times.
✓ Branch 33 → 35 taken 1 time.
16 {QStringLiteral("smtpPort"), best.smtp.valid() ? best.smtp.port : 465},
133
4/6
✓ Branch 41 → 42 taken 7 times.
✓ Branch 41 → 43 taken 1 time.
✓ Branch 76 → 77 taken 1 time.
✓ Branch 76 → 78 taken 7 times.
✗ Branch 166 → 167 not taken.
✗ Branch 166 → 168 not taken.
17 {QStringLiteral("smtpSecurity"), best.smtp.valid() ? best.smtp.security : QStringLiteral("ssl")},
134 16 {QStringLiteral("username"), best.imap.username.isEmpty() ? m_address : best.imap.username},
135
2/4
✓ Branch 67 → 68 taken 72 times.
✓ Branch 67 → 69 taken 8 times.
✗ Branch 143 → 144 not taken.
✗ Branch 143 → 145 not taken.
96 {QStringLiteral("trusted"), best.trusted}, {QStringLiteral("source"), best.source}};
136
1/1
✓ Branch 95 → 96 taken 8 times.
8 const QString domain = m_address.section('@', 1);
137
2/2
✓ Branch 96 → 97 taken 1 time.
✓ Branch 96 → 109 taken 7 times.
8 if (!found)
138
1/1
✓ Branch 103 → 104 taken 1 time.
1 setState(QStringLiteral("manual"),
139
2/2
✓ Branch 97 → 98 taken 1 time.
✓ Branch 99 → 100 taken 1 time.
3 tr("MailJD could not find the servers of %1. Enter them from your provider's instructions.").arg(domain));
140
1/2
✗ Branch 110 → 111 not taken.
✓ Branch 110 → 123 taken 7 times.
7 else if (!best.complete())
141 ✗ setState(QStringLiteral("manual"), tr("MailJD found the incoming server of %1 but not the outgoing one.").arg(domain));
142
2/2
✓ Branch 123 → 124 taken 1 time.
✓ Branch 123 → 136 taken 6 times.
7 else if (!best.trusted)
143
1/1
✓ Branch 130 → 131 taken 1 time.
1 setState(QStringLiteral("review"),
144
2/2
✓ Branch 124 → 125 taken 1 time.
✓ Branch 126 → 127 taken 1 time.
3 tr("These servers do not belong to %1. Continue only if your provider told you to use them.").arg(domain));
145 else
146
1/1
✓ Branch 136 → 137 taken 6 times.
6 check();
147 88 }
148
149 ✗ void AccountSetupSession::useServers() {
150 ✗ if (m_state == QLatin1String("review")) check();
151 ✗ }
152
153 ✗ void AccountSetupSession::useManual(const QVariantMap &fields) {
154 ✗ for (const auto *key : {"imapHost", "imapPort", "imapSecurity", "smtpHost", "smtpPort", "smtpSecurity", "username",
155 ✗ "smtpLogin", "smtpUsername"})
156 ✗ if (fields.contains(QLatin1String(key))) m_servers.insert(QLatin1String(key), fields.value(QLatin1String(key)));
157 ✗ if (fields.contains(QStringLiteral("smtpPassword")))
158 ✗ m_servers.insert(QStringLiteral("smtpPassword"), fields.value(QStringLiteral("smtpPassword")));
159 ✗ check();
160 ✗ }
161
162 12 QVariantMap AccountSetupSession::accountFields() const {
163
2/2
✓ Branch 10 → 11 taken 12 times.
✓ Branch 11 → 12 taken 12 times.
36 const bool shared = m_servers.value(QStringLiteral("smtpLogin"), QStringLiteral("imap")).toString() == QLatin1String("imap");
164
2/2
✓ Branch 24 → 25 taken 12 times.
✓ Branch 25 → 26 taken 12 times.
24 const QString username = m_servers.value(QStringLiteral("username")).toString();
165
1/1
✓ Branch 30 → 31 taken 12 times.
12 const QString password = QString::fromUtf8(m_password);
166 36 return {{QStringLiteral("name"), m_name}, {QStringLiteral("email"), m_address},
167
1/1
✓ Branch 46 → 47 taken 12 times.
36 {QStringLiteral("imapHost"), m_servers.value(QStringLiteral("imapHost"))},
168
1/1
✓ Branch 55 → 56 taken 12 times.
36 {QStringLiteral("imapPort"), m_servers.value(QStringLiteral("imapPort"))},
169
1/1
✓ Branch 64 → 65 taken 12 times.
36 {QStringLiteral("imapSecurity"), m_servers.value(QStringLiteral("imapSecurity"))},
170 36 {QStringLiteral("imapUsername"), username}, {QStringLiteral("imapPassword"), password},
171
1/1
✓ Branch 81 → 82 taken 12 times.
36 {QStringLiteral("smtpHost"), m_servers.value(QStringLiteral("smtpHost"))},
172
1/1
✓ Branch 90 → 91 taken 12 times.
36 {QStringLiteral("smtpPort"), m_servers.value(QStringLiteral("smtpPort"))},
173
1/1
✓ Branch 99 → 100 taken 12 times.
36 {QStringLiteral("smtpSecurity"), m_servers.value(QStringLiteral("smtpSecurity"))},
174
3/10
✓ Branch 104 → 105 taken 12 times.
✗ Branch 104 → 108 not taken.
✗ Branch 163 → 164 not taken.
✓ Branch 163 → 165 taken 12 times.
✓ Branch 165 → 166 taken 12 times.
✗ Branch 165 → 167 not taken.
✗ Branch 305 → 306 not taken.
✗ Branch 305 → 307 not taken.
✗ Branch 309 → 310 not taken.
✗ Branch 309 → 311 not taken.
36 {QStringLiteral("smtpLogin"), shared ? QStringLiteral("imap") : QStringLiteral("separate")},
175
5/20
✓ Branch 115 → 116 taken 12 times.
✗ Branch 115 → 117 not taken.
✗ Branch 121 → 122 not taken.
✗ Branch 122 → 123 not taken.
✗ Branch 152 → 153 not taken.
✓ Branch 152 → 154 taken 12 times.
✗ Branch 154 → 155 not taken.
✓ Branch 154 → 156 taken 12 times.
✗ Branch 156 → 157 not taken.
✓ Branch 156 → 158 taken 12 times.
✗ Branch 158 → 159 not taken.
✓ Branch 158 → 160 taken 12 times.
✗ Branch 280 → 281 not taken.
✗ Branch 280 → 282 not taken.
✗ Branch 284 → 285 not taken.
✗ Branch 284 → 286 not taken.
✗ Branch 288 → 289 not taken.
✗ Branch 288 → 290 not taken.
✗ Branch 292 → 293 not taken.
✗ Branch 292 → 294 not taken.
24 {QStringLiteral("smtpUsername"), shared ? username : m_servers.value(QStringLiteral("smtpUsername")).toString()},
176
7/24
✓ Branch 127 → 128 taken 12 times.
✗ Branch 127 → 129 not taken.
✗ Branch 133 → 134 not taken.
✗ Branch 134 → 135 not taken.
✓ Branch 138 → 139 taken 156 times.
✓ Branch 138 → 140 taken 12 times.
✗ Branch 141 → 142 not taken.
✓ Branch 141 → 143 taken 12 times.
✗ Branch 143 → 144 not taken.
✓ Branch 143 → 145 taken 12 times.
✗ Branch 145 → 146 not taken.
✓ Branch 145 → 147 taken 12 times.
✗ Branch 147 → 148 not taken.
✓ Branch 147 → 149 taken 12 times.
✗ Branch 250 → 251 not taken.
✗ Branch 250 → 252 not taken.
✗ Branch 255 → 256 not taken.
✗ Branch 255 → 257 not taken.
✗ Branch 259 → 260 not taken.
✗ Branch 259 → 261 not taken.
✗ Branch 263 → 264 not taken.
✗ Branch 263 → 265 not taken.
✗ Branch 267 → 268 not taken.
✗ Branch 267 → 269 not taken.
192 {QStringLiteral("smtpPassword"), shared ? password : m_servers.value(QStringLiteral("smtpPassword")).toString()}};
177 180 }
178
179 7 void AccountSetupSession::check() {
180
1/1
✓ Branch 6 → 7 taken 7 times.
14 setState(QStringLiteral("testing"));
181
1/1
✓ Branch 10 → 11 taken 7 times.
7 QVariantMap fields = accountFields();
182
1/1
✓ Branch 15 → 16 taken 7 times.
14 fields.insert(QStringLiteral("checkOutgoing"), !m_skipOutgoing);
183
1/1
✓ Branch 19 → 20 taken 7 times.
7 m_checkId = m_check.check(fields);
184 7 }
185
186 7 void AccountSetupSession::checked(const QVariantMap &result) {
187
2/2
✓ Branch 6 → 7 taken 7 times.
✓ Branch 7 → 8 taken 7 times.
14 m_incoming = result.value(QStringLiteral("incoming")).toMap();
188
2/2
✓ Branch 18 → 19 taken 7 times.
✓ Branch 19 → 20 taken 7 times.
14 m_outgoing = result.value(QStringLiteral("outgoing")).toMap();
189
2/2
✓ Branch 31 → 32 taken 7 times.
✓ Branch 32 → 33 taken 7 times.
14 const bool incomingOk = m_incoming.value(QStringLiteral("kind")).toString() == QLatin1String("ok");
190
3/3
✓ Branch 39 → 40 taken 1 time.
✓ Branch 39 → 49 taken 6 times.
✓ Branch 44 → 45 taken 1 time.
8 if (!incomingOk) { setState(QStringLiteral("failed")); return; }
191
12/25
✓ Branch 53 → 54 taken 6 times.
✓ Branch 54 → 55 taken 6 times.
✓ Branch 55 → 56 taken 2 times.
✓ Branch 55 → 58 taken 4 times.
✓ Branch 56 → 57 taken 2 times.
✗ Branch 56 → 58 not taken.
✓ Branch 59 → 60 taken 6 times.
✗ Branch 59 → 61 not taken.
✓ Branch 61 → 62 taken 6 times.
✗ Branch 61 → 63 not taken.
✓ Branch 63 → 64 taken 6 times.
✗ Branch 63 → 65 not taken.
✓ Branch 65 → 66 taken 6 times.
✗ Branch 65 → 67 not taken.
✓ Branch 67 → 68 taken 2 times.
✓ Branch 67 → 77 taken 4 times.
✓ Branch 72 → 73 taken 2 times.
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 130 not taken.
✗ Branch 132 → 133 not taken.
✗ Branch 132 → 134 not taken.
✗ Branch 136 → 137 not taken.
✗ Branch 136 → 138 not taken.
✗ Branch 140 → 141 not taken.
✗ Branch 140 → 142 not taken.
14 if (!result.value(QStringLiteral("ok")).toBool() && !m_skipOutgoing) { setState(QStringLiteral("outgoing")); return; }
192 4 save();
193 }
194
195 1 void AccountSetupSession::retry(const QString &password) {
196
2/3
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 8 not taken.
✓ Branch 4 → 5 taken 1 time.
1 if (!password.isEmpty()) m_password = password.toUtf8();
197 1 check();
198 1 }
199
200 1 void AccountSetupSession::continueWithoutSending() {
201 1 m_skipOutgoing = true;
202 1 save();
203 1 }
204
205 5 void AccountSetupSession::save() {
206
1/1
✓ Branch 6 → 7 taken 5 times.
10 setState(QStringLiteral("saving"));
207
2/2
✓ Branch 10 → 11 taken 5 times.
✓ Branch 11 → 12 taken 5 times.
5 const QVariantMap result = m_saver(accountFields());
208
3/4
✓ Branch 17 → 18 taken 5 times.
✓ Branch 18 → 19 taken 5 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 42 taken 5 times.
10 if (!result.value(QStringLiteral("ok")).toBool()) {
209 ✗ setState(QStringLiteral("failed"), result.value(QStringLiteral("error")).toString());
210 ✗ return;
211 }
212
2/2
✓ Branch 46 → 47 taken 5 times.
✓ Branch 47 → 48 taken 5 times.
10 m_saveId = result.value(QStringLiteral("requestId")).toString();
213 5 }
214
215 4 void AccountSetupSession::saved(const QVariantMap &result) {
216
3/4
✓ Branch 6 → 7 taken 4 times.
✓ Branch 7 → 8 taken 4 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 31 taken 4 times.
8 if (!result.value(QStringLiteral("ok")).toBool()) {
217 ✗ setState(QStringLiteral("failed"), result.value(QStringLiteral("error")).toString());
218 ✗ return;
219 }
220
2/2
✓ Branch 35 → 36 taken 4 times.
✓ Branch 36 → 37 taken 4 times.
8 m_accountId = result.value(QStringLiteral("id")).toString();
221
1/1
✓ Branch 47 → 48 taken 4 times.
8 setState(QStringLiteral("services"));
222 4 findCalendars();
223 }
224
225 4 void AccountSetupSession::findCalendars() {
226
2/2
✓ Branch 4 → 5 taken 4 times.
✓ Branch 5 → 6 taken 4 times.
4 const QString domain = m_address.section('@', 1).toLower();
227
2/2
✓ Branch 11 → 12 taken 4 times.
✓ Branch 12 → 13 taken 4 times.
8 const QString imapHost = m_servers.value(QStringLiteral("imapHost")).toString();
228
2/4
✓ Branch 27 → 28 taken 8 times.
✓ Branch 27 → 29 taken 4 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
20 m_davCandidates = {QStringLiteral("https://") + domain, QStringLiteral("https://dav.") + domain};
229 // F-23: derived hosts (bare domain, dav.<domain>) are probed without
230 // credentials first; only the autoconfig-named IMAP host — which already
231 // receives the mail login — gets the credentials right away.
232 4 m_davTrustedCount = m_davCandidates.size();
233
6/9
✓ Branch 35 → 36 taken 4 times.
✗ Branch 35 → 39 not taken.
✓ Branch 36 → 37 taken 4 times.
✓ Branch 37 → 38 taken 4 times.
✗ Branch 37 → 39 not taken.
✓ Branch 40 → 41 taken 4 times.
✗ Branch 40 → 50 not taken.
✓ Branch 44 → 45 taken 4 times.
✓ Branch 45 → 46 taken 4 times.
8 if (!imapHost.isEmpty() && !imapHost.endsWith(domain)) m_davCandidates << QStringLiteral("https://") + imapHost;
234 4 m_davIndex = 0;
235 4 m_davHost.clear();
236 4 m_davState = QStringLiteral("searching");
237
1/1
✓ Branch 57 → 58 taken 4 times.
4 emit changed();
238
1/1
✓ Branch 58 → 59 taken 4 times.
4 tryDav(0, false);
239 16 }
240
241 12 void AccountSetupSession::tryDav(int index, bool withCredentials) {
242
2/2
✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 12 taken 10 times.
12 if (index >= m_davCandidates.size()) {
243 2 m_davState = QStringLiteral("none");
244
1/1
✓ Branch 10 → 11 taken 2 times.
2 emit changed();
245 2 return;
246 }
247 10 m_davIndex = index;
248
3/3
✓ Branch 13 → 14 taken 6 times.
✓ Branch 13 → 16 taken 4 times.
✓ Branch 15 → 16 taken 6 times.
10 if (m_davRun) m_davRun->deleteLater();
249
4/7
✓ Branch 16 → 17 taken 10 times.
✓ Branch 17 → 18 taken 10 times.
✓ Branch 18 → 19 taken 10 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 10 times.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
10 m_davRun = new QObject(this);
250 10 QPointer<QObject> run(m_davRun);
251 10 const QString url = m_davCandidates.at(index);
252 10 const bool trusted = index >= m_davTrustedCount;
253
2/2
✓ Branch 25 → 26 taken 2 times.
✓ Branch 25 → 33 taken 6 times.
8 const QString username = withCredentials || trusted
254
9/17
✓ Branch 30 → 31 taken 4 times.
✓ Branch 34 → 35 taken 4 times.
✓ Branch 34 → 36 taken 6 times.
✓ Branch 36 → 37 taken 4 times.
✓ Branch 36 → 38 taken 6 times.
✓ Branch 38 → 39 taken 4 times.
✓ Branch 38 → 40 taken 6 times.
✓ Branch 40 → 41 taken 4 times.
✓ Branch 40 → 42 taken 6 times.
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 64 not taken.
✗ Branch 66 → 67 not taken.
✗ Branch 66 → 68 not taken.
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 72 not taken.
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 76 not taken.
18 ? m_servers.value(QStringLiteral("username")).toString()
255
3/3
✓ Branch 24 → 25 taken 8 times.
✓ Branch 24 → 26 taken 2 times.
✓ Branch 31 → 32 taken 4 times.
20 : QString();
256
4/4
✓ Branch 42 → 43 taken 8 times.
✓ Branch 42 → 44 taken 2 times.
✓ Branch 43 → 44 taken 2 times.
✓ Branch 43 → 45 taken 6 times.
10 const QByteArray password = withCredentials || trusted ? m_password : QByteArray();
257
1/1
✓ Branch 50 → 51 taken 10 times.
10 m_davProbe(m_davRun, url, username, password,
258
1/5
✓ Branch 48 → 49 taken 10 times.
✗ Branch 82 → 83 not taken.
✗ Branch 82 → 84 not taken.
✗ Branch 85 → 86 not taken.
✗ Branch 85 → 87 not taken.
20 [this, run, index, url, withCredentials](bool ok, const QList<CalendarInfo> &calendars,
259 const QList<AddressBookInfo> &books, bool authRequired) {
260 // S106-229: an older probe's answer (its run only queued for deletion)
261 // must not drive the chain the newer probe owns now.
262
3/6
✓ Branch 3 → 4 taken 9 times.
✗ Branch 3 → 6 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 9 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 9 times.
9 if (!run || run != m_davRun) return;
263 // A derived host wants the login: never send it silently (F-23). Show
264 // the host and let the user answer with authorizeDavHost()/skipDavHost().
265
6/8
✓ Branch 10 → 11 taken 8 times.
✓ Branch 10 → 28 taken 1 time.
✓ Branch 11 → 12 taken 3 times.
✓ Branch 11 → 28 taken 5 times.
✓ Branch 12 → 13 taken 3 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 3 times.
✗ Branch 13 → 28 not taken.
9 if (!ok && authRequired && !withCredentials && index < m_davTrustedCount) {
266 3 m_davIndex = index;
267
2/2
✓ Branch 14 → 15 taken 3 times.
✓ Branch 16 → 17 taken 3 times.
6 m_davHost = QUrl(url).host();
268 3 m_davState = QStringLiteral("confirm");
269 3 emit changed();
270 3 return;
271 }
272
5/8
✓ Branch 28 → 29 taken 1 time.
✓ Branch 28 → 33 taken 5 times.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 34 taken 1 time.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
✓ Branch 35 → 36 taken 5 times.
✓ Branch 35 → 38 taken 1 time.
6 if (!ok || (calendars.isEmpty() && books.isEmpty())) { tryDav(index + 1, false); return; }
273 1 m_davServer = url;
274 1 m_davHost.clear();
275 1 m_collections.clear();
276
2/2
✓ Branch 59 → 43 taken 2 times.
✓ Branch 59 → 60 taken 1 time.
3 for (const auto &calendar : calendars) {
277
1/1
✓ Branch 44 → 45 taken 2 times.
2 const QString reason = DavCollectionDiscovery::defaultOffReason(calendar.path, true);
278 2 m_collections.append({calendar.path, calendar.displayName.isEmpty() ? calendar.path : calendar.displayName,
279 4 contentKind(calendar.supportedComponents), reason, reason.isEmpty(), true});
280 2 }
281
2/2
✓ Branch 81 → 62 taken 2 times.
✓ Branch 81 → 82 taken 1 time.
3 for (const auto &book : books) {
282
1/1
✓ Branch 63 → 64 taken 2 times.
2 const QString reason = DavCollectionDiscovery::defaultOffReason(book.path, false);
283 2 m_collections.append({book.path, book.displayName.isEmpty() ? book.path : book.displayName, QStringLiteral("book"),
284 2 reason, reason.isEmpty(), false});
285 2 }
286 1 m_davState = QStringLiteral("found");
287
6/6
✓ Branch 88 → 89 taken 1 time.
✓ Branch 92 → 93 taken 1 time.
✓ Branch 93 → 94 taken 1 time.
✓ Branch 95 → 96 taken 1 time.
✓ Branch 99 → 90 taken 1 time.
✓ Branch 99 → 100 taken 1 time.
2 qCInfo(lcSettings) << "setup found calendars and contacts" << m_collections.size();
288 1 emit changed();
289
5/23
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 2 times.
✓ Branch 51 → 52 taken 2 times.
✓ Branch 54 → 55 taken 2 times.
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 68 taken 2 times.
✓ Branch 75 → 76 taken 2 times.
✗ Branch 109 → 110 not taken.
✗ Branch 109 → 111 not taken.
✗ Branch 112 → 113 not taken.
✗ Branch 112 → 114 not taken.
✗ Branch 115 → 116 not taken.
✗ Branch 115 → 117 not taken.
✗ Branch 118 → 119 not taken.
✗ Branch 118 → 120 not taken.
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 130 not taken.
✗ Branch 131 → 132 not taken.
✗ Branch 131 → 133 not taken.
✗ Branch 137 → 138 not taken.
✗ Branch 137 → 139 not taken.
✗ Branch 140 → 141 not taken.
✗ Branch 140 → 142 not taken.
6 });
290 10 }
291
292 2 void AccountSetupSession::authorizeDavHost() {
293
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 2 times.
2 if (m_davState != QLatin1String("confirm")) return;
294 2 m_davState = QStringLiteral("searching");
295 2 emit changed();
296 2 tryDav(m_davIndex, true);
297 }
298
299 1 void AccountSetupSession::skipDavHost() {
300
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 1 time.
1 if (m_davState != QLatin1String("confirm")) return;
301 1 m_davHost.clear();
302 1 m_davState = QStringLiteral("searching");
303 1 emit changed();
304 1 tryDav(m_davIndex + 1, false);
305 }
306
307 3 QVariantList AccountSetupSession::collections() const {
308 3 QVariantList list;
309
2/2
✓ Branch 45 → 4 taken 4 times.
✓ Branch 45 → 46 taken 3 times.
7 for (const auto &item : m_collections)
310
1/1
✓ Branch 27 → 28 taken 4 times.
16 list.append(QVariantMap{{QStringLiteral("key"), item.key}, {QStringLiteral("name"), item.name},
311 12 {QStringLiteral("kind"), item.kind}, {QStringLiteral("selected"), item.selected},
312
2/4
✓ Branch 31 → 32 taken 20 times.
✓ Branch 31 → 33 taken 4 times.
✗ Branch 53 → 54 not taken.
✗ Branch 53 → 55 not taken.
32 {QStringLiteral("reason"), item.reason}});
313 3 return list;
314 24 }
315
316 ✗ void AccountSetupSession::setCollection(const QString &key, bool selected) {
317 ✗ for (auto &item : m_collections)
318 ✗ if (item.key == key) item.selected = selected;
319 ✗ emit changed();
320 ✗ }
321
322 1 void AccountSetupSession::finish(bool withCalendars) {
323
2/6
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 1 time.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 20 not taken.
1 if (!withCalendars || m_davState != QLatin1String("found")) {
324
1/1
✓ Branch 9 → 10 taken 1 time.
1 m_password.fill('\0');
325
1/1
✓ Branch 14 → 15 taken 1 time.
2 setState(QStringLiteral("done"));
326
1/1
✓ Branch 18 → 19 taken 1 time.
1 emit done(m_accountId);
327 1 return;
328 }
329 ✗ setState(QStringLiteral("saving"));
330 ✗ const QVariantMap fields{{QStringLiteral("serverUrl"), m_davServer},
331 ✗ {QStringLiteral("username"), m_servers.value(QStringLiteral("username"))},
332 ✗ {QStringLiteral("password"), QString::fromUtf8(m_password)},
333 ✗ {QStringLiteral("mailAccountId"), m_accountId}};
334 ✗ QPointer<AccountSetupSession> guard(this);
335 ✗ DavAccountSettings::saveAsync(this, fields, [guard](const QVariantMap &result) {
336 ✗ if (!guard) return;
337 ✗ const QString id = result.value(QStringLiteral("id")).toString();
338 ✗ if (result.value(QStringLiteral("ok")).toBool()) {
339 ✗ QStringList calendars, books;
340 ✗ for (const auto &item : guard->m_collections)
341 ✗ if (item.selected) (item.calendar ? calendars : books).append(item.key);
342 ✗ for (const auto &account : DavAccountSettings::accounts())
343 ✗ if (account.id == id)
344 ✗ DavAccountSettings::storeSelections(account, {id, {}, {}}, books, calendars);
345 ✗ guard->m_settings->notifyDavChanged(id);
346 ✗ }
347 ✗ guard->m_password.fill('\0');
348 ✗ guard->setState(QStringLiteral("done"), result.value(QStringLiteral("ok")).toBool()
349 ✗ ? QString() : result.value(QStringLiteral("error")).toString());
350 ✗ emit guard->done(guard->m_accountId);
351 ✗ });
352 ✗ }
353
354 28 void AccountSetupSession::cancel() {
355 28 m_discovery.cancel();
356 28 m_check.cancel();
357
2/2
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 8 taken 24 times.
28 if (m_davRun) m_davRun->deleteLater();
358 28 m_davRun = nullptr;
359 28 m_davHost.clear();
360 28 m_davState = QStringLiteral("idle");
361 28 m_password.fill('\0');
362
3/3
✓ Branch 19 → 20 taken 8 times.
✓ Branch 19 → 29 taken 20 times.
✓ Branch 24 → 25 taken 8 times.
36 if (m_state != QLatin1String("address")) setState(QStringLiteral("address"));
363 28 }
364