KIMAP

copyjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]>
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 "session_p.h"
14 #include "rfccodecs.h"
15 
16 //TODO: when custom error codes are introduced, handle the NO [TRYCREATE] response
17 
18 namespace KIMAP
19 {
20 class CopyJobPrivate : public JobPrivate
21 {
22 public:
23  CopyJobPrivate(Session *session, const QString &name) : JobPrivate(session, name) { }
24  ~CopyJobPrivate() { }
25 
26  QString mailBox;
27  ImapSet set;
28  bool uidBased = false;
29  ImapSet resultingUids;
30 };
31 }
32 
33 using namespace KIMAP;
34 
35 CopyJob::CopyJob(Session *session)
36  : Job(*new CopyJobPrivate(session, i18n("Copy")))
37 {
38  Q_D(CopyJob);
39  d->uidBased = false;
40 }
41 
42 CopyJob::~CopyJob()
43 {
44 }
45 
46 void CopyJob::setMailBox(const QString &mailBox)
47 {
48  Q_D(CopyJob);
49  d->mailBox = mailBox;
50 }
51 
53 {
54  Q_D(const CopyJob);
55  return d->mailBox;
56 }
57 
59 {
60  Q_D(CopyJob);
61  d->set = set;
62 }
63 
65 {
66  Q_D(const CopyJob);
67  return d->set;
68 }
69 
70 void CopyJob::setUidBased(bool uidBased)
71 {
72  Q_D(CopyJob);
73  d->uidBased = uidBased;
74 }
75 
76 bool CopyJob::isUidBased() const
77 {
78  Q_D(const CopyJob);
79  return d->uidBased;
80 }
81 
83 {
84  Q_D(const CopyJob);
85  return d->resultingUids;
86 }
87 
88 void CopyJob::doStart()
89 {
90  Q_D(CopyJob);
91 
92  d->set.optimize();
93  QByteArray parameters = d->set.toImapSequenceSet() + ' ';
94  parameters += '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"';
95 
96  QByteArray command = "COPY";
97  if (d->uidBased) {
98  command = "UID " + command;
99  }
100 
101  d->tags << d->sessionInternal()->sendCommand(command, parameters);
102 }
103 
104 void CopyJob::handleResponse(const Response &response)
105 {
106  Q_D(CopyJob);
107  for (auto it = response.responseCode.cbegin(), end = response.responseCode.cend();
108  it != end; ++it) {
109  if (it->toString() == "COPYUID") {
110  it = it + 3;
111  if (it < end) {
112  d->resultingUids = ImapSet::fromImapSequenceSet(it->toString());
113  }
114  break;
115  }
116  }
117 
118  handleErrorReplies(response);
119 }
This file is part of the IMAP support library and defines the RfcCodecs class.
void setMailBox(const QString &mailBox)
Sets the destination mailbox.
Definition: copyjob.cpp:46
ImapSet sequenceSet() const
The messages that will be copied.
Definition: copyjob.cpp:64
void setUidBased(bool uidBased)
Set how the sequence set should be interpreted.
Definition: copyjob.cpp:70
void setSequenceSet(const ImapSet &set)
Sets the messages to be copied.
Definition: copyjob.cpp:58
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:178
QString mailBox() const
The destination mailbox.
Definition: copyjob.cpp:52
bool isUidBased() const
How to interpret the sequence set.
Definition: copyjob.cpp:76
Represents a set of natural numbers (1->∞) in a as compact as possible form.
Definition: imapset.h:128
QString i18n(const char *text, const TYPE &arg...)
static ImapSet fromImapSequenceSet(const QByteArray &sequence)
Return the set corresponding to the given IMAP-compatible QByteArray representation.
Definition: imapset.cpp:281
ImapSet resultingUids() const
The UIDs of the new copies of the messages.
Definition: copyjob.cpp:82
Definition: acl.cpp:12
Copies one or more messages to another mailbox.
Definition: copyjob.h:34
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Oct 24 2020 23:16:51 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.