KIMAP2

movejob.cpp
1/*
2 Copyright (c) 2016 Daniel Vrátil <dvratil@kde.org>
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 "movejob.h"
21
22#include "job_p.h"
23#include "message_p.h"
24#include "session_p.h"
25#include "rfccodecs.h"
26
27//TODO: when custom error codes are introduced, handle the NO [TRYCREATE] response
28
29namespace KIMAP2
30{
31class MoveJobPrivate : public JobPrivate
32{
33public:
34 MoveJobPrivate(Session *session, const QString &name)
35 : JobPrivate(session, name)
36 , uidBased(false)
37 {}
38
39 ~MoveJobPrivate()
40 {}
41
42 QString mailBox;
43 ImapSet set;
44 bool uidBased;
45 ImapSet resultingUids;
46};
47}
48
49using namespace KIMAP2;
50
51MoveJob::MoveJob(Session *session)
52 : Job(*new MoveJobPrivate(session, "Move"))
53{
54 Q_D(MoveJob);
55 d->uidBased = false;
56}
57
58MoveJob::~MoveJob()
59{
60}
61
62void MoveJob::setMailBox(const QString &mailBox)
63{
64 Q_D(MoveJob);
65 d->mailBox = mailBox;
66}
67
69{
70 Q_D(const MoveJob);
71 return d->mailBox;
72}
73
75{
76 Q_D(MoveJob);
77 d->set = set;
78}
79
81{
82 Q_D(const MoveJob);
83 return d->set;
84}
85
86void MoveJob::setUidBased(bool uidBased)
87{
88 Q_D(MoveJob);
89 d->uidBased = uidBased;
90}
91
93{
94 Q_D(const MoveJob);
95 return d->uidBased;
96}
97
99{
100 Q_D(const MoveJob);
101 return d->resultingUids;
102}
103
104void MoveJob::doStart()
105{
106 Q_D(MoveJob);
107
108 d->set.optimize();
109 QByteArray parameters = d->set.toImapSequenceSet() + ' ';
110 parameters += '\"' + KIMAP2::encodeImapFolderName(d->mailBox.toUtf8()) + '\"';
111
112 QByteArray command = "MOVE";
113 if (d->uidBased) {
114 command = "UID " + command;
115 }
116
117 d->sendCommand(command, parameters);
118}
119
120void MoveJob::handleResponse(const Message &response)
121{
122 Q_D(MoveJob);
123
124 for (QList<Message::Part>::ConstIterator it = response.responseCode.begin();
125 it != response.responseCode.end(); ++it) {
126 if (it->toString() == "COPYUID") {
127 it = it + 3;
128 if (it < response.responseCode.end()) {
129 d->resultingUids = ImapSet::fromImapSequenceSet(it->toString());
130 }
131 break;
132 }
133 }
134
135 handleErrorReplies(response);
136}
Represents a set of natural numbers (1->∞) in a as compact as possible form.
Definition imapset.h:142
static ImapSet fromImapSequenceSet(const QByteArray &sequence)
Return the set corresponding to the given IMAP-compatible QByteArray representation.
Definition imapset.cpp:294
Moves messages from current mailbox to another.
Definition movejob.h:46
bool isUidBased() const
How to interpret the sequence set.
Definition movejob.cpp:92
void setSequenceSet(const ImapSet &set)
Sets the messages to be moved,.
Definition movejob.cpp:74
ImapSet sequenceSet() const
The messages that will be moved.
Definition movejob.cpp:80
ImapSet resultingUids() const
The UIDs of the moved messages in the destination mailbox.
Definition movejob.cpp:98
QString mailBox() const
The destination mailbox.
Definition movejob.cpp:68
void setUidBased(bool uidBased)
Set how the sequence set should be interpreted.
Definition movejob.cpp:86
void setMailBox(const QString &mailbox)
Set the destination mailbox.
Definition movejob.cpp:62
QString name(GameStandardAction id)
This file is part of the IMAP support library and defines the RfcCodecs class.
KIMAP2_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 29 2024 11:56:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.