• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.13.3 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/KLocalizedString>
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  if ( d->set.isEmpty() ) {
119  kWarning() << "Empty uid set passed to store job";
120  setError( KJob::UserDefinedError );
121  setErrorText( QLatin1String("Empty uid set passed to store job") );
122  emitResult();
123  return;
124  }
125 
126  QByteArray parameters = d->set.toImapSequenceSet()+' ';
127 
128  switch ( d->mode ) {
129  case SetFlags:
130  parameters += "FLAGS";
131  break;
132  case AppendFlags:
133  parameters += "+FLAGS";
134  break;
135  case RemoveFlags:
136  parameters += "-FLAGS";
137  break;
138  }
139 
140  parameters += " (";
141  foreach ( const QByteArray &flag, d->flags ) {
142  parameters += flag + ' ';
143  }
144  if ( !d->flags.isEmpty() ) {
145  parameters.chop( 1 );
146  }
147  parameters += ')';
148 
149  kDebug() << parameters;
150 
151  QByteArray command = "STORE";
152  if ( d->uidBased ) {
153  command = "UID "+command;
154  }
155 
156  d->tags << d->sessionInternal()->sendCommand( command, parameters );
157 }
158 
159 void StoreJob::handleResponse( const Message &response )
160 {
161  Q_D( StoreJob );
162 
163  if ( handleErrorReplies( response ) == NotHandled ) {
164  if ( response.content.size() == 4 &&
165  response.content[2].toString() == "FETCH" &&
166  response.content[3].type() == Message::Part::List ) {
167 
168  int id = response.content[1].toString().toInt();
169  qint64 uid = 0;
170  bool uidFound = false;
171  QList<QByteArray> resultingFlags;
172 
173  QList<QByteArray> content = response.content[3].toList();
174 
175  for ( QList<QByteArray>::ConstIterator it = content.constBegin();
176  it != content.constEnd(); ++it ) {
177  QByteArray str = *it;
178  ++it;
179 
180  if ( str == "FLAGS" ) {
181  if ( ( *it ).startsWith( '(' ) && ( *it ).endsWith( ')' ) ) {
182  QByteArray str = *it;
183  str.chop( 1 );
184  str.remove( 0, 1 );
185  resultingFlags = str.split( ' ' );
186  } else {
187  resultingFlags << *it;
188  }
189  } else if ( str == "UID" ) {
190  uid = it->toLongLong( &uidFound );
191  }
192  }
193 
194  if ( !d->uidBased ) {
195  d->resultingFlags[id] = resultingFlags;
196  } else if ( uidFound ) {
197  d->resultingFlags[uid] = resultingFlags;
198  } else {
199  kWarning() << "We asked for UID but the server didn't give it back, resultingFlags not stored.";
200  }
201  }
202  }
203 }
KIMAP::ImapSet
Represents a set of natural numbers (1-> ) in a as compact as possible form.
Definition: imapset.h:140
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 07:59:56 by doxygen 1.8.6 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.13.3 API Reference

Skip menu "kdepimlibs-4.13.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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