22 #include <boost/bind.hpp>
23 #include <QtCore/QTimer>
24 #include <KDE/KLocalizedString>
27 #include "message_p.h"
29 #include "session_p.h"
33 class ListJobPrivate :
public JobPrivate
36 ListJobPrivate( ListJob *job, Session *session,
const QString& name ) : JobPrivate( session, name ), q( job ), option( ListJob::NoOption ) { }
41 if ( pendingDescriptors.isEmpty() ) {
45 emit q->mailBoxesReceived( pendingDescriptors, pendingFlags );
47 pendingDescriptors.clear();
53 ListJob::Option option;
63 using namespace KIMAP;
65 ListJob::ListJob( Session *session )
66 : Job( *new ListJobPrivate( this, session, i18n(
"List" ) ) )
69 connect( &d->emitPendingsTimer, SIGNAL(timeout()),
70 this, SLOT(emitPendings()) );
77 void ListJob::setIncludeUnsubscribed(
bool include )
81 d->option = ListJob::IncludeUnsubscribed;
83 d->option = ListJob::NoOption;
87 bool ListJob::isIncludeUnsubscribed()
const
90 return ( d->option == ListJob::IncludeUnsubscribed );
93 void ListJob::setOption( Option option )
99 ListJob::Option ListJob::option()
const
101 Q_D(
const ListJob );
108 d->namespaces = namespaces;
113 Q_D(
const ListJob );
114 return d->namespaces;
127 void ListJob::doStart()
131 switch ( d->option ) {
133 case IncludeUnsubscribed:
136 case IncludeFolderRoleFlags:
137 d->command =
"XLIST";
144 d->emitPendingsTimer.start( 100 );
146 if ( d->namespaces.isEmpty() ) {
147 d->tags << d->sessionInternal()->sendCommand( d->command,
"\"\" *" );
149 foreach (
const MailBoxDescriptor &descriptor, d->namespaces ) {
152 if ( descriptor.name.endsWith( descriptor.separator ) ) {
153 QString name = encodeImapFolderName( descriptor.name );
155 d->tags << d->sessionInternal()->sendCommand( d->command,
159 d->tags << d->sessionInternal()->sendCommand( d->command,
165 void ListJob::handleResponse(
const Message &response )
171 if ( !response.content.isEmpty() &&
172 d->tags.size() == 1 &&
173 d->tags.contains( response.content.first().toString() ) ) {
174 d->emitPendingsTimer.stop();
178 if ( handleErrorReplies( response ) == NotHandled ) {
179 if ( response.content.size() >= 5 && response.content[1].toString() == d->command ) {
182 QByteArray separator = response.content[3].toString();
183 if ( separator.isEmpty() ) {
189 Q_ASSERT( separator.size() == 1 );
191 for (
int i=4; i<response.content.size(); i++ ) {
192 fullName += response.content[i].toString() +
' ';
196 fullName = decodeImapFolderName( fullName );
198 MailBoxDescriptor mailBoxDescriptor;
199 mailBoxDescriptor.separator =
QLatin1Char( separator[0] );
201 convertInboxName( mailBoxDescriptor );
203 d->pendingDescriptors << mailBoxDescriptor;
204 d->pendingFlags << flags;
209 void ListJob::convertInboxName(KIMAP::MailBoxDescriptor& descriptor)
214 pathParts[0].compare(
QLatin1String(
"INBOX" ), Qt::CaseInsensitive ) == 0 ) {
218 descriptor.name += descriptor.separator + pathParts.
join( descriptor.separator );
222 #include "moc_listjob.cpp"
This file is part of the IMAP support library and defines the RfcCodecs class.
QByteArray toLower() const
QString join(const QString &separator) const
QString fromUtf8(const char *str, int size)
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QByteArray toUtf8() const