KIMAP

createjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "createjob.h"
8 
9 #include <KLocalizedString>
10 
11 #include "job_p.h"
12 #include "response_p.h"
13 #include "rfccodecs.h"
14 #include "session_p.h"
15 
16 namespace KIMAP
17 {
18 class CreateJobPrivate : public JobPrivate
19 {
20 public:
21  CreateJobPrivate(Session *session, const QString &name)
22  : JobPrivate(session, name)
23  {
24  }
25  ~CreateJobPrivate()
26  {
27  }
28 
29  QString mailBox;
30 };
31 }
32 
33 using namespace KIMAP;
34 
35 CreateJob::CreateJob(Session *session)
36  : Job(*new CreateJobPrivate(session, i18n("Create")))
37 {
38 }
39 
40 CreateJob::~CreateJob()
41 {
42 }
43 
44 void CreateJob::doStart()
45 {
46  Q_D(CreateJob);
47  d->tags << d->sessionInternal()->sendCommand("CREATE", '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"');
48 }
49 
50 void CreateJob::handleResponse(const Response &response)
51 {
52  Q_D(CreateJob);
53 
54  if (!response.content.isEmpty() && d->tags.contains(response.content.first().toString())) {
55  if (response.content.size() >= 2 && response.content[1].toString() == "NO") {
56  for (auto it = response.responseCode.cbegin(), end = response.responseCode.cend(); it != end; ++it) {
57  // ALREADYEXISTS can be considered a success during CREATE
58  // cf. https://tools.ietf.org/html/rfc5530#section-3
59  if (it->toString() == "ALREADYEXISTS") {
60  // Code copied from handleErrorReplies:
61  d->tags.removeAll(response.content.first().toString());
62  if (d->tags.isEmpty()) { // Only emit result when the last command returned
63  emitResult();
64  }
65  return;
66  }
67  }
68  }
69  }
70 
71  handleErrorReplies(response);
72 }
73 
74 void CreateJob::setMailBox(const QString &mailBox)
75 {
76  Q_D(CreateJob);
77  d->mailBox = mailBox;
78 }
79 
81 {
82  Q_D(const CreateJob);
83  return d->mailBox;
84 }
85 
86 #include "moc_createjob.cpp"
QString mailBox() const
The name of the mailbox that will be created.
Definition: createjob.cpp:80
QString i18n(const char *text, const TYPE &arg...)
void setMailBox(const QString &mailBox)
Set the name of the new mailbox.
Definition: createjob.cpp:74
const char * name(StandardAction id)
Creates a new mailbox.
Definition: createjob.h:33
void emitResult()
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 10 2023 03:48:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.