File indexing completed on 2024-05-12 05:17:21
0001 /* 0002 Copyright (c) 2009 Kevin Ottens <ervin@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 "appendjob.h" 0021 0022 #include "job_p.h" 0023 #include "message_p.h" 0024 #include "session_p.h" 0025 #include "rfccodecs.h" 0026 0027 namespace KIMAP2 0028 { 0029 class AppendJobPrivate : public JobPrivate 0030 { 0031 public: 0032 AppendJobPrivate(Session *session, const QString &name) : JobPrivate(session, name), uid(0) { } 0033 ~AppendJobPrivate() { } 0034 0035 QString mailBox; 0036 QList<QByteArray> flags; 0037 QDateTime internalDate; 0038 QByteArray content; 0039 qint64 uid; 0040 }; 0041 } 0042 0043 using namespace KIMAP2; 0044 0045 AppendJob::AppendJob(Session *session) 0046 : Job(*new AppendJobPrivate(session, "Append")) 0047 { 0048 } 0049 0050 AppendJob::~AppendJob() 0051 { 0052 } 0053 0054 void AppendJob::setMailBox(const QString &mailBox) 0055 { 0056 Q_D(AppendJob); 0057 d->mailBox = mailBox; 0058 } 0059 0060 QString AppendJob::mailBox() const 0061 { 0062 Q_D(const AppendJob); 0063 return d->mailBox; 0064 } 0065 0066 void AppendJob::setFlags(const QList<QByteArray> &flags) 0067 { 0068 Q_D(AppendJob); 0069 d->flags = flags; 0070 } 0071 0072 QList<QByteArray> AppendJob::flags() const 0073 { 0074 Q_D(const AppendJob); 0075 return d->flags; 0076 } 0077 0078 void AppendJob::setInternalDate(const QDateTime &internalDate) 0079 { 0080 Q_D(AppendJob); 0081 d->internalDate = internalDate; 0082 } 0083 0084 QDateTime AppendJob::internalDate() const 0085 { 0086 Q_D(const AppendJob); 0087 return d->internalDate; 0088 } 0089 0090 void AppendJob::setContent(const QByteArray &content) 0091 { 0092 Q_D(AppendJob); 0093 d->content = content; 0094 } 0095 0096 QByteArray AppendJob::content() const 0097 { 0098 Q_D(const AppendJob); 0099 return d->content; 0100 } 0101 0102 qint64 AppendJob::uid() const 0103 { 0104 Q_D(const AppendJob); 0105 return d->uid; 0106 } 0107 0108 void AppendJob::doStart() 0109 { 0110 Q_D(AppendJob); 0111 0112 QByteArray parameters = '\"' + KIMAP2::encodeImapFolderName(d->mailBox.toUtf8()) + '\"'; 0113 0114 if (!d->flags.isEmpty()) { 0115 parameters += " ("; 0116 foreach (const QByteArray &flag, d->flags) { 0117 parameters += flag + ' '; 0118 } 0119 parameters.chop(1); 0120 parameters += ')'; 0121 } 0122 0123 if (!d->internalDate.isNull()) { 0124 const QDateTime utcDateTime = d->internalDate.toUTC(); 0125 parameters += " \"" + QLocale::c().toString(utcDateTime, QStringLiteral("dd-MMM-yyyy hh:mm:ss")).toLatin1() + " +0000" + '\"'; 0126 } 0127 0128 parameters += " {" + QByteArray::number(d->content.size()) + '}'; 0129 0130 d->sendCommand("APPEND", parameters); 0131 } 0132 0133 void AppendJob::handleResponse(const Message &response) 0134 { 0135 Q_D(AppendJob); 0136 0137 for (QList<Message::Part>::ConstIterator it = response.responseCode.begin(); 0138 it != response.responseCode.end(); ++it) { 0139 if (it->toString() == "APPENDUID") { 0140 it = it + 2; 0141 if (it != response.responseCode.end()) { 0142 d->uid = it->toString().toLongLong(); 0143 } 0144 break; 0145 } 0146 } 0147 0148 if (handleErrorReplies(response) == NotHandled) { 0149 if (!response.content.isEmpty() && response.content[0].toString() == "+") { 0150 d->sessionInternal()->sendData(d->content); 0151 } 0152 } 0153 }