23 #include <KDE/KLocalizedString>
26 #include "message_p.h"
27 #include "session_p.h"
31 class StoreJobPrivate :
public JobPrivate
34 StoreJobPrivate( Session *session,
const QString& name ) : JobPrivate( session, name ) { }
35 ~StoreJobPrivate() { }
40 case StoreJob::SetFlags:
43 case StoreJob::AppendFlags:
44 parameters +=
"+" + param;
46 case StoreJob::RemoveFlags:
47 parameters +=
"-" + param;
53 parameters += flag +
' ';
65 StoreJob::StoreMode mode;
73 using namespace KIMAP;
75 StoreJob::StoreJob( Session *session )
76 : Job( *new StoreJobPrivate( session, i18n(
"Store" ) ) )
87 void StoreJob::setSequenceSet(
const ImapSet &set )
93 ImapSet StoreJob::sequenceSet()
const
95 Q_D(
const StoreJob );
99 void StoreJob::setUidBased(
bool uidBased)
102 d->uidBased = uidBased;
105 bool StoreJob::isUidBased()
const
107 Q_D(
const StoreJob );
119 Q_D(
const StoreJob );
123 void StoreJob::setGMLabels(
const MessageFlags &gmLabels )
126 d->gmLabels = gmLabels;
131 Q_D(
const StoreJob );
135 void StoreJob::setMode( StoreMode mode )
141 StoreJob::StoreMode StoreJob::mode()
const
143 Q_D(
const StoreJob );
149 Q_D(
const StoreJob );
150 return d->resultingFlags;
153 void StoreJob::doStart()
157 if ( d->set.isEmpty() ) {
158 kWarning() <<
"Empty uid set passed to store job";
159 setError( KJob::UserDefinedError );
160 setErrorText(
QLatin1String(
"Empty uid set passed to store job") );
165 QByteArray parameters = d->set.toImapSequenceSet()+
' ';
167 if (!d->flags.isEmpty()) {
168 parameters += d->addFlags(
"FLAGS", d->flags);
170 if (!d->gmLabels.isEmpty()) {
171 if (!d->flags.isEmpty()) {
174 parameters += d->addFlags(
"X-GM-LABELS", d->gmLabels);
177 kDebug() << parameters;
181 command =
"UID " + command;
184 d->tags << d->sessionInternal()->sendCommand( command, parameters );
187 void StoreJob::handleResponse(
const Message &response )
191 if ( handleErrorReplies( response ) == NotHandled ) {
192 if ( response.content.size() == 4 &&
193 response.content[2].toString() ==
"FETCH" &&
194 response.content[3].type() == Message::Part::List ) {
196 int id = response.content[1].toString().toInt();
198 bool uidFound =
false;
208 if ( str ==
"FLAGS" ) {
209 if ( ( *it ).startsWith(
'(' ) && ( *it ).endsWith(
')' ) ) {
213 resultingFlags = str.
split(
' ' );
215 resultingFlags << *it;
217 }
else if ( str ==
"UID" ) {
218 uid = it->toLongLong( &uidFound );
222 if ( !d->uidBased ) {
223 d->resultingFlags[id] = resultingFlags;
224 }
else if ( uidFound ) {
225 d->resultingFlags[uid] = resultingFlags;
227 kWarning() <<
"We asked for UID but the server didn't give it back, resultingFlags not stored.";
QList< QByteArray > split(char sep) const
Represents a set of natural numbers (1-> ) in a as compact as possible form.
const_iterator constEnd() const
const_iterator constBegin() const
QByteArray & remove(int pos, int len)