File indexing completed on 2024-05-12 05:17:13

0001 /*
0002     SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "expungejob.h"
0008 
0009 #include "kimap_debug.h"
0010 #include <KLocalizedString>
0011 
0012 #include "imapset.h"
0013 #include "job_p.h"
0014 #include "response_p.h"
0015 #include "session_p.h"
0016 
0017 namespace KIMAP
0018 {
0019 class ExpungeJobPrivate : public JobPrivate
0020 {
0021 public:
0022     ExpungeJobPrivate(Session *session, const QString &name)
0023         : JobPrivate(session, name)
0024     {
0025     }
0026 #if 0
0027     QList< int > items;
0028 #endif
0029     KIMAP::ImapSet vanished;
0030     quint64 highestModSeq = 0;
0031 };
0032 }
0033 
0034 using namespace KIMAP;
0035 
0036 ExpungeJob::ExpungeJob(Session *session)
0037     : Job(*new ExpungeJobPrivate(session, i18n("Expunge")))
0038 {
0039 }
0040 
0041 KIMAP::ImapSet ExpungeJob::vanishedMessages() const
0042 {
0043     Q_D(const ExpungeJob);
0044     return d->vanished;
0045 }
0046 
0047 quint64 ExpungeJob::newHighestModSeq() const
0048 {
0049     Q_D(const ExpungeJob);
0050     return d->highestModSeq;
0051 }
0052 
0053 void ExpungeJob::doStart()
0054 {
0055     Q_D(ExpungeJob);
0056     d->tags << d->sessionInternal()->sendCommand("EXPUNGE");
0057 }
0058 
0059 void ExpungeJob::handleResponse(const Response &response)
0060 {
0061     Q_D(ExpungeJob);
0062 
0063     // Must be handler before handleErrorReplies(), so the value is available
0064     // before the result is emitted.
0065     if (response.responseCode.size() >= 2) {
0066         if (response.responseCode[0].toString() == "HIGHESTMODSEQ") {
0067             d->highestModSeq = response.responseCode[1].toString().toULongLong();
0068         }
0069     }
0070 
0071     if (handleErrorReplies(response) == NotHandled) {
0072         if (response.content.size() >= 3) {
0073             if (response.content[1].toString() == "VANISHED") {
0074                 d->vanished = KIMAP::ImapSet::fromImapSequenceSet(response.content[2].toString());
0075                 return;
0076             } else if (response.content[2].toString() == "EXPUNGE") {
0077 #if 0
0078                 QByteArray s = response.content[1].toString();
0079                 bool ok = true;
0080                 int id = s.toInt(&ok);
0081                 if (ok) {
0082                     d->items.append(id);
0083                 }
0084                 //TODO error handling
0085 #endif
0086                 return;
0087             }
0088         }
0089         qCDebug(KIMAP_LOG) << "Unhandled response: " << response.toString().constData();
0090     }
0091 }
0092 
0093 #include "moc_expungejob.cpp"