KIMAP

statusjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Daniel Vr├ítil <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "statusjob.h"
8 #include "job_p.h"
9 #include "kimap_debug.h"
10 #include "response_p.h"
11 #include "rfccodecs.h"
12 #include "session_p.h"
13 
14 #include <KLocalizedString>
15 
16 namespace KIMAP
17 {
18 class StatusJobPrivate : public JobPrivate
19 {
20 public:
21  explicit StatusJobPrivate(Session *session, const QString &name)
22  : JobPrivate(session, name)
23  {
24  }
25 
26  ~StatusJobPrivate()
27  {
28  }
29 
30  QString mailBox;
31  QList<QByteArray> dataItems;
33 };
34 
35 }
36 
37 using namespace KIMAP;
38 
39 StatusJob::StatusJob(Session *session)
40  : Job(*new StatusJobPrivate(session, i18nc("name of the status job", "Status")))
41 {
42 }
43 
44 StatusJob::~StatusJob()
45 {
46 }
47 
48 void StatusJob::setMailBox(const QString &mailBox)
49 {
50  Q_D(StatusJob);
51  d->mailBox = mailBox;
52 }
53 
54 QString StatusJob::mailBox() const
55 {
56  Q_D(const StatusJob);
57  return d->mailBox;
58 }
59 
60 void StatusJob::setDataItems(const QList<QByteArray> &dataItems)
61 {
62  Q_D(StatusJob);
63  d->dataItems = dataItems;
64 }
65 
66 QList<QByteArray> StatusJob::dataItems() const
67 {
68  Q_D(const StatusJob);
69  return d->dataItems;
70 }
71 
73 {
74  Q_D(const StatusJob);
75  return d->status;
76 }
77 
78 void StatusJob::doStart()
79 {
80  Q_D(StatusJob);
81 
82  const QByteArray params = '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + "\" (" + d->dataItems.join(' ') + ')';
83 
84  d->tags << d->sessionInternal()->sendCommand("STATUS", params);
85 }
86 
87 void StatusJob::handleResponse(const Response &response)
88 {
89  Q_D(StatusJob);
90 
91  if (handleErrorReplies(response) == NotHandled) {
92  if (response.content.size() >= 3) {
93  const QByteArray code = response.content[1].toString();
94  if (code == "STATUS") {
95  const QList<QByteArray> resp = response.content[3].toList();
96  for (int i = 0; i < resp.size(); i += 2) {
97  d->status << (qMakePair(resp[i], resp[i + 1].toLongLong()));
98  }
99 
100  } else if (code == "OK") {
101  return;
102  } else {
103  qCDebug(KIMAP_LOG) << response.toString();
104  }
105  }
106  }
107 }
108 
109 #include "moc_statusjob.cpp"
KIMAP_EXPORT QString encodeImapFolderName(const QString &src)
Converts an Unicode IMAP mailbox to a QString which can be used in IMAP communication.
Definition: rfccodecs.cpp:180
int size() const const
Q_SCRIPTABLE CaptureState status()
const char * name(StandardAction id)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
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 Dec 3 2023 03:51:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.