File indexing completed on 2024-05-12 05:17:24
0001 /* 0002 Copyright (c) 2016 Daniel Vrátil <dvratil@kde.org> 0003 0004 This library is free software; you can redistribute it and/or modify it 0005 under the terms of the GNU Library General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or (at your 0007 option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, but WITHOUT 0010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0012 License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to the 0016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA. 0018 */ 0019 0020 #include "movejob.h" 0021 0022 #include "job_p.h" 0023 #include "message_p.h" 0024 #include "session_p.h" 0025 #include "rfccodecs.h" 0026 0027 //TODO: when custom error codes are introduced, handle the NO [TRYCREATE] response 0028 0029 namespace KIMAP2 0030 { 0031 class MoveJobPrivate : public JobPrivate 0032 { 0033 public: 0034 MoveJobPrivate(Session *session, const QString &name) 0035 : JobPrivate(session, name) 0036 , uidBased(false) 0037 {} 0038 0039 ~MoveJobPrivate() 0040 {} 0041 0042 QString mailBox; 0043 ImapSet set; 0044 bool uidBased; 0045 ImapSet resultingUids; 0046 }; 0047 } 0048 0049 using namespace KIMAP2; 0050 0051 MoveJob::MoveJob(Session *session) 0052 : Job(*new MoveJobPrivate(session, "Move")) 0053 { 0054 Q_D(MoveJob); 0055 d->uidBased = false; 0056 } 0057 0058 MoveJob::~MoveJob() 0059 { 0060 } 0061 0062 void MoveJob::setMailBox(const QString &mailBox) 0063 { 0064 Q_D(MoveJob); 0065 d->mailBox = mailBox; 0066 } 0067 0068 QString MoveJob::mailBox() const 0069 { 0070 Q_D(const MoveJob); 0071 return d->mailBox; 0072 } 0073 0074 void MoveJob::setSequenceSet(const ImapSet &set) 0075 { 0076 Q_D(MoveJob); 0077 d->set = set; 0078 } 0079 0080 ImapSet MoveJob::sequenceSet() const 0081 { 0082 Q_D(const MoveJob); 0083 return d->set; 0084 } 0085 0086 void MoveJob::setUidBased(bool uidBased) 0087 { 0088 Q_D(MoveJob); 0089 d->uidBased = uidBased; 0090 } 0091 0092 bool MoveJob::isUidBased() const 0093 { 0094 Q_D(const MoveJob); 0095 return d->uidBased; 0096 } 0097 0098 ImapSet MoveJob::resultingUids() const 0099 { 0100 Q_D(const MoveJob); 0101 return d->resultingUids; 0102 } 0103 0104 void MoveJob::doStart() 0105 { 0106 Q_D(MoveJob); 0107 0108 d->set.optimize(); 0109 QByteArray parameters = d->set.toImapSequenceSet() + ' '; 0110 parameters += '\"' + KIMAP2::encodeImapFolderName(d->mailBox.toUtf8()) + '\"'; 0111 0112 QByteArray command = "MOVE"; 0113 if (d->uidBased) { 0114 command = "UID " + command; 0115 } 0116 0117 d->sendCommand(command, parameters); 0118 } 0119 0120 void MoveJob::handleResponse(const Message &response) 0121 { 0122 Q_D(MoveJob); 0123 0124 for (QList<Message::Part>::ConstIterator it = response.responseCode.begin(); 0125 it != response.responseCode.end(); ++it) { 0126 if (it->toString() == "COPYUID") { 0127 it = it + 3; 0128 if (it < response.responseCode.end()) { 0129 d->resultingUids = ImapSet::fromImapSequenceSet(it->toString()); 0130 } 0131 break; 0132 } 0133 } 0134 0135 handleErrorReplies(response); 0136 }