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 "rfccodecs.h"
14 #include "session_p.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)
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 
38 using namespace KIMAP;
39 
40 CopyJob::CopyJob(Session *session)
41  : Job(*new CopyJobPrivate(session, i18n("Copy")))
42 {
43  Q_D(CopyJob);
44  d->uidBased = false;
45 }
46 
47 CopyJob::~CopyJob()
48 {
49 }
50 
51 void 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 
75 void CopyJob::setUidBased(bool uidBased)
76 {
77  Q_D(CopyJob);
78  d->uidBased = uidBased;
79 }
80 
81 bool CopyJob::isUidBased() const
82 {
83  Q_D(const CopyJob);
84  return d->uidBased;
85 }
86 
88 {
89  Q_D(const CopyJob);
90  return d->resultingUids;
91 }
92 
93 void 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 
109 void 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"
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:180
static ImapSet fromImapSequenceSet(const QByteArray &sequence)
Return the set corresponding to the given IMAP-compatible QByteArray representation.
Definition: imapset.cpp:285
ImapSet resultingUids() const
The UIDs of the new copies of the messages.
Definition: copyjob.cpp:87
void setSequenceSet(const ImapSet &set)
Sets the messages to be copied.
Definition: copyjob.cpp:63
QString i18n(const char *text, const TYPE &arg...)
Represents a set of natural numbers (1->∞) in a as compact as possible form.
Definition: imapset.h:126
bool isUidBased() const
How to interpret the sequence set.
Definition: copyjob.cpp:81
QString mailBox() const
The destination mailbox.
Definition: copyjob.cpp:57
const char * name(StandardAction id)
ImapSet sequenceSet() const
The messages that will be copied.
Definition: copyjob.cpp:69
Copies one or more messages to another mailbox.
Definition: copyjob.h:32
void setMailBox(const QString &mailBox)
Sets the destination mailbox.
Definition: copyjob.cpp:51
void setUidBased(bool uidBased)
Set how the sequence set should be interpreted.
Definition: copyjob.cpp:75
Provides handlers for various RFC/MIME encodings.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 10 2023 03:48:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.