• 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
getmetadatajob.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 "getmetadatajob.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 GetMetaDataJobPrivate : public MetaDataJobBasePrivate
33  {
34  public:
35  GetMetaDataJobPrivate( Session *session, const QString& name ) : MetaDataJobBasePrivate( session, name ), maxSize( -1 ), depth( "0" ) { }
36  ~GetMetaDataJobPrivate() { }
37 
38  qint64 maxSize;
39  QByteArray depth;
40  QList<QByteArray> entries;
41  QList<QByteArray> attributes;
42  QMap<QString, QMap<QByteArray, QMap<QByteArray, QByteArray> > > metadata;
43  // ^ mailbox ^ entry ^attribute ^ value
44  };
45 }
46 
47 using namespace KIMAP;
48 
49 GetMetaDataJob::GetMetaDataJob( Session *session )
50  : MetaDataJobBase( *new GetMetaDataJobPrivate( session, i18n( "GetMetaData" ) ) )
51 {
52 }
53 
54 GetMetaDataJob::~GetMetaDataJob()
55 {
56 }
57 
58 void GetMetaDataJob::doStart()
59 {
60  Q_D( GetMetaDataJob );
61  QByteArray parameters;
62  parameters = '\"' + KIMAP::encodeImapFolderName( d->mailBox.toUtf8() ) + "\" ";
63 
64  QByteArray command = "GETMETADATA";
65  if ( d->serverCapability == Annotatemore ) {
66  d->m_name = i18n( "GetAnnotation" );
67  command = "GETANNOTATION";
68  if ( d->entries.size() > 1 ) {
69  parameters += '(';
70  }
71  Q_FOREACH ( const QByteArray &entry, d->entries ) {
72  parameters += '\"' + entry + "\" ";
73  }
74  if ( d->entries.size() > 1 ) {
75  parameters[parameters.length() - 1 ] = ')';
76  } else {
77  parameters.truncate( parameters.length() - 1 );
78  }
79 
80  parameters += ' ';
81 
82  if ( d->attributes.size() > 1 ) {
83  parameters += '(';
84  }
85  Q_FOREACH ( const QByteArray &attribute, d->attributes ) {
86  parameters += '\"' + attribute + "\" ";
87  }
88  if ( d->attributes.size() > 1 ) {
89  parameters[parameters.length() - 1 ] = ')';
90  } else {
91  parameters.truncate( parameters.length() - 1 );
92  }
93 
94  } else {
95  if ( d->depth != "0" ) {
96  parameters += "(DEPTH " + d->depth;
97  }
98  if ( d->maxSize != -1 ) {
99  parameters += "(MAXSIZE " + QByteArray::number( d->maxSize ) + ')';
100  }
101  if ( d->depth != "0" ) {
102  parameters += ") ";
103  }
104 
105  if ( d->entries.size() >= 1 ) {
106  parameters += '(';
107  Q_FOREACH ( const QByteArray &entry, d->entries ) {
108  parameters += entry + " ";
109  }
110  parameters[parameters.length() - 1 ] = ')';
111  }
112  }
113 
114  if ( d->entries.isEmpty() ) { {
115  parameters += ')';
116  }
117  }
118 
119  d->tags << d->sessionInternal()->sendCommand( command, parameters );
120 // kDebug() << "SENT: " << command << " " << parameters;
121 }
122 
123 void GetMetaDataJob::handleResponse( const Message &response )
124 {
125  Q_D( GetMetaDataJob );
126 // kDebug() << "GOT: " << response.toString();
127 
128  //TODO: handle NO error messages having [METADATA MAXSIZE NNN], [METADATA TOOMANY], [METADATA NOPRIVATE] (see rfc5464)
129  // or [ANNOTATEMORE TOOBIG], [ANNOTATEMORE TOOMANY] respectively
130  if ( handleErrorReplies( response ) == NotHandled ) {
131  if ( response.content.size() >= 4 ) {
132  if ( d->serverCapability == Annotatemore && response.content[1].toString() == "ANNOTATION" ) {
133  QString mailBox = QString::fromUtf8( KIMAP::decodeImapFolderName( response.content[2].toString() ) );
134 
135  int i = 3;
136  while ( i < response.content.size() - 1 ) {
137  QByteArray entry = response.content[i].toString();
138  QList<QByteArray> attributes = response.content[i + 1].toList();
139  int j = 0;
140  while ( j < attributes.size() - 1 ) {
141  d->metadata[mailBox][entry][attributes[j]] = attributes[j + 1];
142  j += 2;
143  }
144  i += 2;
145  }
146  } else if ( d->serverCapability == Metadata && response.content[1].toString() == "METADATA" ) {
147  QString mailBox = QString::fromUtf8( KIMAP::decodeImapFolderName( response.content[2].toString() ) );
148 
149  QList<QByteArray> entries = response.content[3].toList();
150  int i = 0;
151  while ( i < entries.size() - 1 ) {
152  d->metadata[mailBox][entries[i]][""] = entries[i + 1];
153  i += 2;
154  }
155  }
156  }
157  }
158 }
159 
160 void GetMetaDataJob::addEntry(const QByteArray &entry, const QByteArray &attribute)
161 {
162  Q_D( GetMetaDataJob );
163  if ( d->serverCapability == Annotatemore && attribute.isNull() ) {
164  qWarning() << "In ANNOTATEMORE mode an attribute must be specified with addEntry!";
165  }
166  d->entries.append( entry );
167  d->attributes.append( attribute );
168 }
169 
170 void GetMetaDataJob::setMaximumSize(qint64 size)
171 {
172  Q_D( GetMetaDataJob );
173  d->maxSize = size;
174 }
175 
176 void GetMetaDataJob::setDepth(Depth depth)
177 {
178  Q_D( GetMetaDataJob );
179 
180  switch ( depth ) {
181  case OneLevel:
182  d->depth = "1"; //krazy:exclude=doublequote_chars
183  break;
184  case AllLevels:
185  d->depth = "infinity";
186  break;
187  default:
188  d->depth = "0"; //krazy:exclude=doublequote_chars
189  }
190 }
191 
192 QByteArray GetMetaDataJob::metaData(const QString &mailBox, const QByteArray &entry, const QByteArray &attribute) const
193 {
194  Q_D( const GetMetaDataJob );
195  QByteArray attr = attribute;
196 
197  if ( d->serverCapability == Metadata ) {
198  attr = "";
199  }
200 
201  QByteArray result;
202  if ( d->metadata.contains( mailBox ) ) {
203  if ( d->metadata[mailBox].contains( entry ) ) {
204  result = d->metadata[mailBox][entry].value( attr );
205  }
206  }
207  return result;
208 }
209 
210 QMap<QByteArray, QMap<QByteArray, QByteArray> > GetMetaDataJob::allMetaData(const QString &mailBox) const
211 {
212  Q_D( const GetMetaDataJob );
213  return d->metadata[mailBox];
214 }
rfccodecs.h
This file is part of the IMAP support library and defines the RfcCodecs class.
KIMAP::GetMetaDataJob::metaData
QByteArray metaData(const QString &mailBox, const QByteArray &entry, const QByteArray &attribute=QByteArray()) const
Get a single metadata entry.
Definition: getmetadatajob.cpp:192
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::GetMetaDataJob::OneLevel
The requested entries and all their direct children.
Definition: getmetadatajob.h:77
KIMAP::GetMetaDataJob::allMetaData
QMap< QByteArray, QMap< QByteArray, QByteArray > > allMetaData(const QString &mailBox) const
Get all the metadata for a given mailbox.
Definition: getmetadatajob.cpp:210
KIMAP::MetaDataJobBase::mailBox
QString mailBox() const
The mailbox that will be acted upon.
Definition: metadatajobbase.cpp:50
KIMAP::GetMetaDataJob::addEntry
void addEntry(const QByteArray &entry, const QByteArray &attribute=QByteArray())
Add an entry to the query list.
Definition: getmetadatajob.cpp:160
KIMAP::GetMetaDataJob
Fetches mailbox metadata.
Definition: getmetadatajob.h:61
KIMAP::GetMetaDataJob::Depth
Depth
Used to specify the depth of the metadata heirachy to walk.
Definition: getmetadatajob.h:75
KIMAP::GetMetaDataJob::setMaximumSize
void setMaximumSize(qint64 size)
Limits the size of returned metadata entries.
Definition: getmetadatajob.cpp:170
KIMAP::MetaDataJobBase
Base class for jobs that operate on mailbox metadata.
Definition: metadatajobbase.h:47
KIMAP::GetMetaDataJob::setDepth
void setDepth(Depth depth)
Sets whether to retrieve children or descendants of the requested entries.
Definition: getmetadatajob.cpp:176
KIMAP::GetMetaDataJob::AllLevels
The requested entries and all their descendants.
Definition: getmetadatajob.h:78
KIMAP::MetaDataJobBase::Metadata
Used to indicate that the server supports the RFC 5464 version of the extension.
Definition: metadatajobbase.h:68
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