KIMAP

copyjob.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "copyjob.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// TODO: when custom error codes are introduced, handle the NO [TRYCREATE] response
17
18namespace KIMAP
19{
20class CopyJobPrivate : public JobPrivate
21{
22public:
23 CopyJobPrivate(Session *session, const QString &name)
24 : JobPrivate(session, name)
25 {
26 }
27 ~CopyJobPrivate()
28 {
29 }
30
31 QString mailBox;
32 ImapSet set;
33 bool uidBased = false;
34 ImapSet resultingUids;
35};
36}
37
38using namespace KIMAP;
39
40CopyJob::CopyJob(Session *session)
41 : Job(*new CopyJobPrivate(session, i18n("Copy")))
42{
43 Q_D(CopyJob);
44 d->uidBased = false;
45}
46
47CopyJob::~CopyJob()
48{
49}
50
51void CopyJob::setMailBox(const QString &mailBox)
52{
53 Q_D(CopyJob);
54 d->mailBox = mailBox;
55}
56
58{
59 Q_D(const CopyJob);
60 return d->mailBox;
61}
62
64{
65 Q_D(CopyJob);
66 d->set = set;
67}
68
70{
71 Q_D(const CopyJob);
72 return d->set;
73}
74
75void CopyJob::setUidBased(bool uidBased)
76{
77 Q_D(CopyJob);
78 d->uidBased = uidBased;
79}
80
82{
83 Q_D(const CopyJob);
84 return d->uidBased;
85}
86
88{
89 Q_D(const CopyJob);
90 return d->resultingUids;
91}
92
93void CopyJob::doStart()
94{
95 Q_D(CopyJob);
96
97 d->set.optimize();
98 QByteArray parameters = d->set.toImapSequenceSet() + ' ';
99 parameters += '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"';
100
101 QByteArray command = "COPY";
102 if (d->uidBased) {
103 command = "UID " + command;
104 }
105
106 d->tags << d->sessionInternal()->sendCommand(command, parameters);
107}
108
109void CopyJob::handleResponse(const Response &response)
110{
111 Q_D(CopyJob);
112 for (auto it = response.responseCode.cbegin(), end = response.responseCode.cend(); it != end; ++it) {
113 if (it->toString() == "COPYUID") {
114 it = it + 3;
115 if (it < end) {
116 d->resultingUids = ImapSet::fromImapSequenceSet(it->toString());
117 }
118 break;
119 }
120 }
121
122 handleErrorReplies(response);
123}
124
125#include "moc_copyjob.cpp"
Copies one or more messages to another mailbox.
Definition copyjob.h:33
void setUidBased(bool uidBased)
Set how the sequence set should be interpreted.
Definition copyjob.cpp:75
QString mailBox() const
The destination mailbox.
Definition copyjob.cpp:57
void setSequenceSet(const ImapSet &set)
Sets the messages to be copied.
Definition copyjob.cpp:63
bool isUidBased() const
How to interpret the sequence set.
Definition copyjob.cpp:81
ImapSet resultingUids() const
The UIDs of the new copies of the messages.
Definition copyjob.cpp:87
ImapSet sequenceSet() const
The messages that will be copied.
Definition copyjob.cpp:69
void setMailBox(const QString &mailBox)
Sets the destination mailbox.
Definition copyjob.cpp:51
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
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.