KIMAP2

copyjob.cpp
1/*
2 Copyright (c) 2009 Andras Mantia <amantia@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 "copyjob.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 CopyJobPrivate : public JobPrivate
32{
33public:
34 CopyJobPrivate(Session *session, const QString &name) : JobPrivate(session, name), uidBased(false) { }
35 ~CopyJobPrivate() { }
36
37 QString mailBox;
38 ImapSet set;
39 bool uidBased;
40 ImapSet resultingUids;
41};
42}
43
44using namespace KIMAP2;
45
46CopyJob::CopyJob(Session *session)
47 : Job(*new CopyJobPrivate(session, "Copy"))
48{
49 Q_D(CopyJob);
50 d->uidBased = false;
51}
52
53CopyJob::~CopyJob()
54{
55}
56
57void CopyJob::setMailBox(const QString &mailBox)
58{
59 Q_D(CopyJob);
60 d->mailBox = mailBox;
61}
62
64{
65 Q_D(const CopyJob);
66 return d->mailBox;
67}
68
70{
71 Q_D(CopyJob);
72 d->set = set;
73}
74
76{
77 Q_D(const CopyJob);
78 return d->set;
79}
80
81void CopyJob::setUidBased(bool uidBased)
82{
83 Q_D(CopyJob);
84 d->uidBased = uidBased;
85}
86
88{
89 Q_D(const CopyJob);
90 return d->uidBased;
91}
92
94{
95 Q_D(const CopyJob);
96 return d->resultingUids;
97}
98
99void CopyJob::doStart()
100{
101 Q_D(CopyJob);
102
103 d->set.optimize();
104 QByteArray parameters = d->set.toImapSequenceSet() + ' ';
105 parameters += '\"' + KIMAP2::encodeImapFolderName(d->mailBox.toUtf8()) + '\"';
106
107 QByteArray command = "COPY";
108 if (d->uidBased) {
109 command = "UID " + command;
110 }
111
112 d->sendCommand(command, parameters);
113}
114
115void CopyJob::handleResponse(const Message &response)
116{
117 Q_D(CopyJob);
118
119 for (QList<Message::Part>::ConstIterator it = response.responseCode.begin();
120 it != response.responseCode.end(); ++it) {
121 if (it->toString() == "COPYUID") {
122 it = it + 3;
123 if (it < response.responseCode.end()) {
124 d->resultingUids = ImapSet::fromImapSequenceSet(it->toString());
125 }
126 break;
127 }
128 }
129
130 handleErrorReplies(response);
131}
Copies one or more messages to another mailbox.
Definition copyjob.h:48
void setUidBased(bool uidBased)
Set how the sequence set should be interpreted.
Definition copyjob.cpp:81
QString mailBox() const
The destination mailbox.
Definition copyjob.cpp:63
void setSequenceSet(const ImapSet &set)
Sets the messages to be copied.
Definition copyjob.cpp:69
bool isUidBased() const
How to interpret the sequence set.
Definition copyjob.cpp:87
ImapSet resultingUids() const
The UIDs of the new copies of the messages.
Definition copyjob.cpp:93
ImapSet sequenceSet() const
The messages that will be copied.
Definition copyjob.cpp:75
void setMailBox(const QString &mailBox)
Sets the destination mailbox.
Definition copyjob.cpp:57
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
QString name(StandardAction 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 Sat Dec 21 2024 16:56:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.