KIMAP2

movejob.cpp
1 /*
2  Copyright (c) 2016 Daniel Vrátil <[email protected]>
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 
29 namespace KIMAP2
30 {
31 class MoveJobPrivate : public JobPrivate
32 {
33 public:
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 
49 using namespace KIMAP2;
50 
51 MoveJob::MoveJob(Session *session)
52  : Job(*new MoveJobPrivate(session, "Move"))
53 {
54  Q_D(MoveJob);
55  d->uidBased = false;
56 }
57 
58 MoveJob::~MoveJob()
59 {
60 }
61 
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 
86 void MoveJob::setUidBased(bool uidBased)
87 {
88  Q_D(MoveJob);
89  d->uidBased = uidBased;
90 }
91 
92 bool MoveJob::isUidBased() const
93 {
94  Q_D(const MoveJob);
95  return d->uidBased;
96 }
97 
99 {
100  Q_D(const MoveJob);
101  return d->resultingUids;
102 }
103 
104 void 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 
120 void 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 }
This file is part of the IMAP support library and defines the RfcCodecs class.
void setUidBased(bool uidBased)
Set how the sequence set should be interpreted.
Definition: movejob.cpp:86
QString mailBox() const
The destination mailbox.
Definition: movejob.cpp:68
KIMAP2_EXPORT QString encodeImapFolderName(const QString &src)
Converts an Unicode IMAP mailbox to a QString which can be used in IMAP communication.
Definition: rfccodecs.cpp:192
ImapSet sequenceSet() const
The messages that will be moved.
Definition: movejob.cpp:80
void setMailBox(const QString &mailbox)
Set the destination mailbox.
Definition: movejob.cpp:62
void setSequenceSet(const ImapSet &set)
Sets the messages to be moved,.
Definition: movejob.cpp:74
Represents a set of natural numbers (1->∞) in a as compact as possible form.
Definition: imapset.h:141
Definition: acl.cpp:25
ImapSet resultingUids() const
The UIDs of the moved messages in the destination mailbox.
Definition: movejob.cpp:98
static ImapSet fromImapSequenceSet(const QByteArray &sequence)
Return the set corresponding to the given IMAP-compatible QByteArray representation.
Definition: imapset.cpp:294
QString mailBox() const
The mailbox that will be acted upon.
Moves messages from current mailbox to another.
Definition: movejob.h:45
bool isUidBased() const
How to interpret the sequence set.
Definition: movejob.cpp:92
QList::iterator begin()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 23:00:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.