KIMAP2

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

KDE's Doxygen guidelines are available online.