22 #include <QtCore/QTimer>
23 #include <KDE/KLocalizedString>
26 #include "message_p.h"
27 #include "session_p.h"
31 class IdleJobPrivate :
public JobPrivate
34 IdleJobPrivate(
IdleJob *job, Session *session,
const QString& name )
35 : JobPrivate( session, name ), q( job ),
36 messageCount( -1 ), recentCount( -1 ),
37 lastMessageCount( -1 ), lastRecentCount( -1 ),
38 originalSocketTimeout( -1 ) { }
43 emitStatsTimer.stop();
45 emit q->mailBoxStats( q, m_session->selectedMailBox(),
46 messageCount, recentCount );
48 lastMessageCount = messageCount;
49 lastRecentCount = recentCount;
57 sessionInternal()->setSocketTimeout( originalSocketTimeout );
70 int originalSocketTimeout;
74 using namespace KIMAP;
76 IdleJob::IdleJob( Session *session )
77 : Job( *new IdleJobPrivate( this, session, i18nc(
"name of the idle job",
"Idle" ) ) )
80 connect( &d->emitStatsTimer, SIGNAL(timeout()),
81 this, SLOT(emitStats()) );
83 connect(
this, SIGNAL(result(KJob*)),
84 this, SLOT(resetTimeout()) );
94 d->sessionInternal()->setSocketTimeout( d->originalSocketTimeout );
95 d->sessionInternal()->sendData(
"DONE" );
98 void IdleJob::doStart()
101 d->originalSocketTimeout = d->sessionInternal()->socketTimeout();
102 d->sessionInternal()->setSocketTimeout( -1 );
103 d->tags << d->sessionInternal()->sendCommand(
"IDLE" );
106 void IdleJob::handleResponse(
const Message &response )
113 if ( !response.content.isEmpty() &&
114 d->tags.size() == 1 &&
115 d->tags.contains( response.content.first().toString() ) &&
116 ( d->messageCount >= 0 || d->recentCount >= 0 ) ) {
120 if ( handleErrorReplies( response ) == NotHandled ) {
121 if ( response.content.size() > 0 && response.content[0].toString() ==
"+" ) {
125 }
else if ( response.content.size() > 2 ) {
126 if ( response.content[2].toString() ==
"EXISTS" ) {
127 if ( d->messageCount >= 0 ) {
131 d->messageCount = response.content[1].toString().toInt();
132 }
else if ( response.content[2].toString() ==
"RECENT" ) {
133 if ( d->recentCount >= 0 ) {
137 d->recentCount = response.content[1].toString().toInt();
138 }
else if ( response.content[2].toString() ==
"FETCH" ) {
139 const qint64 uid = response.content[1].toString().toLongLong();
144 if ( d->messageCount>=0 && d->recentCount>=0 ) {
146 }
else if ( d->messageCount>=0 || d->recentCount>=0 ) {
147 d->emitStatsTimer.start( 200 );
155 return d->m_session->selectedMailBox();
161 return d->lastMessageCount;
167 return d->lastRecentCount;
170 #include "moc_idlejob.cpp"
Idles the connection to the IMAP server.
int lastMessageCount() const
The last message count that was reported.
int lastRecentCount() const
The last recent message count that was reported.
void stop()
Stops the idle job.
void mailBoxMessageFlagsChanged(KIMAP::IdleJob *job, qint64 uid)
Signals that the server has notified that the some messages flags have changed.
QString lastMailBox() const
The last mailbox status that was reported.