Commit c215c5a3 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Don't update annotations when server does not support it

Don't try to update annotations when server does not have METADATA or
ANNOTATEMORE capability.

Fixes a warning shown when user changed something in Folder properties
in KMail

BUG: 284527
FIXED-IN: 4.11.3
parent 4b23d9be
......@@ -22,6 +22,7 @@
#include "addcollectiontask.h"
#include "collectionannotationsattribute.h"
#include <accountwizard/ispdb/ispdb.h>
#include <KDE/KDebug>
#include <KDE/KLocale>
......@@ -107,7 +108,7 @@ void AddCollectionTask::onSubscribeDone( KJob *job )
}
const Akonadi::CollectionAnnotationsAttribute *attribute = m_collection.attribute<Akonadi::CollectionAnnotationsAttribute>();
if ( !attribute ) {
if ( !attribute || !serverSupportsAnnotations() ) {
// we are finished
changeCommitted( m_collection );
synchronizeCollectionTree();
......@@ -125,7 +126,7 @@ void AddCollectionTask::onSubscribeDone( KJob *job )
}
QByteArray attribute = entry;
if ( job->serverCapability()==KIMAP::MetaDataJobBase::Annotatemore ) {
if ( job->serverCapability() == KIMAP::MetaDataJobBase::Annotatemore ) {
attribute = "value.shared";
}
......
......@@ -120,7 +120,7 @@ void ChangeCollectionTask::doStart( KIMAP::Session *session )
}
}
if ( parts().contains( "collectionannotations" ) ) {
if ( parts().contains( "collectionannotations" ) && serverSupportsAnnotations() ) {
Akonadi::CollectionAnnotationsAttribute *annotationsAttribute =
collection().attribute<Akonadi::CollectionAnnotationsAttribute>();
......
......@@ -29,6 +29,7 @@
#include "imapflags.h"
#include "sessionpool.h"
#include "resourcestateinterface.h"
#include <accountwizard/ispdb/ispdb.h>
ResourceTask::ResourceTask( ActionIfNoSession action, ResourceStateInterface::Ptr resource, QObject *parent )
: QObject( parent ),
......@@ -449,5 +450,11 @@ void ResourceTask::setSeparatorCharacter( const QChar& separator )
m_resource->setSeparatorCharacter( separator );
}
bool ResourceTask::serverSupportsAnnotations() const
{
return serverCapabilities().contains( QLatin1String( "METADATA" ) )
|| serverCapabilities().contains( QLatin1String( "ANNOTATEMORE" ) );
}
#include "resourcetask.moc"
......@@ -129,6 +129,8 @@ protected:
static QList<QByteArray> toAkonadiFlags( const QList<QByteArray> &flags );
bool serverSupportsAnnotations() const;
private:
static QList<QByteArray> fromAkonadiFlags( const QList<QByteArray> &flags );
......
......@@ -38,6 +38,7 @@ private slots:
QTest::addColumn< QList<QByteArray> >( "scenario" );
QTest::addColumn<QStringList>( "callNames" );
QTest::addColumn<QString>( "collectionName" );
QTest::addColumn<bool>( "supportsAnnotations" );
Akonadi::Collection collection;
QSet<QByteArray> parts;
......@@ -91,7 +92,21 @@ private slots:
callNames.clear();
callNames << "collectionChangeCommitted";
QTest::newRow( "complete case" ) << collection << parts << scenario << callNames << collection.name();
QTest::newRow( "complete case" ) << collection << parts << scenario << callNames << collection.name() << true;
scenario.clear();
scenario << defaultPoolConnectionScenario()
<< "C: A000003 SETACL \"Foo\" \"test@kdab.com\" \"lrswipckxtda\""
<< "S: A000003 OK acl changed"
<< "C: A000004 SETACL \"Foo\" \"foo@kde.org\" \"lrswipcda\""
<< "S: A000004 OK acl changed"
<< "C: A000005 SETACL \"Foo\" \"test@kdab.com\" \"lrswipckxtda\""
<< "S: A000005 OK acl changed"
<< "C: A000006 RENAME \"Foo\" \"Bar\""
<< "S: A000006 OK rename done"
<< "C: A000007 SUBSCRIBE \"Bar\""
<< "S: A000007 OK mailbox subscribed";
QTest::newRow( "no ANNOTATEMORE support" ) << collection << parts << scenario << callNames << collection.name() << false;
collection = Akonadi::Collection( 1 );
collection.setName( "Bar/Baz" );
......@@ -107,7 +122,7 @@ private slots:
callNames.clear();
callNames << "collectionChangeCommitted";
QTest::newRow( "rename with invalid separator" ) << collection << parts << scenario << callNames
<< "BarBaz";
<< "BarBaz" << true;
}
void shouldUpdateMetadataAclAndName()
......@@ -117,6 +132,7 @@ private slots:
QFETCH( QList<QByteArray>, scenario );
QFETCH( QStringList, callNames );
QFETCH( QString, collectionName );
QFETCH( bool, supportsAnnotations );
FakeServer server;
server.setScenario( scenario );
......@@ -128,9 +144,14 @@ private slots:
QVERIFY( pool.connect( createDefaultAccount() ) );
QVERIFY( waitForSignal( &pool, SIGNAL(connectDone(int,QString)) ) );
QStringList caps;
caps << QLatin1String( "ACL" );
if ( supportsAnnotations ) {
caps << QLatin1String( "ANNOTATEMORE" );
}
DummyResourceState::Ptr state = DummyResourceState::Ptr( new DummyResourceState );
state->setUserName( defaultUserName() );
state->setServerCapabilities( QStringList() << "ANNOTATEMORE" << "ACL" );
state->setServerCapabilities( caps );
state->setCollection( collection );
state->setParts( parts );
ChangeCollectionTask *task = new ChangeCollectionTask( state );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment