KIMAP

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

KDE's Doxygen guidelines are available online.