20 #include "selectjob.h"
22 #include <KDE/KLocalizedString>
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
72 Q_D(
const SelectJob );
76 void SelectJob::setOpenReadOnly(
bool readOnly )
79 d->readOnly = readOnly;
82 bool SelectJob::isOpenReadOnly()
const
84 Q_D(
const SelectJob );
88 QList<QByteArray> SelectJob::flags()
const
90 Q_D(
const SelectJob );
94 QList<QByteArray> SelectJob::permanentFlags()
const
96 Q_D(
const SelectJob );
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();
150 if ( code ==
"OK" ) {
151 if ( response.responseCode.size() < 2 ) {
155 code = response.responseCode[0].toString();
157 if ( code ==
"PERMANENTFLAGS" ) {
158 d->permanentFlags = response.responseCode[1].toList();
162 if ( code ==
"UIDVALIDITY" ) {
163 qint64 value = response.responseCode[1].toString().toLongLong( &isInt );
167 d->uidValidity = value;
169 qint64 value = response.responseCode[1].toString().toLongLong( &isInt );
173 if ( code ==
"UNSEEN" ) {
174 d->firstUnseenIndex = value;
175 }
else if ( code ==
"UIDNEXT" ) {
180 }
else if ( code ==
"FLAGS" ) {
181 d->flags = response.content[2].toList();
184 int value = response.content[1].toString().toInt( &isInt );
185 if ( !isInt || response.content.size() < 3 ) {
189 code = response.content[2].toString();
190 if ( code ==
"EXISTS" ) {
191 d->messageCount = value;
192 }
else if ( code ==
"RECENT" ) {
193 d->recentCount = value;
197 kDebug() << response.toString();
200 Q_ASSERT( error() || d->m_session->selectedMailBox() == d->mailBox );
This file is part of the IMAP support library and defines the RfcCodecs class.