20 #include "selectjob.h"
22 #include <KDE/KLocale>
26 #include "message_p.h"
27 #include "session_p.h"
32 class SelectJobPrivate :
public JobPrivate
35 SelectJobPrivate( Session *session,
const QString& name )
36 : JobPrivate(session, name), readOnly(false), messageCount(-1), recentCount(-1),
37 firstUnseenIndex(-1), uidValidity(-1), nextUid(-1) { }
38 ~SelectJobPrivate() { }
43 QList<QByteArray> flags;
44 QList<QByteArray> permanentFlags;
53 using namespace KIMAP;
55 SelectJob::SelectJob( Session *session )
56 : Job( *new SelectJobPrivate(session, i18nc(
"name of the select job",
"Select")) )
60 SelectJob::~SelectJob()
64 void SelectJob::setMailBox(
const QString &mailBox )
70 QString SelectJob::mailBox()
const
76 void SelectJob::setOpenReadOnly(
bool readOnly )
79 d->readOnly = readOnly;
82 bool SelectJob::isOpenReadOnly()
const
88 QList<QByteArray> SelectJob::flags()
const
94 QList<QByteArray> SelectJob::permanentFlags()
const
97 return d->permanentFlags;
100 int SelectJob::messageCount()
const
102 Q_D(
const SelectJob);
103 return d->messageCount;
106 int SelectJob::recentCount()
const
108 Q_D(
const SelectJob);
109 return d->recentCount;
112 int SelectJob::firstUnseenIndex()
const
114 Q_D(
const SelectJob);
115 return d->firstUnseenIndex;
118 qint64 SelectJob::uidValidity()
const
120 Q_D(
const SelectJob);
121 return d->uidValidity;
124 qint64 SelectJob::nextUid()
const
126 Q_D(
const SelectJob);
130 void SelectJob::doStart()
134 QByteArray command =
"SELECT";
139 d->tags << d->sessionInternal()->sendCommand( command,
'\"'+KIMAP::encodeImapFolderName( d->mailBox.toUtf8() )+
'\"' );
142 void SelectJob::handleResponse(
const Message &response )
146 if ( handleErrorReplies(response) == NotHandled) {
147 if ( response.content.size() >= 2 ) {
148 QByteArray code = response.content[1].toString();
151 if ( response.responseCode.size() < 2 )
return;
153 code = response.responseCode[0].toString();
155 if ( code==
"PERMANENTFLAGS" ) {
156 d->permanentFlags = response.responseCode[1].toList();
160 if ( code==
"UIDVALIDITY" ) {
161 qint64 value = response.responseCode[1].toString().toLongLong(&isInt);
162 if ( !isInt )
return;
163 d->uidValidity = value;
165 qint64 value = response.responseCode[1].toString().toLongLong(&isInt);
166 if ( !isInt )
return;
167 if ( code==
"UNSEEN" ) {
168 d->firstUnseenIndex = value;
169 }
else if ( code==
"UIDNEXT" ) {
174 }
else if ( code==
"FLAGS" ) {
175 d->flags = response.content[2].toList();
178 int value = response.content[1].toString().toInt(&isInt);
179 if ( !isInt || response.content.size()<3 )
return;
181 code = response.content[2].toString();
182 if ( code==
"EXISTS" ) {
183 d->messageCount = value;
184 }
else if ( code==
"RECENT" ) {
185 d->recentCount = value;
189 kDebug() << response.toString();
192 Q_ASSERT( error() || d->m_session->selectedMailBox() == d->mailBox );
196 #include "selectjob.moc"