• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.5 API Reference
  • KDE Home
  • Contact Us
 

KIMAP Library

  • kimap
setmetadatajob.cpp
1 /*
2  Copyright (c) 2009 Andras Mantia <amantia@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 "setmetadatajob.h"
21 
22 #include <KDE/KLocale>
23 #include <KDE/KDebug>
24 
25 #include "metadatajobbase_p.h"
26 #include "message_p.h"
27 #include "session_p.h"
28 #include "rfccodecs.h"
29 
30 namespace KIMAP
31 {
32  class SetMetaDataJobPrivate : public MetaDataJobBasePrivate
33  {
34  public:
35  SetMetaDataJobPrivate( Session *session, const QString& name ) : MetaDataJobBasePrivate(session, name), metaDataErrors(0), maxAcceptedSize(-1) { }
36  ~SetMetaDataJobPrivate() { }
37 
38  QMap<QByteArray, QByteArray> entries;
39  QMap<QByteArray, QByteArray>::ConstIterator entriesIt;
40  QByteArray entryName;
41  SetMetaDataJob::MetaDataErrors metaDataErrors;
42  qint64 maxAcceptedSize;
43  };
44 }
45 
46 using namespace KIMAP;
47 
48 SetMetaDataJob::SetMetaDataJob( Session *session )
49  : MetaDataJobBase( *new SetMetaDataJobPrivate(session, i18n("SetMetaData")) )
50 {
51 }
52 
53 SetMetaDataJob::~SetMetaDataJob()
54 {
55 }
56 
57 void SetMetaDataJob::doStart()
58 {
59  Q_D(SetMetaDataJob);
60  QByteArray parameters;
61  parameters = '\"' + KIMAP::encodeImapFolderName( d->mailBox.toUtf8() ) + "\" ";
62  d->entriesIt = d->entries.constBegin();
63 
64  QByteArray command = "SETMETADATA";
65  if (d->serverCapability == Annotatemore) {
66  command = "SETANNOTATION";
67  parameters += '\"' + d->entryName + "\" (";
68  d->m_name = i18n("SetAnnotation");
69  if (!d->entries.isEmpty()) {
70  for (; d->entriesIt != d->entries.constEnd(); ++d->entriesIt) {
71  parameters += '\"' + d->entriesIt.key() + "\" \"" + d->entriesIt.value() + "\" ";
72  }
73  parameters[parameters.length() - 1] = ')';
74  }
75  } else {
76  parameters += '(';
77  if (!d->entries.isEmpty()) {
78  parameters += '\"' + d->entriesIt.key() + '\"';
79  parameters += ' ';
80  parameters +=" {" + QByteArray::number(d->entriesIt.value().size()) + '}';
81  }
82  }
83 
84  if (d->entries.isEmpty()) {
85  parameters += ')';
86  }
87 
88  d->tags << d->sessionInternal()->sendCommand( command, parameters );
89 // kDebug() << "SENT: " << command << " " << parameters;
90 }
91 
92 void SetMetaDataJob::handleResponse( const Message &response )
93 {
94  Q_D(SetMetaDataJob);
95 
96  //TODO: Test if a server can really return more then one untagged NO response. If not, no need to OR the error codes
97  if ( !response.content.isEmpty()
98  && d->tags.contains( response.content.first().toString() ) ) {
99  if ( response.content[1].toString() == "NO" ) {
100  setError( UserDefinedError );
101  setErrorText( i18n("%1 failed, server replied: %2", d->m_name, response.toString().constData()) );
102  if (response.content[2].toString() == "[ANNOTATEMORE TOOMANY]" || response.content[2].toString() == "[METADATA TOOMANY]") {
103  d->metaDataErrors |= TooMany;
104  } else if (response.content[2].toString() == "[ANNOTATEMORE TOOBIG]" || response.content[2].toString().startsWith("[METADATA MAXSIZE")) {
105  d->metaDataErrors |= TooBig;
106  d->maxAcceptedSize = -1;
107  if (response.content[2].toString().startsWith("[METADATA MAXSIZE")) { //krazy:exclude=strings
108  QByteArray max = response.content[2].toString();
109  max.replace("[METADATA MAXSIZE",""); //krazy:exclude=doublequote_chars
110  max.replace("]", ""); //krazy:exclude=doublequote_chars
111  d->maxAcceptedSize = max.toLongLong();
112  }
113  } else if (response.content[2].toString() == "[METADATA NOPRIVATE]") {
114  d->metaDataErrors |= NoPrivate;
115  }
116  } else if ( response.content.size() < 2 ) {
117  setErrorText( i18n("%1 failed, malformed reply from the server.", d->m_name) );
118  } else if ( response.content[1].toString() != "OK" ) {
119  setError( UserDefinedError );
120  setErrorText( i18n("%1 failed, server replied: %2", d->m_name, response.toString().constData()) );
121  }
122  emitResult();
123  } else if ( d->serverCapability == Metadata && response.content[0].toString() == "+" ) {
124  QByteArray content = d->entriesIt.value();
125  ++d->entriesIt;
126  if (d->entriesIt == d->entries.constEnd()) {
127  content += ')';
128  } else {
129  content +=" {" + QByteArray::number(d->entriesIt.value().size()) + '}';
130  }
131 // kDebug() << "SENT: " << content;
132  d->sessionInternal()->sendData( content );
133  }
134 }
135 
136 void SetMetaDataJob::addMetaData(const QByteArray &name, const QByteArray &value)
137 {
138  Q_D(SetMetaDataJob);
139  d->entries[name] = value;
140 }
141 
142 void SetMetaDataJob::setEntry(const QByteArray &entry)
143 {
144  Q_D(SetMetaDataJob);
145  d->entryName = entry;
146 }
147 
148 SetMetaDataJob::MetaDataErrors SetMetaDataJob::metaDataErrors() const
149 {
150  Q_D(const SetMetaDataJob);
151  return d->metaDataErrors;
152 }
153 
154 #include "setmetadatajob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jan 5 2013 19:44:10 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIMAP Library

Skip menu "KIMAP Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.9.5 API Reference

Skip menu "kdepimlibs-4.9.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal