File indexing completed on 2024-05-12 05:17:17
0001 /* 0002 SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "statusjob.h" 0008 #include "job_p.h" 0009 #include "kimap_debug.h" 0010 #include "response_p.h" 0011 #include "rfccodecs.h" 0012 #include "session_p.h" 0013 0014 #include <KLocalizedString> 0015 0016 namespace KIMAP 0017 { 0018 class StatusJobPrivate : public JobPrivate 0019 { 0020 public: 0021 explicit StatusJobPrivate(Session *session, const QString &name) 0022 : JobPrivate(session, name) 0023 { 0024 } 0025 0026 ~StatusJobPrivate() 0027 { 0028 } 0029 0030 QString mailBox; 0031 QList<QByteArray> dataItems; 0032 QList<QPair<QByteArray, qint64>> status; 0033 }; 0034 0035 } 0036 0037 using namespace KIMAP; 0038 0039 StatusJob::StatusJob(Session *session) 0040 : Job(*new StatusJobPrivate(session, i18nc("name of the status job", "Status"))) 0041 { 0042 } 0043 0044 StatusJob::~StatusJob() 0045 { 0046 } 0047 0048 void StatusJob::setMailBox(const QString &mailBox) 0049 { 0050 Q_D(StatusJob); 0051 d->mailBox = mailBox; 0052 } 0053 0054 QString StatusJob::mailBox() const 0055 { 0056 Q_D(const StatusJob); 0057 return d->mailBox; 0058 } 0059 0060 void StatusJob::setDataItems(const QList<QByteArray> &dataItems) 0061 { 0062 Q_D(StatusJob); 0063 d->dataItems = dataItems; 0064 } 0065 0066 QList<QByteArray> StatusJob::dataItems() const 0067 { 0068 Q_D(const StatusJob); 0069 return d->dataItems; 0070 } 0071 0072 QList<QPair<QByteArray, qint64>> StatusJob::status() const 0073 { 0074 Q_D(const StatusJob); 0075 return d->status; 0076 } 0077 0078 void StatusJob::doStart() 0079 { 0080 Q_D(StatusJob); 0081 0082 const QByteArray params = '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + "\" (" + d->dataItems.join(' ') + ')'; 0083 0084 d->tags << d->sessionInternal()->sendCommand("STATUS", params); 0085 } 0086 0087 void StatusJob::handleResponse(const Response &response) 0088 { 0089 Q_D(StatusJob); 0090 0091 if (handleErrorReplies(response) == NotHandled) { 0092 if (response.content.size() >= 3) { 0093 const QByteArray code = response.content[1].toString(); 0094 if (code == "STATUS") { 0095 const QList<QByteArray> resp = response.content[3].toList(); 0096 for (int i = 0; i < resp.size(); i += 2) { 0097 d->status << (qMakePair(resp[i], resp[i + 1].toLongLong())); 0098 } 0099 0100 } else if (code == "OK") { 0101 return; 0102 } else { 0103 qCDebug(KIMAP_LOG) << response.toString(); 0104 } 0105 } 0106 } 0107 } 0108 0109 #include "moc_statusjob.cpp"