KIMAP2

statusjob.cpp
1 /*
2  Copyright (c) 2016 Daniel Vr├ítil <[email protected]>
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 "statusjob.h"
21 #include "job_p.h"
22 #include "message_p.h"
23 #include "session_p.h"
24 #include "rfccodecs.h"
25 #include "kimap_debug.h"
26 
27 namespace KIMAP2
28 {
29 
30 class StatusJobPrivate : public JobPrivate
31 {
32 public:
33  explicit StatusJobPrivate(Session *session, const QString &name)
34  : JobPrivate(session, name)
35  {
36  }
37 
38  ~StatusJobPrivate()
39  {
40  }
41 
42  QString mailBox;
43  QList<QByteArray> dataItems;
45 };
46 
47 }
48 
49 using namespace KIMAP2;
50 
51 StatusJob::StatusJob(Session *session)
52  : Job(*new StatusJobPrivate(session, "Status"))
53 {
54 }
55 
56 StatusJob::~StatusJob()
57 {
58 }
59 
60 void StatusJob::setMailBox(const QString &mailBox)
61 {
62  Q_D(StatusJob);
63  d->mailBox = mailBox;
64 }
65 
66 QString StatusJob::mailBox() const
67 {
68  Q_D(const StatusJob);
69  return d->mailBox;
70 }
71 
72 void StatusJob::setDataItems(const QList<QByteArray> &dataItems)
73 {
74  Q_D(StatusJob);
75  d->dataItems = dataItems;
76 }
77 
78 QList<QByteArray> StatusJob::dataItems() const
79 {
80  Q_D(const StatusJob);
81  return d->dataItems;
82 }
83 
85 {
86  Q_D(const StatusJob);
87  return d->status;
88 }
89 
90 void StatusJob::doStart()
91 {
92  Q_D(StatusJob);
93 
94  const QByteArray params = '\"' + KIMAP2::encodeImapFolderName(d->mailBox.toUtf8()) + "\" ("
95  + d->dataItems.join(' ') + ')';
96 
97  d->sendCommand("STATUS", params);
98 }
99 
100 void StatusJob::handleResponse(const Message &response)
101 {
102  Q_D(StatusJob);
103 
104  if (handleErrorReplies(response) == NotHandled) {
105  if (response.content.size() >= 3) {
106  const QByteArray code = response.content[1].toString();
107  if (code == "STATUS") {
108 
109  const QList<QByteArray> resp = response.content[3].toList();
110  for (int i = 0; i < resp.size(); i += 2) {
111  d->status << (qMakePair(resp[i], resp[i + 1].toLongLong()));
112  }
113 
114  } else if (code == "OK") {
115  return;
116  } else {
117  qCDebug(KIMAP2_LOG) << response.toString();
118  }
119  }
120  }
121 }
KIMAP2_EXPORT QString encodeImapFolderName(const QString &src)
Converts an Unicode IMAP mailbox to a QString which can be used in IMAP communication.
Definition: rfccodecs.cpp:192
int size() const const
Q_SCRIPTABLE CaptureState status()
QString name(StandardShortcut id)
Provides handlers for various RFC/MIME encodings.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Feb 5 2023 04:11:00 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.