20 #include "getmetadatajob.h"
22 #include <KDE/KLocale>
25 #include "metadatajobbase_p.h"
26 #include "message_p.h"
27 #include "session_p.h"
32 class GetMetaDataJobPrivate :
public MetaDataJobBasePrivate
35 GetMetaDataJobPrivate( Session *session,
const QString& name ) : MetaDataJobBasePrivate( session, name ), maxSize( -1 ), depth(
"0" ) { }
36 ~GetMetaDataJobPrivate() { }
40 QList<QByteArray> entries;
41 QList<QByteArray> attributes;
42 QMap<QString, QMap<QByteArray, QMap<QByteArray, QByteArray> > > metadata;
47 using namespace KIMAP;
49 GetMetaDataJob::GetMetaDataJob( Session *session )
50 :
MetaDataJobBase( *new GetMetaDataJobPrivate( session, i18n(
"GetMetaData" ) ) )
54 GetMetaDataJob::~GetMetaDataJob()
58 void GetMetaDataJob::doStart()
61 QByteArray parameters;
62 parameters =
'\"' + KIMAP::encodeImapFolderName( d->mailBox.toUtf8() ) +
"\" ";
64 QByteArray command =
"GETMETADATA";
66 d->m_name = i18n(
"GetAnnotation" );
67 command =
"GETANNOTATION";
68 if ( d->entries.size() > 1 ) {
71 Q_FOREACH (
const QByteArray &entry, d->entries ) {
72 parameters +=
'\"' + entry +
"\" ";
74 if ( d->entries.size() > 1 ) {
75 parameters[parameters.length() - 1 ] =
')';
77 parameters.truncate( parameters.length() - 1 );
82 if ( d->attributes.size() > 1 ) {
85 Q_FOREACH (
const QByteArray &attribute, d->attributes ) {
86 parameters +=
'\"' + attribute +
"\" ";
88 if ( d->attributes.size() > 1 ) {
89 parameters[parameters.length() - 1 ] =
')';
91 parameters.truncate( parameters.length() - 1 );
95 if ( d->depth !=
"0" ) {
96 parameters +=
"(DEPTH " + d->depth;
98 if ( d->maxSize != -1 ) {
99 parameters +=
"(MAXSIZE " + QByteArray::number( d->maxSize ) +
')';
101 if ( d->depth !=
"0" ) {
105 if ( d->entries.size() > 1 ) {
108 Q_FOREACH (
const QByteArray &entry, d->entries ) {
109 parameters +=
'\"' + entry +
"\" ";
111 if ( d->entries.size() > 1 ) {
112 parameters[parameters.length() - 1 ] =
')';
116 if ( d->entries.isEmpty() ) { {
121 d->tags << d->sessionInternal()->sendCommand( command, parameters );
125 void GetMetaDataJob::handleResponse(
const Message &response )
132 if ( handleErrorReplies( response ) == NotHandled ) {
133 if ( response.content.size() >= 4 ) {
134 if ( d->serverCapability ==
Annotatemore && response.content[1].toString() ==
"ANNOTATION" ) {
135 QString
mailBox = QString::fromUtf8( KIMAP::decodeImapFolderName( response.content[2].toString() ) );
138 while ( i < response.content.size() - 1 ) {
139 QByteArray entry = response.content[i].toString();
140 QList<QByteArray> attributes = response.content[i + 1].toList();
142 while ( j < attributes.size() - 1 ) {
143 d->metadata[
mailBox][entry][attributes[j]] = attributes[j + 1];
148 }
else if ( d->serverCapability ==
Metadata && response.content[1].toString() ==
"METADATA" ) {
149 QString mailBox = QString::fromUtf8( KIMAP::decodeImapFolderName( response.content[2].toString() ) );
151 QList<QByteArray> entries = response.content[3].toList();
153 while ( i < entries.size() - 1 ) {
154 d->metadata[
mailBox][entries[i]][
""] = entries[i + 1];
165 if ( d->serverCapability ==
Annotatemore && attribute.isNull() ) {
166 qWarning() <<
"In ANNOTATEMORE mode an attribute must be specified with addEntry!";
168 d->entries.append( entry );
169 d->attributes.append( attribute );
187 d->depth =
"infinity";
197 QByteArray attr = attribute;
199 if ( d->serverCapability ==
Metadata ) {
204 if ( d->metadata.contains( mailBox ) ) {
205 if ( d->metadata[mailBox].contains( entry ) ) {
206 result = d->metadata[
mailBox][entry].value( attr );