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 "rfccodecs.h"
14 #include "session_p.h"
15 
16 namespace KIMAP
17 {
18 class AppendJobPrivate : public JobPrivate
19 {
20 public:
21  AppendJobPrivate(Session *session, const QString &name)
22  : JobPrivate(session, name)
23  {
24  }
25  ~AppendJobPrivate()
26  {
27  }
28 
29  QString mailBox;
30  QList<QByteArray> flags;
31  QDateTime internalDate;
32  QByteArray content;
33  qint64 uid = 0;
34 };
35 }
36 
37 using namespace KIMAP;
38 
39 AppendJob::AppendJob(Session *session)
40  : Job(*new AppendJobPrivate(session, i18n("Append")))
41 {
42 }
43 
44 AppendJob::~AppendJob()
45 {
46 }
47 
48 void AppendJob::setMailBox(const QString &mailBox)
49 {
50  Q_D(AppendJob);
51  d->mailBox = mailBox;
52 }
53 
55 {
56  Q_D(const AppendJob);
57  return d->mailBox;
58 }
59 
61 {
62  Q_D(AppendJob);
63  d->flags = flags;
64 }
65 
67 {
68  Q_D(const AppendJob);
69  return d->flags;
70 }
71 
72 void AppendJob::setInternalDate(const QDateTime &internalDate)
73 {
74  Q_D(AppendJob);
75  d->internalDate = internalDate;
76 }
77 
79 {
80  Q_D(const AppendJob);
81  return d->internalDate;
82 }
83 
84 void AppendJob::setContent(const QByteArray &content)
85 {
86  Q_D(AppendJob);
87  d->content = content;
88 }
89 
91 {
92  Q_D(const AppendJob);
93  return d->content;
94 }
95 
96 qint64 AppendJob::uid() const
97 {
98  Q_D(const AppendJob);
99  return d->uid;
100 }
101 
102 void 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 
127 void 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"
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
Appends a message to a mailbox.
Definition: appendjob.h:29
QByteArray content() const
The content that the message will have.
Definition: appendjob.cpp:90
void setMailBox(const QString &mailBox)
Set the mailbox to append the message to.
Definition: appendjob.cpp:48
QByteArray number(int n, int base)
QByteArray toLatin1() const const
QList< QByteArray > flags() const
The flags that will be set on the appended message.
Definition: appendjob.cpp:66
void chop(int n)
void setInternalDate(const QDateTime &internalDate)
Set the internal date that should be applied to the appended message.
Definition: appendjob.cpp:72
QString i18n(const char *text, const TYPE &arg...)
QLocale c()
void setContent(const QByteArray &content)
The content of the message.
Definition: appendjob.cpp:84
QString toString(qlonglong i) const const
void setFlags(const QList< QByteArray > &flags)
Set the flags that should be applied to the appended message.
Definition: appendjob.cpp:60
QDateTime internalDate() const
The internal date that will be set on the appended message.
Definition: appendjob.cpp:78
QDateTime toUTC() const const
const char * name(StandardAction id)
qint64 uid() const
The UID of the new message.
Definition: appendjob.cpp:96
QList::iterator begin()
Provides handlers for various RFC/MIME encodings.
QString mailBox() const
The mailbox that the message will be appended to.
Definition: appendjob.cpp:54
const QList< QKeySequence > & end()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 3 2023 03:51:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.