KIMAP

movejob.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 "movejob.h"
8 
9 #include "job_p.h"
10 #include "response_p.h"
11 #include "rfccodecs.h"
12 #include "session_p.h"
13 
14 #include <KLocalizedString>
15 
16 // TODO: when custom error codes are introduced, handle the NO [TRYCREATE] response
17 
18 namespace KIMAP
19 {
20 class MoveJobPrivate : public JobPrivate
21 {
22 public:
23  MoveJobPrivate(Session *session, const QString &name)
24  : JobPrivate(session, name)
25  {
26  }
27 
28  ~MoveJobPrivate()
29  {
30  }
31 
32  QString mailBox;
33  ImapSet set;
34  ImapSet resultingUids;
35  bool uidBased = false;
36 };
37 }
38 
39 using namespace KIMAP;
40 
41 MoveJob::MoveJob(Session *session)
42  : Job(*new MoveJobPrivate(session, i18n("Move")))
43 {
44  Q_D(MoveJob);
45  d->uidBased = false;
46 }
47 
48 MoveJob::~MoveJob()
49 {
50 }
51 
52 void MoveJob::setMailBox(const QString &mailBox)
53 {
54  Q_D(MoveJob);
55  d->mailBox = mailBox;
56 }
57 
59 {
60  Q_D(const MoveJob);
61  return d->mailBox;
62 }
63 
65 {
66  Q_D(MoveJob);
67  d->set = set;
68 }
69 
71 {
72  Q_D(const MoveJob);
73  return d->set;
74 }
75 
76 void MoveJob::setUidBased(bool uidBased)
77 {
78  Q_D(MoveJob);
79  d->uidBased = uidBased;
80 }
81 
82 bool MoveJob::isUidBased() const
83 {
84  Q_D(const MoveJob);
85  return d->uidBased;
86 }
87 
89 {
90  Q_D(const MoveJob);
91  return d->resultingUids;
92 }
93 
94 void MoveJob::doStart()
95 {
96  Q_D(MoveJob);
97 
98  d->set.optimize();
99  QByteArray parameters = d->set.toImapSequenceSet() + ' ';
100  parameters += '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"';
101 
102  QByteArray command = "MOVE";
103  if (d->uidBased) {
104  command = "UID " + command;
105  }
106 
107  d->tags << d->sessionInternal()->sendCommand(command, parameters);
108 }
109 
110 void MoveJob::handleResponse(const Response &response)
111 {
112  Q_D(MoveJob);
113 
114  for (auto it = response.responseCode.cbegin(), end = response.responseCode.cend(); it != end; ++it) {
115  if (it->toString() == "COPYUID") {
116  it = it + 3;
117  if (it < end) {
118  d->resultingUids = ImapSet::fromImapSequenceSet(it->toString());
119  }
120  break;
121  }
122  }
123 
124  handleErrorReplies(response);
125 }
126 
127 #include "moc_movejob.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
ImapSet sequenceSet() const
The messages that will be moved.
Definition: movejob.cpp:70
bool isUidBased() const
How to interpret the sequence set.
Definition: movejob.cpp:82
static ImapSet fromImapSequenceSet(const QByteArray &sequence)
Return the set corresponding to the given IMAP-compatible QByteArray representation.
Definition: imapset.cpp:285
void setUidBased(bool uidBased)
Set how the sequence set should be interpreted.
Definition: movejob.cpp:76
void setMailBox(const QString &mailbox)
Set the destination mailbox.
Definition: movejob.cpp:52
QString mailBox() const
The destination mailbox.
Definition: movejob.cpp:58
QString i18n(const char *text, const TYPE &arg...)
ImapSet resultingUids() const
The UIDs of the moved messages in the destination mailbox.
Definition: movejob.cpp:88
Represents a set of natural numbers (1->∞) in a as compact as possible form.
Definition: imapset.h:126
Moves messages from current mailbox to another.
Definition: movejob.h:31
const char * name(StandardAction id)
void setSequenceSet(const ImapSet &set)
Sets the messages to be moved,.
Definition: movejob.cpp:64
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.