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

KIMAP Library

  • 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 ) { }
38  ~SelectJobPrivate() { }
39 
40  QString mailBox;
41  bool readOnly;
42 
43  QList<QByteArray> flags;
44  QList<QByteArray> permanentFlags;
45  int messageCount;
46  int recentCount;
47  int firstUnseenIndex;
48  qint64 uidValidity;
49  qint64 nextUid;
50  };
51 }
52 
53 using namespace KIMAP;
54 
55 SelectJob::SelectJob( Session *session )
56  : Job( *new SelectJobPrivate( session, i18nc( "name of the select job", "Select" ) ) )
57 {
58 }
59 
60 SelectJob::~SelectJob()
61 {
62 }
63 
64 void SelectJob::setMailBox( const QString &mailBox )
65 {
66  Q_D( SelectJob );
67  d->mailBox = mailBox;
68 }
69 
70 QString SelectJob::mailBox() const
71 {
72  Q_D( const SelectJob );
73  return d->mailBox;
74 }
75 
76 void SelectJob::setOpenReadOnly( bool readOnly )
77 {
78  Q_D( SelectJob );
79  d->readOnly = readOnly;
80 }
81 
82 bool SelectJob::isOpenReadOnly() const
83 {
84  Q_D( const SelectJob );
85  return d->readOnly;
86 }
87 
88 QList<QByteArray> SelectJob::flags() const
89 {
90  Q_D( const SelectJob );
91  return d->flags;
92 }
93 
94 QList<QByteArray> SelectJob::permanentFlags() const
95 {
96  Q_D( const SelectJob );
97  return d->permanentFlags;
98 }
99 
100 int SelectJob::messageCount() const
101 {
102  Q_D( const SelectJob );
103  return d->messageCount;
104 }
105 
106 int SelectJob::recentCount() const
107 {
108  Q_D( const SelectJob );
109  return d->recentCount;
110 }
111 
112 int SelectJob::firstUnseenIndex() const
113 {
114  Q_D( const SelectJob );
115  return d->firstUnseenIndex;
116 }
117 
118 qint64 SelectJob::uidValidity() const
119 {
120  Q_D( const SelectJob );
121  return d->uidValidity;
122 }
123 
124 qint64 SelectJob::nextUid() const
125 {
126  Q_D( const SelectJob );
127  return d->nextUid;
128 }
129 
130 void SelectJob::doStart()
131 {
132  Q_D( SelectJob );
133 
134  QByteArray command = "SELECT";
135  if ( d->readOnly ) {
136  command = "EXAMINE";
137  }
138 
139  d->tags << d->sessionInternal()->sendCommand( command, '\"'+KIMAP::encodeImapFolderName( d->mailBox.toUtf8() )+'\"' );
140 }
141 
142 void SelectJob::handleResponse( const Message &response )
143 {
144  Q_D( SelectJob );
145 
146  if ( handleErrorReplies( response ) == NotHandled ) {
147  if ( response.content.size() >= 2 ) {
148  QByteArray code = response.content[1].toString();
149 
150  if ( code == "OK" ) {
151  if ( response.responseCode.size() < 2 ) {
152  return;
153  }
154 
155  code = response.responseCode[0].toString();
156 
157  if ( code == "PERMANENTFLAGS" ) {
158  d->permanentFlags = response.responseCode[1].toList();
159  } else {
160  bool isInt;
161 
162  if ( code == "UIDVALIDITY" ) {
163  qint64 value = response.responseCode[1].toString().toLongLong( &isInt );
164  if ( !isInt ) {
165  return;
166  }
167  d->uidValidity = value;
168  } else {
169  qint64 value = response.responseCode[1].toString().toLongLong( &isInt );
170  if ( !isInt ) {
171  return;
172  }
173  if ( code == "UNSEEN" ) {
174  d->firstUnseenIndex = value;
175  } else if ( code == "UIDNEXT" ) {
176  d->nextUid = value;
177  }
178  }
179  }
180  } else if ( code == "FLAGS" ) {
181  d->flags = response.content[2].toList();
182  } else {
183  bool isInt;
184  int value = response.content[1].toString().toInt( &isInt );
185  if ( !isInt || response.content.size() < 3 ) {
186  return;
187  }
188 
189  code = response.content[2].toString();
190  if ( code == "EXISTS" ) {
191  d->messageCount = value;
192  } else if ( code == "RECENT" ) {
193  d->recentCount = value;
194  }
195  }
196  } else {
197  kDebug() << response.toString();
198  }
199  } else {
200  Q_ASSERT( error() || d->m_session->selectedMailBox() == d->mailBox );
201  }
202 }
rfccodecs.h
This file is part of the IMAP support library and defines the RfcCodecs class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:02:14 by doxygen 1.8.5 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.11.3 API Reference

Skip menu "kdepimlibs-4.11.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