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

KIMAP Library

namespacejob.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 "namespacejob.h"
00021 
00022 #include <KDE/KDebug>
00023 #include <KDE/KLocale>
00024 
00025 #include "job_p.h"
00026 #include "listjob.h"
00027 #include "message_p.h"
00028 #include "rfccodecs.h"
00029 #include "session_p.h"
00030 #include "imapstreamparser.h"
00031 
00032 namespace KIMAP
00033 {
00034   class NamespaceJobPrivate : public JobPrivate
00035   {
00036     public:
00037       NamespaceJobPrivate( Session *session,  const QString& name ) : JobPrivate(session, name) { }
00038       ~NamespaceJobPrivate() { }
00039 
00040       QList<MailBoxDescriptor> processNamespaceList( const QList<QByteArray> &namespaceList )
00041       {
00042         QList<MailBoxDescriptor> result;
00043 
00044         foreach ( const QByteArray &namespaceItem, namespaceList ) {
00045           ImapStreamParser parser( 0 );
00046           parser.setData( namespaceItem );
00047 
00048           QList<QByteArray> parts = parser.readParenthesizedList();
00049 
00050           if ( parts.size() < 2 ) {
00051             continue;
00052           }
00053 
00054           MailBoxDescriptor descriptor;
00055           descriptor.name = QString::fromUtf8( decodeImapFolderName( parts[0] ) );
00056           descriptor.separator = QChar( parts[1][0] );
00057 
00058           result << descriptor;
00059         }
00060 
00061         return result;
00062       }
00063 
00064       QList<MailBoxDescriptor> personalNamespaces;
00065       QList<MailBoxDescriptor> userNamespaces;
00066       QList<MailBoxDescriptor> sharedNamespaces;
00067   };
00068 }
00069 
00070 using namespace KIMAP;
00071 
00072 NamespaceJob::NamespaceJob( Session *session )
00073   : Job( *new NamespaceJobPrivate(session, i18n("Namespace")) )
00074 {
00075 }
00076 
00077 NamespaceJob::~NamespaceJob()
00078 {
00079 }
00080 
00081 QList<MailBoxDescriptor> NamespaceJob::personalNamespaces() const
00082 {
00083   Q_D(const NamespaceJob);
00084   return d->personalNamespaces;
00085 }
00086 
00087 QList<MailBoxDescriptor> NamespaceJob::userNamespaces() const
00088 {
00089   Q_D(const NamespaceJob);
00090   return d->userNamespaces;
00091 }
00092 
00093 QList<MailBoxDescriptor> NamespaceJob::sharedNamespaces() const
00094 {
00095   Q_D(const NamespaceJob);
00096   return d->sharedNamespaces;
00097 }
00098 
00099 bool NamespaceJob::containsEmptyNamespace() const
00100 {
00101   Q_D(const NamespaceJob);
00102   QList<MailBoxDescriptor> completeList = d->personalNamespaces
00103                                         + d->userNamespaces
00104                                         + d->sharedNamespaces;
00105 
00106   foreach ( const MailBoxDescriptor &descriptor, completeList ) {
00107     if ( descriptor.name.isEmpty() ) {
00108       return true;
00109     }
00110   }
00111 
00112   return false;
00113 }
00114 
00115 void NamespaceJob::doStart()
00116 {
00117   Q_D(NamespaceJob);
00118   d->tags << d->sessionInternal()->sendCommand( "NAMESPACE" );
00119 }
00120 
00121 void NamespaceJob::handleResponse( const Message &response )
00122 {
00123   Q_D(NamespaceJob);
00124   if (handleErrorReplies(response) == NotHandled) {
00125     if ( response.content.size() >= 5
00126       && response.content[1].toString()=="NAMESPACE" ) {
00127       // Personal namespaces
00128       d->personalNamespaces = d->processNamespaceList( response.content[2].toList() );
00129 
00130       // User namespaces
00131       d->userNamespaces = d->processNamespaceList( response.content[3].toList() );
00132 
00133       // Shared namespaces
00134       d->sharedNamespaces = d->processNamespaceList( response.content[4].toList() );
00135     }
00136   }
00137 }
00138 
00139 #include "namespacejob.moc"

KIMAP Library

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
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