KIMAP2

appendjob.cpp
1 /*
2  Copyright (c) 2009 Kevin Ottens <[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 "appendjob.h"
21 
22 #include "job_p.h"
23 #include "message_p.h"
24 #include "session_p.h"
25 #include "rfccodecs.h"
26 
27 namespace KIMAP2
28 {
29 class AppendJobPrivate : public JobPrivate
30 {
31 public:
32  AppendJobPrivate(Session *session, const QString &name) : JobPrivate(session, name), uid(0) { }
33  ~AppendJobPrivate() { }
34 
35  QString mailBox;
36  QList<QByteArray> flags;
37  QDateTime internalDate;
38  QByteArray content;
39  qint64 uid;
40 };
41 }
42 
43 using namespace KIMAP2;
44 
45 AppendJob::AppendJob(Session *session)
46  : Job(*new AppendJobPrivate(session, "Append"))
47 {
48 }
49 
50 AppendJob::~AppendJob()
51 {
52 }
53 
55 {
56  Q_D(AppendJob);
57  d->mailBox = mailBox;
58 }
59 
61 {
62  Q_D(const AppendJob);
63  return d->mailBox;
64 }
65 
67 {
68  Q_D(AppendJob);
69  d->flags = flags;
70 }
71 
73 {
74  Q_D(const AppendJob);
75  return d->flags;
76 }
77 
78 void AppendJob::setInternalDate(const QDateTime &internalDate)
79 {
80  Q_D(AppendJob);
81  d->internalDate = internalDate;
82 }
83 
85 {
86  Q_D(const AppendJob);
87  return d->internalDate;
88 }
89 
90 void AppendJob::setContent(const QByteArray &content)
91 {
92  Q_D(AppendJob);
93  d->content = content;
94 }
95 
97 {
98  Q_D(const AppendJob);
99  return d->content;
100 }
101 
102 qint64 AppendJob::uid() const
103 {
104  Q_D(const AppendJob);
105  return d->uid;
106 }
107 
108 void 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 
133 void 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 }
This file is part of the IMAP support library and defines the RfcCodecs class.
QDateTime toUTC() const const
QList< QByteArray > flags() const
The flags that will be set on the appended message.
Definition: appendjob.cpp:72
QString toString(qlonglong i) const const
QString mailBox() const
The mailbox that the message will be appended to.
Definition: appendjob.cpp:60
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
void chop(int n)
QLocale c()
QDateTime internalDate() const
The internal date that will be set on the appended message.
Definition: appendjob.cpp:84
QByteArray number(int n, int base)
void setFlags(const QList< QByteArray > &flags)
Set the flags that should be applied to the appended message.
Definition: appendjob.cpp:66
Definition: acl.cpp:25
QByteArray content() const
The content that the message will have.
Definition: appendjob.cpp:96
void setMailBox(const QString &mailBox)
Set the mailbox to append the message to.
Definition: appendjob.cpp:54
QByteArray toLatin1() const const
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 will be acted upon.
Definition: acljobbase.cpp:86
Appends a message to a mailbox.
Definition: appendjob.h:44
qint64 uid() const
The UID of the new message.
Definition: appendjob.cpp:102
void setContent(const QByteArray &content)
The content of the message.
Definition: appendjob.cpp:90
QList::iterator begin()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jun 6 2020 23:03:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.