KIMAP Library
storejob.cpp
00001 /* 00002 Copyright (c) 2009 Kevin Ottens <ervin@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #include "storejob.h" 00021 00022 #include <KDE/KDebug> 00023 #include <KDE/KLocale> 00024 00025 #include "job_p.h" 00026 #include "message_p.h" 00027 #include "session_p.h" 00028 00029 namespace KIMAP 00030 { 00031 class StoreJobPrivate : public JobPrivate 00032 { 00033 public: 00034 StoreJobPrivate( Session *session, const QString& name ) : JobPrivate( session, name ) { } 00035 ~StoreJobPrivate() { } 00036 00037 ImapSet set; 00038 bool uidBased; 00039 StoreJob::StoreMode mode; 00040 MessageFlags flags; 00041 00042 QMap<int, MessageFlags> resultingFlags; 00043 }; 00044 } 00045 00046 using namespace KIMAP; 00047 00048 StoreJob::StoreJob( Session *session ) 00049 : Job( *new StoreJobPrivate(session, i18n("Store")) ) 00050 { 00051 Q_D(StoreJob); 00052 d->uidBased = false; 00053 d->mode = SetFlags; 00054 } 00055 00056 StoreJob::~StoreJob() 00057 { 00058 } 00059 00060 void StoreJob::setSequenceSet( const ImapSet &set ) 00061 { 00062 Q_D(StoreJob); 00063 d->set = set; 00064 } 00065 00066 ImapSet StoreJob::sequenceSet() const 00067 { 00068 Q_D(const StoreJob); 00069 return d->set; 00070 } 00071 00072 void StoreJob::setUidBased(bool uidBased) 00073 { 00074 Q_D(StoreJob); 00075 d->uidBased = uidBased; 00076 } 00077 00078 bool StoreJob::isUidBased() const 00079 { 00080 Q_D(const StoreJob); 00081 return d->uidBased; 00082 } 00083 00084 void StoreJob::setFlags( const MessageFlags &flags ) 00085 { 00086 Q_D(StoreJob); 00087 d->flags = flags; 00088 } 00089 00090 MessageFlags StoreJob::flags() const 00091 { 00092 Q_D(const StoreJob); 00093 return d->flags; 00094 } 00095 00096 void StoreJob::setMode( StoreMode mode ) 00097 { 00098 Q_D(StoreJob); 00099 d->mode = mode; 00100 } 00101 00102 StoreJob::StoreMode StoreJob::mode() const 00103 { 00104 Q_D(const StoreJob); 00105 return d->mode; 00106 } 00107 00108 QMap<int, MessageFlags> StoreJob::resultingFlags() const 00109 { 00110 Q_D(const StoreJob); 00111 return d->resultingFlags; 00112 } 00113 00114 void StoreJob::doStart() 00115 { 00116 Q_D(StoreJob); 00117 00118 QByteArray parameters = d->set.toImapSequenceSet()+' '; 00119 00120 switch ( d->mode ) { 00121 case SetFlags: 00122 parameters+= "FLAGS"; 00123 break; 00124 case AppendFlags: 00125 parameters+= "+FLAGS"; 00126 break; 00127 case RemoveFlags: 00128 parameters+= "-FLAGS"; 00129 break; 00130 } 00131 00132 parameters+=" ("; 00133 foreach ( const QByteArray &flag, d->flags ) { 00134 parameters+=flag+' '; 00135 } 00136 if (!d->flags.isEmpty()) parameters.chop(1); 00137 parameters+=')'; 00138 00139 qDebug("%s", parameters.constData()); 00140 00141 QByteArray command = "STORE"; 00142 if ( d->uidBased ) { 00143 command = "UID "+command; 00144 } 00145 00146 d->tags << d->sessionInternal()->sendCommand( command, parameters ); 00147 } 00148 00149 void StoreJob::handleResponse( const Message &response ) 00150 { 00151 Q_D(StoreJob); 00152 00153 if (handleErrorReplies(response) == NotHandled ) { 00154 if ( response.content.size() == 4 00155 && response.content[2].toString()=="FETCH" 00156 && response.content[3].type()==Message::Part::List ) { 00157 00158 int id = response.content[1].toString().toInt(); 00159 qint64 uid = 0; 00160 bool uidFound = false; 00161 QList<QByteArray> resultingFlags; 00162 00163 QList<QByteArray> content = response.content[3].toList(); 00164 00165 for ( QList<QByteArray>::ConstIterator it = content.constBegin(); 00166 it!=content.constEnd(); ++it ) { 00167 QByteArray str = *it; 00168 ++it; 00169 00170 if ( str=="FLAGS" ) { 00171 if ( (*it).startsWith('(') && (*it).endsWith(')') ) { 00172 QByteArray str = *it; 00173 str.chop(1); 00174 str.remove(0, 1); 00175 resultingFlags = str.split(' '); 00176 } else { 00177 resultingFlags << *it; 00178 } 00179 } else if ( str=="UID" ) { 00180 uid = it->toLongLong(&uidFound); 00181 } 00182 } 00183 00184 if ( !d->uidBased ) { 00185 d->resultingFlags[id] = resultingFlags; 00186 } else if ( uidFound ) { 00187 d->resultingFlags[uid] = resultingFlags; 00188 } else { 00189 kWarning() << "We asked for UID but the server didn't give it back, resultingFlags not stored."; 00190 } 00191 } 00192 } 00193 } 00194 00195 #include "storejob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:08:14 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:08:14 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.