• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KIMAP Library

listjob.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 "listjob.h"
00021 
00022 #include <QtCore/QTimer>
00023 #include <KDE/KLocale>
00024 
00025 #include "job_p.h"
00026 #include "message_p.h"
00027 #include "rfccodecs.h"
00028 #include "session_p.h"
00029 
00030 namespace KIMAP
00031 {
00032   class ListJobPrivate : public JobPrivate
00033   {
00034     public:
00035       ListJobPrivate( ListJob *job, Session *session, const QString& name ) : JobPrivate(session, name), q(job), includeUnsubscribed(false) { }
00036       ~ListJobPrivate() { }
00037 
00038       void emitPendings()
00039       {
00040         if ( pendingDescriptors.isEmpty() ) {
00041           return;
00042         }
00043 
00044         emit q->mailBoxesReceived( pendingDescriptors, pendingFlags );
00045 
00046         pendingDescriptors.clear();
00047         pendingFlags.clear();
00048       }
00049 
00050       ListJob * const q;
00051 
00052       bool includeUnsubscribed;
00053       QByteArray command;
00054       QList<MailBoxDescriptor> descriptors;
00055       QMap< MailBoxDescriptor, QList<QByteArray> > flags;
00056 
00057       QTimer emitPendingsTimer;
00058       QList<MailBoxDescriptor> pendingDescriptors;
00059       QList< QList<QByteArray> > pendingFlags;
00060   };
00061 }
00062 
00063 using namespace KIMAP;
00064 
00065 ListJob::ListJob( Session *session )
00066   : Job( *new ListJobPrivate(this, session, i18n("List")) )
00067 {
00068   Q_D(ListJob);
00069   connect( &d->emitPendingsTimer, SIGNAL( timeout() ),
00070            this, SLOT( emitPendings() ) );
00071 }
00072 
00073 ListJob::~ListJob()
00074 {
00075 }
00076 
00077 void ListJob::setIncludeUnsubscribed( bool include )
00078 {
00079   Q_D(ListJob);
00080   d->includeUnsubscribed = include;
00081 }
00082 
00083 bool ListJob::isIncludeUnsubscribed() const
00084 {
00085   Q_D(const ListJob);
00086   return d->includeUnsubscribed;
00087 }
00088 
00089 QList<MailBoxDescriptor> ListJob::mailBoxes() const
00090 {
00091   Q_D(const ListJob);
00092   return d->descriptors;
00093 }
00094 
00095 QMap< MailBoxDescriptor, QList<QByteArray> > ListJob::flags() const
00096 {
00097   Q_D(const ListJob);
00098   return d->flags;
00099 }
00100 
00101 void ListJob::doStart()
00102 {
00103   Q_D(ListJob);
00104 
00105   d->command = "LSUB";
00106   if (d->includeUnsubscribed) {
00107     d->command = "LIST";
00108   }
00109 
00110   d->emitPendingsTimer.start( 100 );
00111   d->tag = d->sessionInternal()->sendCommand( d->command, "\"\" *" );
00112 }
00113 
00114 void ListJob::handleResponse( const Message &response )
00115 {
00116   Q_D(ListJob);
00117 
00118   // We can predict it'll be handled by handleErrorReplies() so stop
00119   // the timer now so that result() will really be the last emitted signal.
00120   if ( !response.content.isEmpty()
00121        && response.content.first().toString() == d->tag ) {
00122     d->emitPendingsTimer.stop();
00123     d->emitPendings();
00124   }
00125 
00126   if (handleErrorReplies(response) == NotHandled) {
00127     if ( response.content.size() >= 5
00128            && response.content[1].toString()==d->command ) {
00129       QList<QByteArray> flags = response.content[2].toList();
00130       QByteArray separator = response.content[3].toString();
00131       Q_ASSERT(separator.size()==1);
00132       QByteArray fullName;
00133       for ( int i=4; i<response.content.size(); i++ ) {
00134         fullName+= response.content[i].toString()+' ';
00135       }
00136       fullName.chop( 1 );
00137 
00138       fullName = decodeImapFolderName( fullName );
00139 
00140       MailBoxDescriptor mailBoxDescriptor;
00141       mailBoxDescriptor.separator = QChar( separator[0] );
00142       mailBoxDescriptor.name = QString::fromUtf8( fullName );
00143 
00144       d->descriptors << mailBoxDescriptor;
00145       d->flags[mailBoxDescriptor] = flags;
00146 
00147       d->pendingDescriptors << mailBoxDescriptor;
00148       d->pendingFlags << flags;
00149     }
00150   }
00151 }
00152 
00153 #include "listjob.moc"

KIMAP Library

Skip menu "KIMAP Library"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal