KIMAP

appendjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Kevin Ottens <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "appendjob.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 
17 namespace KIMAP
18 {
19 class AppendJobPrivate : public JobPrivate
20 {
21 public:
22  AppendJobPrivate(Session *session, const QString &name) : JobPrivate(session, name) { }
23  ~AppendJobPrivate() { }
24 
25  QString mailBox;
26  QList<QByteArray> flags;
27  QDateTime internalDate;
28  QByteArray content;
29  qint64 uid = 0;
30 };
31 }
32 
33 using namespace KIMAP;
34 
35 AppendJob::AppendJob(Session *session)
36  : Job(*new AppendJobPrivate(session, i18n("Append")))
37 {
38 }
39 
40 AppendJob::~AppendJob()
41 {
42 }
43 
45 {
46  Q_D(AppendJob);
47  d->mailBox = mailBox;
48 }
49 
51 {
52  Q_D(const AppendJob);
53  return d->mailBox;
54 }
55 
57 {
58  Q_D(AppendJob);
59  d->flags = flags;
60 }
61 
63 {
64  Q_D(const AppendJob);
65  return d->flags;
66 }
67 
68 void AppendJob::setInternalDate(const QDateTime &internalDate)
69 {
70  Q_D(AppendJob);
71  d->internalDate = internalDate;
72 }
73 
75 {
76  Q_D(const AppendJob);
77  return d->internalDate;
78 }
79 
80 void AppendJob::setContent(const QByteArray &content)
81 {
82  Q_D(AppendJob);
83  d->content = content;
84 }
85 
87 {
88  Q_D(const AppendJob);
89  return d->content;
90 }
91 
92 qint64 AppendJob::uid() const
93 {
94  Q_D(const AppendJob);
95  return d->uid;
96 }
97 
98 void AppendJob::doStart()
99 {
100  Q_D(AppendJob);
101 
102  QByteArray parameters = '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"';
103 
104  if (!d->flags.isEmpty()) {
105  parameters += " (";
106  for (const QByteArray &flag : qAsConst(d->flags)) {
107  parameters += flag + ' ';
108  }
109  parameters.chop(1);
110  parameters += ')';
111  }
112 
113  if (!d->internalDate.isNull()) {
114  const QDateTime utcDateTime = d->internalDate.toUTC();
115  parameters += " \"" + QLocale::c().toString(utcDateTime, QStringLiteral("dd-MMM-yyyy hh:mm:ss")).toLatin1() + " +0000" + '\"';
116  }
117 
118  parameters += " {" + QByteArray::number(d->content.size()) + '}';
119 
120  d->tags << d->sessionInternal()->sendCommand("APPEND", parameters);
121 }
122 
123 void AppendJob::handleResponse(const Response &response)
124 {
125  Q_D(AppendJob);
126  const QList<Response::Part>::ConstIterator end(response.responseCode.end());
127  for (QList<Response::Part>::ConstIterator it = response.responseCode.begin();
128  it != end; ++it) {
129  if (it->toString() == "APPENDUID") {
130  it = it + 2;
131  if (it != end) {
132  d->uid = it->toString().toLongLong();
133  }
134  break;
135  }
136  }
137 
138  if (handleErrorReplies(response) == NotHandled) {
139  if (!response.content.isEmpty() && response.content[0].toString() == "+") {
140  d->sessionInternal()->sendData(d->content);
141  }
142  }
143 }
This file is part of the IMAP support library and defines the RfcCodecs class.
QDateTime toUTC() const const
void setFlags(const QList< QByteArray > &flags)
Set the flags that should be applied to the appended message.
Definition: appendjob.cpp:56
void setInternalDate(const QDateTime &internalDate)
Set the internal date that should be applied to the appended message.
Definition: appendjob.cpp:68
QString toString(qlonglong i) const const
qint64 uid() const
The UID of the new message.
Definition: appendjob.cpp:92
void chop(int n)
void setContent(const QByteArray &content)
The content of the message.
Definition: appendjob.cpp:80
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
void setMailBox(const QString &mailBox)
Set the mailbox to append the message to.
Definition: appendjob.cpp:44
QByteArray content() const
The content that the message will have.
Definition: appendjob.cpp:86
QLocale c()
QByteArray number(int n, int base)
QString mailBox() const
The mailbox that the message will be appended to.
Definition: appendjob.cpp:50
QString i18n(const char *text, const TYPE &arg...)
QByteArray toLatin1() const const
QList< QByteArray > flags() const
The flags that will be set on the appended message.
Definition: appendjob.cpp:62
Definition: acl.cpp:12
Appends a message to a mailbox.
Definition: appendjob.h:31
QString mailBox() const
The mailbox that will be acted upon.
Definition: acljobbase.cpp:76
QList::iterator begin()
QDateTime internalDate() const
The internal date that will be set on the appended message.
Definition: appendjob.cpp:74
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.