• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 API Reference
  • KDE Home
  • Contact Us
 

KIMAP Library

  • kimap
storejob.cpp
1 /*
2  Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "storejob.h"
21 
22 #include <KDE/KDebug>
23 #include <KDE/KLocale>
24 
25 #include "job_p.h"
26 #include "message_p.h"
27 #include "session_p.h"
28 
29 namespace KIMAP
30 {
31  class StoreJobPrivate : public JobPrivate
32  {
33  public:
34  StoreJobPrivate( Session *session, const QString& name ) : JobPrivate( session, name ) { }
35  ~StoreJobPrivate() { }
36 
37  ImapSet set;
38  bool uidBased;
39  StoreJob::StoreMode mode;
40  MessageFlags flags;
41 
42  QMap<int, MessageFlags> resultingFlags;
43  };
44 }
45 
46 using namespace KIMAP;
47 
48 StoreJob::StoreJob( Session *session )
49  : Job( *new StoreJobPrivate(session, i18n("Store")) )
50 {
51  Q_D(StoreJob);
52  d->uidBased = false;
53  d->mode = SetFlags;
54 }
55 
56 StoreJob::~StoreJob()
57 {
58 }
59 
60 void StoreJob::setSequenceSet( const ImapSet &set )
61 {
62  Q_D(StoreJob);
63  d->set = set;
64 }
65 
66 ImapSet StoreJob::sequenceSet() const
67 {
68  Q_D(const StoreJob);
69  return d->set;
70 }
71 
72 void StoreJob::setUidBased(bool uidBased)
73 {
74  Q_D(StoreJob);
75  d->uidBased = uidBased;
76 }
77 
78 bool StoreJob::isUidBased() const
79 {
80  Q_D(const StoreJob);
81  return d->uidBased;
82 }
83 
84 void StoreJob::setFlags( const MessageFlags &flags )
85 {
86  Q_D(StoreJob);
87  d->flags = flags;
88 }
89 
90 MessageFlags StoreJob::flags() const
91 {
92  Q_D(const StoreJob);
93  return d->flags;
94 }
95 
96 void StoreJob::setMode( StoreMode mode )
97 {
98  Q_D(StoreJob);
99  d->mode = mode;
100 }
101 
102 StoreJob::StoreMode StoreJob::mode() const
103 {
104  Q_D(const StoreJob);
105  return d->mode;
106 }
107 
108 QMap<int, MessageFlags> StoreJob::resultingFlags() const
109 {
110  Q_D(const StoreJob);
111  return d->resultingFlags;
112 }
113 
114 void StoreJob::doStart()
115 {
116  Q_D(StoreJob);
117 
118  QByteArray parameters = d->set.toImapSequenceSet()+' ';
119 
120  switch ( d->mode ) {
121  case SetFlags:
122  parameters+= "FLAGS";
123  break;
124  case AppendFlags:
125  parameters+= "+FLAGS";
126  break;
127  case RemoveFlags:
128  parameters+= "-FLAGS";
129  break;
130  }
131 
132  parameters+=" (";
133  foreach ( const QByteArray &flag, d->flags ) {
134  parameters+=flag+' ';
135  }
136  if (!d->flags.isEmpty()) parameters.chop(1);
137  parameters+=')';
138 
139  kDebug() << parameters;
140 
141  QByteArray command = "STORE";
142  if ( d->uidBased ) {
143  command = "UID "+command;
144  }
145 
146  d->tags << d->sessionInternal()->sendCommand( command, parameters );
147 }
148 
149 void StoreJob::handleResponse( const Message &response )
150 {
151  Q_D(StoreJob);
152 
153  if (handleErrorReplies(response) == NotHandled ) {
154  if ( response.content.size() == 4
155  && response.content[2].toString()=="FETCH"
156  && response.content[3].type()==Message::Part::List ) {
157 
158  int id = response.content[1].toString().toInt();
159  qint64 uid = 0;
160  bool uidFound = false;
161  QList<QByteArray> resultingFlags;
162 
163  QList<QByteArray> content = response.content[3].toList();
164 
165  for ( QList<QByteArray>::ConstIterator it = content.constBegin();
166  it!=content.constEnd(); ++it ) {
167  QByteArray str = *it;
168  ++it;
169 
170  if ( str=="FLAGS" ) {
171  if ( (*it).startsWith('(') && (*it).endsWith(')') ) {
172  QByteArray str = *it;
173  str.chop(1);
174  str.remove(0, 1);
175  resultingFlags = str.split(' ');
176  } else {
177  resultingFlags << *it;
178  }
179  } else if ( str=="UID" ) {
180  uid = it->toLongLong(&uidFound);
181  }
182  }
183 
184  if ( !d->uidBased ) {
185  d->resultingFlags[id] = resultingFlags;
186  } else if ( uidFound ) {
187  d->resultingFlags[uid] = resultingFlags;
188  } else {
189  kWarning() << "We asked for UID but the server didn't give it back, resultingFlags not stored.";
190  }
191  }
192  }
193 }
194 
195 #include "storejob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Dec 10 2012 13:47:03 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIMAP Library

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

kdepimlibs-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal