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

KIMAP Library

  • sources
  • kde-4.12
  • kdepimlibs
  • 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  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() ) {
137  parameters.chop( 1 );
138  }
139  parameters += ')';
140 
141  kDebug() << parameters;
142 
143  QByteArray command = "STORE";
144  if ( d->uidBased ) {
145  command = "UID "+command;
146  }
147 
148  d->tags << d->sessionInternal()->sendCommand( command, parameters );
149 }
150 
151 void StoreJob::handleResponse( const Message &response )
152 {
153  Q_D( StoreJob );
154 
155  if ( handleErrorReplies( response ) == NotHandled ) {
156  if ( response.content.size() == 4 &&
157  response.content[2].toString() == "FETCH" &&
158  response.content[3].type() == Message::Part::List ) {
159 
160  int id = response.content[1].toString().toInt();
161  qint64 uid = 0;
162  bool uidFound = false;
163  QList<QByteArray> resultingFlags;
164 
165  QList<QByteArray> content = response.content[3].toList();
166 
167  for ( QList<QByteArray>::ConstIterator it = content.constBegin();
168  it != content.constEnd(); ++it ) {
169  QByteArray str = *it;
170  ++it;
171 
172  if ( str == "FLAGS" ) {
173  if ( ( *it ).startsWith( '(' ) && ( *it ).endsWith( ')' ) ) {
174  QByteArray str = *it;
175  str.chop( 1 );
176  str.remove( 0, 1 );
177  resultingFlags = str.split( ' ' );
178  } else {
179  resultingFlags << *it;
180  }
181  } else if ( str == "UID" ) {
182  uid = it->toLongLong( &uidFound );
183  }
184  }
185 
186  if ( !d->uidBased ) {
187  d->resultingFlags[id] = resultingFlags;
188  } else if ( uidFound ) {
189  d->resultingFlags[uid] = resultingFlags;
190  } else {
191  kWarning() << "We asked for UID but the server didn't give it back, resultingFlags not stored.";
192  }
193  }
194  }
195 }
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 Tue Oct 14 2014 23:00:08 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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