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 "deletejob.h" 0008 0009 #include <KLocalizedString> 0010 0011 #include "job_p.h" 0012 #include "response_p.h" 0013 #include "rfccodecs.h" 0014 #include "session_p.h" 0015 0016 namespace KIMAP 0017 { 0018 class DeleteJobPrivate : public JobPrivate 0019 { 0020 public: 0021 DeleteJobPrivate(Session *session, const QString &name) 0022 : JobPrivate(session, name) 0023 { 0024 } 0025 ~DeleteJobPrivate() 0026 { 0027 } 0028 0029 QString mailBox; 0030 }; 0031 } 0032 0033 using namespace KIMAP; 0034 0035 DeleteJob::DeleteJob(Session *session) 0036 : Job(*new DeleteJobPrivate(session, i18n("Delete"))) 0037 { 0038 } 0039 0040 DeleteJob::~DeleteJob() 0041 { 0042 } 0043 0044 void DeleteJob::doStart() 0045 { 0046 Q_D(DeleteJob); 0047 d->tags << d->sessionInternal()->sendCommand("DELETE", '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"'); 0048 } 0049 0050 void DeleteJob::handleResponse(const Response &response) 0051 { 0052 Q_D(DeleteJob); 0053 0054 if (!response.content.isEmpty() && d->tags.contains(response.content.first().toString())) { 0055 if (response.content.size() >= 2 && response.content[1].toString() == "NO") { 0056 for (auto it = response.responseCode.cbegin(), end = response.responseCode.cend(); it != end; ++it) { 0057 // NONEXISTENT can be considered a success during DELETE 0058 // cf. https://tools.ietf.org/html/rfc5530#section-3 0059 if (it->toString() == "NONEXISTENT") { 0060 // Code copied from handleErrorReplies: 0061 d->tags.removeAll(response.content.first().toString()); 0062 if (d->tags.isEmpty()) { // Only emit result when the last command returned 0063 emitResult(); 0064 } 0065 return; 0066 } 0067 } 0068 } 0069 } 0070 0071 handleErrorReplies(response); 0072 } 0073 0074 void DeleteJob::setMailBox(const QString &mailBox) 0075 { 0076 Q_D(DeleteJob); 0077 d->mailBox = mailBox; 0078 } 0079 0080 QString DeleteJob::mailBox() const 0081 { 0082 Q_D(const DeleteJob); 0083 return d->mailBox; 0084 } 0085 0086 #include "moc_deletejob.cpp"