KIMAP Library
selectjob.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 "selectjob.h" 00021 00022 #include <KDE/KLocale> 00023 00024 #include "job_p.h" 00025 #include "message_p.h" 00026 #include "session_p.h" 00027 #include "rfccodecs.h" 00028 00029 namespace KIMAP 00030 { 00031 class SelectJobPrivate : public JobPrivate 00032 { 00033 public: 00034 SelectJobPrivate( Session *session, const QString& name ) 00035 : JobPrivate(session, name), readOnly(false), messageCount(-1), recentCount(-1), 00036 firstUnseenIndex(-1), uidValidity(-1), nextUid(-1) { } 00037 ~SelectJobPrivate() { } 00038 00039 QString mailBox; 00040 bool readOnly; 00041 00042 QList<QByteArray> flags; 00043 QList<QByteArray> permanentFlags; 00044 int messageCount; 00045 int recentCount; 00046 int firstUnseenIndex; 00047 qint64 uidValidity; 00048 qint64 nextUid; 00049 }; 00050 } 00051 00052 using namespace KIMAP; 00053 00054 SelectJob::SelectJob( Session *session ) 00055 : Job( *new SelectJobPrivate(session, i18nc("name of the select job", "Select")) ) 00056 { 00057 } 00058 00059 SelectJob::~SelectJob() 00060 { 00061 } 00062 00063 void SelectJob::setMailBox( const QString &mailBox ) 00064 { 00065 Q_D(SelectJob); 00066 d->mailBox = mailBox; 00067 } 00068 00069 QString SelectJob::mailBox() const 00070 { 00071 Q_D(const SelectJob); 00072 return d->mailBox; 00073 } 00074 00075 void SelectJob::setOpenReadOnly( bool readOnly ) 00076 { 00077 Q_D(SelectJob); 00078 d->readOnly = readOnly; 00079 } 00080 00081 bool SelectJob::isOpenReadOnly() const 00082 { 00083 Q_D(const SelectJob); 00084 return d->readOnly; 00085 } 00086 00087 QList<QByteArray> SelectJob::flags() const 00088 { 00089 Q_D(const SelectJob); 00090 return d->flags; 00091 } 00092 00093 QList<QByteArray> SelectJob::permanentFlags() const 00094 { 00095 Q_D(const SelectJob); 00096 return d->permanentFlags; 00097 } 00098 00099 int SelectJob::messageCount() const 00100 { 00101 Q_D(const SelectJob); 00102 return d->messageCount; 00103 } 00104 00105 int SelectJob::recentCount() const 00106 { 00107 Q_D(const SelectJob); 00108 return d->recentCount; 00109 } 00110 00111 int SelectJob::firstUnseenIndex() const 00112 { 00113 Q_D(const SelectJob); 00114 return d->firstUnseenIndex; 00115 } 00116 00117 qint64 SelectJob::uidValidity() const 00118 { 00119 Q_D(const SelectJob); 00120 return d->uidValidity; 00121 } 00122 00123 qint64 SelectJob::nextUid() const 00124 { 00125 Q_D(const SelectJob); 00126 return d->nextUid; 00127 } 00128 00129 void SelectJob::doStart() 00130 { 00131 Q_D(SelectJob); 00132 00133 QByteArray command = "SELECT"; 00134 if ( d->readOnly ) { 00135 command = "EXAMINE"; 00136 } 00137 00138 d->tags << d->sessionInternal()->sendCommand( command, '\"'+KIMAP::encodeImapFolderName( d->mailBox.toUtf8() )+'\"' ); 00139 } 00140 00141 void SelectJob::handleResponse( const Message &response ) 00142 { 00143 Q_D(SelectJob); 00144 00145 if ( handleErrorReplies(response) == NotHandled) { 00146 if ( response.content.size() >= 2 ) { 00147 QByteArray code = response.content[1].toString(); 00148 00149 if ( code=="OK" ) { 00150 if ( response.responseCode.size() < 2 ) return; 00151 00152 code = response.responseCode[0].toString(); 00153 00154 if ( code=="PERMANENTFLAGS" ) { 00155 d->permanentFlags = response.responseCode[1].toList(); 00156 } else { 00157 bool isInt; 00158 00159 if ( code=="UIDVALIDITY" ) { 00160 qint64 value = response.responseCode[1].toString().toLongLong(&isInt); 00161 if ( !isInt ) return; 00162 d->uidValidity = value; 00163 } else { 00164 qint64 value = response.responseCode[1].toString().toLongLong(&isInt); 00165 if ( !isInt ) return; 00166 if ( code=="UNSEEN" ) { 00167 d->firstUnseenIndex = value; 00168 } else if ( code=="UIDNEXT" ) { 00169 d->nextUid = value; 00170 } 00171 } 00172 } 00173 } else if ( code=="FLAGS" ) { 00174 d->flags = response.content[2].toList(); 00175 } else { 00176 bool isInt; 00177 int value = response.content[1].toString().toInt(&isInt); 00178 if ( !isInt || response.content.size()<3 ) return; 00179 00180 code = response.content[2].toString(); 00181 if ( code=="EXISTS" ) { 00182 d->messageCount = value; 00183 } else if ( code=="RECENT" ) { 00184 d->recentCount = value; 00185 } 00186 } 00187 } else { 00188 qDebug("%s", response.toString().constData()); 00189 } 00190 } else { 00191 Q_ASSERT( error() || d->m_session->selectedMailBox() == d->mailBox ); 00192 } 00193 } 00194 00195 #include "selectjob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 7 2012 23:55:08 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 7 2012 23:55:08 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.