KIMAP

movejob.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org>
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
18namespace KIMAP
19{
20class MoveJobPrivate : public JobPrivate
21{
22public:
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
39using namespace KIMAP;
40
41MoveJob::MoveJob(Session *session)
42 : Job(*new MoveJobPrivate(session, i18n("Move")))
43{
44 Q_D(MoveJob);
45 d->uidBased = false;
46}
47
48MoveJob::~MoveJob()
49{
50}
51
52void 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
76void MoveJob::setUidBased(bool uidBased)
77{
78 Q_D(MoveJob);
79 d->uidBased = uidBased;
80}
81
83{
84 Q_D(const MoveJob);
85 return d->uidBased;
86}
87
89{
90 Q_D(const MoveJob);
91 return d->resultingUids;
92}
93
94void 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
110void 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"
Represents a set of natural numbers (1->∞) in a as compact as possible form.
Definition imapset.h:127
static ImapSet fromImapSequenceSet(const QByteArray &sequence)
Return the set corresponding to the given IMAP-compatible QByteArray representation.
Definition imapset.cpp:285
Moves messages from current mailbox to another.
Definition movejob.h:32
bool isUidBased() const
How to interpret the sequence set.
Definition movejob.cpp:82
void setSequenceSet(const ImapSet &set)
Sets the messages to be moved,.
Definition movejob.cpp:64
ImapSet sequenceSet() const
The messages that will be moved.
Definition movejob.cpp:70
ImapSet resultingUids() const
The UIDs of the moved messages in the destination mailbox.
Definition movejob.cpp:88
QString mailBox() const
The destination mailbox.
Definition movejob.cpp:58
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 i18n(const char *text, const TYPE &arg...)
QString name(GameStandardAction id)
This file is part of the IMAP support library and defines the RfcCodecs class.
KIMAP_EXPORT QByteArray encodeImapFolderName(const QByteArray &src)
Converts an Unicode IMAP mailbox to a QByteArray which can be used in IMAP communication.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:06:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.