• 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.14
  • kdepimlibs
  • kimap
selectjob.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 "selectjob.h"
21 
22 #include <KDE/KLocalizedString>
23 #include <kdebug.h>
24 
25 #include "job_p.h"
26 #include "message_p.h"
27 #include "session_p.h"
28 #include "rfccodecs.h"
29 
30 namespace KIMAP
31 {
32  class SelectJobPrivate : public JobPrivate
33  {
34  public:
35  SelectJobPrivate( Session *session, const QString& name )
36  : JobPrivate( session, name ), readOnly( false ), messageCount( -1 ), recentCount( -1 ),
37  firstUnseenIndex( -1 ), uidValidity( -1 ), nextUid( -1 ), highestmodseq( 0 ),
38  condstoreEnabled( false ) { }
39  ~SelectJobPrivate() { }
40 
41  QString mailBox;
42  bool readOnly;
43 
44  QList<QByteArray> flags;
45  QList<QByteArray> permanentFlags;
46  int messageCount;
47  int recentCount;
48  int firstUnseenIndex;
49  qint64 uidValidity;
50  qint64 nextUid;
51  quint64 highestmodseq;
52  bool condstoreEnabled;
53  };
54 }
55 
56 using namespace KIMAP;
57 
58 SelectJob::SelectJob( Session *session )
59  : Job( *new SelectJobPrivate( session, i18nc( "name of the select job", "Select" ) ) )
60 {
61 }
62 
63 SelectJob::~SelectJob()
64 {
65 }
66 
67 void SelectJob::setMailBox( const QString &mailBox )
68 {
69  Q_D( SelectJob );
70  d->mailBox = mailBox;
71 }
72 
73 QString SelectJob::mailBox() const
74 {
75  Q_D( const SelectJob );
76  return d->mailBox;
77 }
78 
79 void SelectJob::setOpenReadOnly( bool readOnly )
80 {
81  Q_D( SelectJob );
82  d->readOnly = readOnly;
83 }
84 
85 bool SelectJob::isOpenReadOnly() const
86 {
87  Q_D( const SelectJob );
88  return d->readOnly;
89 }
90 
91 QList<QByteArray> SelectJob::flags() const
92 {
93  Q_D( const SelectJob );
94  return d->flags;
95 }
96 
97 QList<QByteArray> SelectJob::permanentFlags() const
98 {
99  Q_D( const SelectJob );
100  return d->permanentFlags;
101 }
102 
103 int SelectJob::messageCount() const
104 {
105  Q_D( const SelectJob );
106  return d->messageCount;
107 }
108 
109 int SelectJob::recentCount() const
110 {
111  Q_D( const SelectJob );
112  return d->recentCount;
113 }
114 
115 int SelectJob::firstUnseenIndex() const
116 {
117  Q_D( const SelectJob );
118  return d->firstUnseenIndex;
119 }
120 
121 qint64 SelectJob::uidValidity() const
122 {
123  Q_D( const SelectJob );
124  return d->uidValidity;
125 }
126 
127 qint64 SelectJob::nextUid() const
128 {
129  Q_D( const SelectJob );
130  return d->nextUid;
131 }
132 
133 quint64 SelectJob::highestModSequence() const
134 {
135  Q_D( const SelectJob );
136  return d->highestmodseq;
137 }
138 
139 void SelectJob::setCondstoreEnabled( bool enable )
140 {
141  Q_D( SelectJob );
142  d->condstoreEnabled = enable;
143 }
144 
145 bool SelectJob::condstoreEnabled() const
146 {
147  Q_D( const SelectJob );
148  return d->condstoreEnabled;
149 }
150 
151 
152 void SelectJob::doStart()
153 {
154  Q_D( SelectJob );
155 
156  QByteArray command = "SELECT";
157  if ( d->readOnly ) {
158  command = "EXAMINE";
159  }
160 
161  QByteArray params = '\"'+KIMAP::encodeImapFolderName( d->mailBox.toUtf8() )+'\"';
162 
163  if ( d->condstoreEnabled ) {
164  params += " (CONDSTORE)";
165  }
166 
167  d->tags << d->sessionInternal()->sendCommand( command, params );
168 }
169 
170 void SelectJob::handleResponse( const Message &response )
171 {
172  Q_D( SelectJob );
173 
174  if ( handleErrorReplies( response ) == NotHandled ) {
175  if ( response.content.size() >= 2 ) {
176  QByteArray code = response.content[1].toString();
177 
178  if ( code == "OK" ) {
179  if ( response.responseCode.size() < 2 ) {
180  return;
181  }
182 
183  code = response.responseCode[0].toString();
184 
185  if ( code == "PERMANENTFLAGS" ) {
186  d->permanentFlags = response.responseCode[1].toList();
187  } else if ( code == "HIGHESTMODSEQ" ) {
188  bool isInt;
189  quint64 value = response.responseCode[1].toString().toULongLong( &isInt );
190  if ( !isInt ) {
191  return;
192  }
193  d->highestmodseq = value;
194  } else {
195  bool isInt;
196  qint64 value = response.responseCode[1].toString().toLongLong( &isInt );
197  if ( !isInt ) {
198  return;
199  }
200  if ( code == "UIDVALIDITY" ) {
201  d->uidValidity = value;
202  } else if ( code == "UNSEEN" ) {
203  d->firstUnseenIndex = value;
204  } else if ( code == "UIDNEXT" ) {
205  d->nextUid = value;
206  }
207  }
208  } else if ( code == "FLAGS" ) {
209  d->flags = response.content[2].toList();
210  } else {
211  bool isInt;
212  int value = response.content[1].toString().toInt( &isInt );
213  if ( !isInt || response.content.size() < 3 ) {
214  return;
215  }
216 
217  code = response.content[2].toString();
218  if ( code == "EXISTS" ) {
219  d->messageCount = value;
220  } else if ( code == "RECENT" ) {
221  d->recentCount = value;
222  }
223  }
224  } else {
225  kDebug() << response.toString();
226  }
227  } else {
228  Q_ASSERT( error() || d->m_session->selectedMailBox() == d->mailBox );
229  }
230 }
rfccodecs.h
This file is part of the IMAP support library and defines the RfcCodecs class.
QByteArray
QString
QList< QByteArray >
QByteArray::toULongLong
qulonglong toULongLong(bool *ok, int base) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:03 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
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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