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

KIMAP Library

storejob.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 "storejob.h"
00021 
00022 #include <KDE/KDebug>
00023 #include <KDE/KLocale>
00024 
00025 #include "job_p.h"
00026 #include "message_p.h"
00027 #include "session_p.h"
00028 
00029 namespace KIMAP
00030 {
00031   class StoreJobPrivate : public JobPrivate
00032   {
00033     public:
00034       StoreJobPrivate( Session *session, const QString& name ) : JobPrivate( session, name ) { }
00035       ~StoreJobPrivate() { }
00036 
00037       ImapSet set;
00038       bool uidBased;
00039       StoreJob::StoreMode mode;
00040       MessageFlags flags;
00041 
00042       QMap<int, MessageFlags> resultingFlags;
00043   };
00044 }
00045 
00046 using namespace KIMAP;
00047 
00048 StoreJob::StoreJob( Session *session )
00049   : Job( *new StoreJobPrivate(session, i18n("Store")) )
00050 {
00051   Q_D(StoreJob);
00052   d->mode = SetFlags;
00053 }
00054 
00055 StoreJob::~StoreJob()
00056 {
00057 }
00058 
00059 void StoreJob::setSequenceSet( const ImapSet &set )
00060 {
00061   Q_D(StoreJob);
00062   d->set = set;
00063 }
00064 
00065 ImapSet StoreJob::sequenceSet() const
00066 {
00067   Q_D(const StoreJob);
00068   return d->set;
00069 }
00070 
00071 void StoreJob::setUidBased(bool uidBased)
00072 {
00073   Q_D(StoreJob);
00074   d->uidBased = uidBased;
00075 }
00076 
00077 bool StoreJob::isUidBased() const
00078 {
00079   Q_D(const StoreJob);
00080   return d->uidBased;
00081 }
00082 
00083 void StoreJob::setFlags( const MessageFlags &flags )
00084 {
00085   Q_D(StoreJob);
00086   d->flags = flags;
00087 }
00088 
00089 MessageFlags StoreJob::flags() const
00090 {
00091   Q_D(const StoreJob);
00092   return d->flags;
00093 }
00094 
00095 void StoreJob::setMode( StoreMode mode )
00096 {
00097   Q_D(StoreJob);
00098   d->mode = mode;
00099 }
00100 
00101 StoreJob::StoreMode StoreJob::mode() const
00102 {
00103   Q_D(const StoreJob);
00104   return d->mode;
00105 }
00106 
00107 QMap<int, MessageFlags> StoreJob::resultingFlags() const
00108 {
00109   Q_D(const StoreJob);
00110   return d->resultingFlags;
00111 }
00112 
00113 void StoreJob::doStart()
00114 {
00115   Q_D(StoreJob);
00116 
00117   QByteArray parameters = d->set.toImapSequenceSet()+' ';
00118 
00119   switch ( d->mode ) {
00120   case SetFlags:
00121     parameters+= "FLAGS";
00122     break;
00123   case AppendFlags:
00124     parameters+= "+FLAGS";
00125     break;
00126   case RemoveFlags:
00127     parameters+= "-FLAGS";
00128     break;
00129   }
00130 
00131   parameters+=" (";
00132   foreach ( const QByteArray &flag, d->flags ) {
00133     parameters+=flag+' ';
00134   }
00135   if (!d->flags.isEmpty()) parameters.chop(1);
00136   parameters+=')';
00137 
00138   qDebug("%s", parameters.constData());
00139 
00140   QByteArray command = "STORE";
00141   if ( d->uidBased ) {
00142     command = "UID "+command;
00143   }
00144 
00145   d->tag = d->sessionInternal()->sendCommand( command, parameters );
00146 }
00147 
00148 void StoreJob::handleResponse( const Message &response )
00149 {
00150   Q_D(StoreJob);
00151 
00152   if (handleErrorReplies(response) == NotHandled ) {
00153     if ( response.content.size() == 4
00154       && response.content[2].toString()=="FETCH"
00155       && response.content[3].type()==Message::Part::List ) {
00156 
00157       int id = response.content[1].toString().toInt();
00158       qint64 uid = 0;
00159       bool uidFound = false;
00160       QList<QByteArray> resultingFlags;
00161 
00162       QList<QByteArray> content = response.content[3].toList();
00163 
00164       for ( QList<QByteArray>::ConstIterator it = content.constBegin();
00165             it!=content.constEnd(); ++it ) {
00166         QByteArray str = *it;
00167         ++it;
00168 
00169         if ( str=="FLAGS" ) {
00170           if ( (*it).startsWith('(') && (*it).endsWith(')') ) {
00171             QByteArray str = *it;
00172             str.chop(1);
00173             str.remove(0, 1);
00174             resultingFlags = str.split(' ');
00175           } else {
00176             resultingFlags << *it;
00177           }
00178         } else if ( str=="UID" ) {
00179           uid = it->toLongLong(&uidFound);
00180         }
00181       }
00182 
00183       if ( !d->uidBased ) {
00184         d->resultingFlags[id] = resultingFlags;
00185       } else if ( uidFound ) {
00186         d->resultingFlags[uid] = resultingFlags;
00187       } else {
00188         kWarning() << "We asked for UID but the server didn't give it back, resultingFlags not stored.";
00189       }
00190     }
00191   }
00192 }
00193 
00194 #include "storejob.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