File indexing completed on 2024-11-17 04:45:08

0001 /*
0002     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0003     SPDX-FileContributor: Kevin Ottens <kevin@kdab.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "resourcestateinterface.h"
0009 #include "imapresource_debug.h"
0010 
0011 ResourceStateInterface::~ResourceStateInterface() = default;
0012 
0013 QString ResourceStateInterface::mailBoxForCollection(const Akonadi::Collection &collection, bool showWarnings)
0014 {
0015     if (collection.remoteId().isEmpty()) { // This should never happen, investigate why a collection without remoteId made it this far
0016         if (showWarnings) {
0017             qCWarning(IMAPRESOURCE_LOG) << "Got incomplete ancestor chain due to empty remoteId:" << collection;
0018         }
0019         return {};
0020     }
0021 
0022     if (collection.parentCollection() == Akonadi::Collection::root()) {
0023         /*if ( showWarnings  && collection.remoteId() != rootRemoteId())
0024           qCWarning(IMAPRESOURCE_LOG) << "RID mismatch, is " << collection.remoteId() << " expected " << rootRemoteId();
0025         */
0026         return QLatin1StringView(""); // see below, this intentionally not just QString()!
0027     }
0028     const QString parentMailbox = mailBoxForCollection(collection.parentCollection());
0029     if (parentMailbox.isNull()) { // invalid, != isEmpty() here!
0030         return {};
0031     }
0032 
0033     const QString mailbox = parentMailbox + collection.remoteId();
0034     if (parentMailbox.isEmpty()) {
0035         return mailbox.mid(1); // strip of the separator on top-level mailboxes
0036     }
0037     return mailbox;
0038 }