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

KIMAP Library

  • sources
  • kde-4.12
  • kdepimlibs
  • 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/KLocalizedString>
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, QLatin1String(response.toString().constData()) ) );
102  if ( response.content[2].toString() == "[ANNOTATEMORE TOOMANY]" ||
103  response.content[2].toString() == "[METADATA TOOMANY]" ) {
104  d->metaDataErrors |= TooMany;
105  } else if ( response.content[2].toString() == "[ANNOTATEMORE TOOBIG]" ||
106  response.content[2].toString().startsWith( "[METADATA MAXSIZE" ) ) { //krazy:exclude=strings
107  d->metaDataErrors |= TooBig;
108  d->maxAcceptedSize = -1;
109  if ( response.content[2].toString().startsWith( "[METADATA MAXSIZE" ) ) { //krazy:exclude=strings
110  QByteArray max = response.content[2].toString();
111  max.replace( "[METADATA MAXSIZE", "" ); //krazy:exclude=doublequote_chars
112  max.replace( "]", "" ); //krazy:exclude=doublequote_chars
113  d->maxAcceptedSize = max.toLongLong();
114  }
115  } else if ( response.content[2].toString() == "[METADATA NOPRIVATE]" ) {
116  d->metaDataErrors |= NoPrivate;
117  }
118  } else if ( response.content.size() < 2 ) {
119  setErrorText( i18n( "%1 failed, malformed reply from the server.", d->m_name ) );
120  } else if ( response.content[1].toString() != "OK" ) {
121  setError( UserDefinedError );
122  setErrorText( i18n( "%1 failed, server replied: %2", d->m_name, QLatin1String(response.toString().constData()) ) );
123  }
124  emitResult();
125  } else if ( d->serverCapability == Metadata && response.content[0].toString() == "+" ) {
126  QByteArray content = d->entriesIt.value();
127  ++d->entriesIt;
128  if ( d->entriesIt == d->entries.constEnd() ) {
129  content += ')';
130  } else {
131  content += " {" + QByteArray::number( d->entriesIt.value().size() ) + '}';
132  }
133 // kDebug() << "SENT: " << content;
134  d->sessionInternal()->sendData( content );
135  }
136 }
137 
138 void SetMetaDataJob::addMetaData(const QByteArray &name, const QByteArray &value)
139 {
140  Q_D( SetMetaDataJob );
141  d->entries[name] = value;
142 }
143 
144 void SetMetaDataJob::setEntry(const QByteArray &entry)
145 {
146  Q_D( SetMetaDataJob );
147  d->entryName = entry;
148 }
149 
150 SetMetaDataJob::MetaDataErrors SetMetaDataJob::metaDataErrors() const
151 {
152  Q_D( const SetMetaDataJob );
153  return d->metaDataErrors;
154 }
rfccodecs.h
This file is part of the IMAP support library and defines the RfcCodecs class.
KIMAP::MetaDataJobBase::Annotatemore
Used to indicate that the server supports the draft-daboo-imap-annotatemore-07 version of the extensi...
Definition: metadatajobbase.h:75
KIMAP::SetMetaDataJob::metaDataErrors
MetaDataErrors metaDataErrors() const
The metadata errors received from the server.
Definition: setmetadatajob.cpp:150
KIMAP::SetMetaDataJob::addMetaData
void addMetaData(const QByteArray &name, const QByteArray &value)
Adds a metadata entry or attribute to the list of modifications to make.
Definition: setmetadatajob.cpp:138
KIMAP::SetMetaDataJob::TooMany
Cannot add a new metadata item, because the limit has already been reached.
Definition: setmetadatajob.h:181
KIMAP::SetMetaDataJob::TooBig
A metadata value was too big (see maxAcceptedSize())
Definition: setmetadatajob.h:182
KIMAP::SetMetaDataJob::setEntry
void setEntry(const QByteArray &entry)
Sets the metadata entry name to operate on (in Annotatemore mode)
Definition: setmetadatajob.cpp:144
KIMAP::MetaDataJobBase
Base class for jobs that operate on mailbox metadata.
Definition: metadatajobbase.h:47
KIMAP::MetaDataJobBase::Metadata
Used to indicate that the server supports the RFC 5464 version of the extension.
Definition: metadatajobbase.h:68
KIMAP::SetMetaDataJob
Sets mailbox metadata.
Definition: setmetadatajob.h:68
KIMAP::SetMetaDataJob::NoPrivate
The server does not support private metadata entries.
Definition: setmetadatajob.h:183
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:08 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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