Branch 'kolab/integration/4.13.0' - 2 commits - kimap/imapstreamparser.cpp kimap/setmetadatajob.cpp kimap/tests
Christian Mollekopf
mollekopf at kolabsys.com
Mon Dec 1 14:47:39 CET 2014
kimap/imapstreamparser.cpp | 2 -
kimap/setmetadatajob.cpp | 46 ++++++++++++++++++++++++++++---------
kimap/tests/appendjobtest.cpp | 8 +++---
kimap/tests/searchjobtest.cpp | 2 -
kimap/tests/setmetadatajobtest.cpp | 42 ++++++++++++++++++++++++++++++++-
5 files changed, 82 insertions(+), 18 deletions(-)
New commits:
commit 9741dbef17498ca83e00cd630a911ee70ac3be1a
Merge: 361ccb1 c0c16a2
Author: Christian Mollekopf <chrigi_1 at fastmail.fm>
Date: Mon Dec 1 14:45:51 2014 +0100
Merge remote-tracking branch 'kolab/dev/fix_setmetadata' into kolab/integration/4.13.0
commit c0c16a26d64ac893125755f63c227117fb3733f5
Author: Sandro Knauà <knauss at kolabsys.com>
Date: Sun Nov 23 21:10:07 2014 +0100
Fix setmetadata command
There are diffenrent issues that need to be handeled:
* so not send whitespaces two times with send size of literal {size}
* make setmetadata be aware of NIL data
* use simple form of setmetadata aka:
SETMETADATA "folder" ("key" "value")
KOLAB: #3966
diff --git a/kimap/imapstreamparser.cpp b/kimap/imapstreamparser.cpp
index 9499136..2193f7e 100644
--- a/kimap/imapstreamparser.cpp
+++ b/kimap/imapstreamparser.cpp
@@ -529,7 +529,7 @@ QByteArray ImapStreamParser::readUntilCommandEnd()
if ( m_data.at( i ) == '{' ) {
m_position = i - 1;
hasLiteral(); //init literal size
- result.append( m_data.mid( i - 1, m_position - i + 1 ) );
+ result.append( m_data.mid( i, m_position + 1 ) );
while ( !atLiteralEnd() ) {
result.append( readLiteralPart() );
}
diff --git a/kimap/setmetadatajob.cpp b/kimap/setmetadatajob.cpp
index 2938d1f..de69d79 100644
--- a/kimap/setmetadatajob.cpp
+++ b/kimap/setmetadatajob.cpp
@@ -62,22 +62,39 @@ void SetMetaDataJob::doStart()
d->entriesIt = d->entries.constBegin();
QByteArray command = "SETMETADATA";
+ bool bSimpleData = true;
+
if ( d->serverCapability == Annotatemore ) {
command = "SETANNOTATION";
- parameters += '\"' + d->entryName + "\" (";
- d->m_name = i18n( "SetAnnotation" );
- if ( !d->entries.isEmpty() ) {
+ parameters += '\"' + d->entryName + "\" ";
+ } else {
+ for ( ; d->entriesIt != d->entries.constEnd(); ++d->entriesIt ) {
+ if (d->entriesIt.value().contains('\r') || d->entriesIt.value().contains('\n')) {
+ bSimpleData = false;
+ break;
+ }
+ }
+ d->entriesIt = d->entries.constBegin();
+ }
+
+ parameters += '(';
+ if (bSimpleData == true) {
for ( ; d->entriesIt != d->entries.constEnd(); ++d->entriesIt ) {
- parameters += '\"' + d->entriesIt.key() + "\" \"" + d->entriesIt.value() + "\" ";
+ parameters += '\"' + d->entriesIt.key() + "\" ";
+ if (d->entriesIt.value().isEmpty()) {
+ parameters += "NIL";
+ } else {
+ parameters += "\"" + d->entriesIt.value() + "\"";
+ }
+ parameters += " ";
+
}
parameters[parameters.length() - 1] = ')';
- }
} else {
- parameters += '(';
if ( !d->entries.isEmpty() ) {
- parameters += '\"' + d->entriesIt.key() + '\"';
- parameters += ' ';
- parameters += " {" + QByteArray::number( d->entriesIt.value().size() ) + '}';
+ parameters += '\"' + d->entriesIt.key() + "\"";
+ int size = d->entriesIt.value().size();
+ parameters += " {" + QByteArray::number( size==0 ? 3 : size ) + '}';
}
}
@@ -123,12 +140,19 @@ void SetMetaDataJob::handleResponse( const Message &response )
}
emitResult();
} else if ( d->serverCapability == Metadata && response.content[0].toString() == "+" ) {
- QByteArray content = d->entriesIt.value();
+ QByteArray content = "";
+ if (d->entriesIt.value().isEmpty()) {
+ content += "NIL";
+ } else {
+ content += d->entriesIt.value();
+ }
++d->entriesIt;
if ( d->entriesIt == d->entries.constEnd() ) {
content += ')';
} else {
- content += " {" + QByteArray::number( d->entriesIt.value().size() ) + '}';
+ content += " \"" + d->entriesIt.key() + '\"';
+ int size = d->entriesIt.value().size();
+ content += " {" + QByteArray::number( size==0 ? 3 : size ) + '}';
}
// kDebug() << "SENT: " << content;
d->sessionInternal()->sendData( content );
diff --git a/kimap/tests/appendjobtest.cpp b/kimap/tests/appendjobtest.cpp
index bc6356b..6da354c 100644
--- a/kimap/tests/appendjobtest.cpp
+++ b/kimap/tests/appendjobtest.cpp
@@ -45,14 +45,14 @@ void testAppend_data() {
{
QList<QByteArray> scenario;
scenario << FakeServer::preauth()
- << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent"
+ << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent"
<< "S: A000001 OK APPEND completed. [ APPENDUID 492 2671 ]";
QTest::newRow( "good" ) << "INBOX" << scenario << flags << KDateTime() << QByteArray("content") << qint64(2671);
}
{
QList<QByteArray> scenario;
scenario << FakeServer::preauth()
- << "C: A000001 APPEND \"INBOX\" (\\Seen) \"26-Feb-2014 12:38:00 +0000\" {7}\r\ncontent"
+ << "C: A000001 APPEND \"INBOX\" (\\Seen) \"26-Feb-2014 12:38:00 +0000\" {7}\r\ncontent"
<< "S: A000001 OK APPEND completed. [ APPENDUID 493 2672 ]";
QTest::newRow( "good, with internalDate set" ) << "INBOX" << scenario << flags << KDateTime::fromString("2014-02-26T12:38:00Z") << QByteArray("content") << qint64(2672);
}
@@ -60,7 +60,7 @@ void testAppend_data() {
{
QList<QByteArray> scenario;
scenario << FakeServer::preauth()
- << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent"
+ << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent"
<< "S: BYE"
<< "X" ;
QTest::newRow( "bad" ) << "INBOX" << scenario << flags << KDateTime() << QByteArray("content") << qint64(0);
@@ -68,7 +68,7 @@ void testAppend_data() {
{
QList<QByteArray> scenario;
scenario << FakeServer::preauth()
- << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent"
+ << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent"
<< "S: "
<< "X" ;
QTest::newRow( "Don't crash on empty response" ) << "INBOX" << scenario << flags << KDateTime() << QByteArray("content") << qint64(0);
diff --git a/kimap/tests/searchjobtest.cpp b/kimap/tests/searchjobtest.cpp
index daa6607..602d279 100644
--- a/kimap/tests/searchjobtest.cpp
+++ b/kimap/tests/searchjobtest.cpp
@@ -72,7 +72,7 @@ void testSearch_data() {
scenario.clear();
criteria.clear();
scenario << FakeServer::preauth()
- << "C: A000001 SEARCH TO {25}\r\n<testuser at kde.testserver>"
+ << "C: A000001 SEARCH TO {25}\r\n<testuser at kde.testserver>"
<< "S: * SEARCH 1"
<< "S: A000001 OK search done";
criteria << searchPair( KIMAP::SearchJob::To, "<testuser at kde.testserver>" );
diff --git a/kimap/tests/setmetadatajobtest.cpp b/kimap/tests/setmetadatajobtest.cpp
index b5144ce..2bc2263 100644
--- a/kimap/tests/setmetadatajobtest.cpp
+++ b/kimap/tests/setmetadatajobtest.cpp
@@ -43,12 +43,52 @@ void metadata_data()
{
QList<QByteArray> scenario;
scenario << FakeServer::preauth()
- << "C: A000001 SETMETADATA \"Folder1\" (\"/shared/comment\" {14}\r\nShared comment)"
+ << "C: A000001 SETMETADATA \"Folder1\" (\"/public/comment\" \"comment2\" \"/shared/comment\" \"Shared comment\")"
<< "S: A000001 OK SETMETADATA complete";
QMap<QByteArray, QByteArray> annotations;
+ annotations.insert("/public/comment", "comment2");
annotations.insert("/shared/comment", "Shared comment");
QTest::newRow( "normal" ) << scenario << "Folder1" << annotations;
}
+ {
+ QList<QByteArray> scenario;
+ scenario << FakeServer::preauth()
+ << "C: A000001 SETMETADATA \"Folder1\" (\"/public/comment\" {8}\r\ncomment2 \"/shared/comment\" {14}\r\nShared\ncomment)"
+ << "S: A000001 OK SETMETADATA complete";
+ QMap<QByteArray, QByteArray> annotations;
+ annotations.insert("/shared/comment", "Shared\ncomment");
+ annotations.insert("/public/comment", "comment2");
+ QTest::newRow( "newline" ) << scenario << "Folder1" << annotations;
+ }
+ {
+ QList<QByteArray> scenario;
+ scenario << FakeServer::preauth()
+ << "C: A000001 SETMETADATA \"Folder1\" (\"/shared/comment\" NIL)"
+ << "S: A000001 OK SETMETADATA complete";
+ QMap<QByteArray, QByteArray> annotations;
+ annotations.insert("/shared/comment","");
+ QTest::newRow( "newline" ) << scenario << "Folder1" << annotations;
+ }
+ {
+ QList<QByteArray> scenario;
+ scenario << FakeServer::preauth()
+ << "C: A000001 SETMETADATA \"Folder1\" (\"/public/comment\" {12}\r\ncomment\ntest \"/shared/comment\" {3}\r\nNIL)"
+ << "S: A000001 OK SETMETADATA complete";
+ QMap<QByteArray, QByteArray> annotations;
+ annotations.insert("/shared/comment","");
+ annotations.insert("/public/comment", "comment\ntest");
+ QTest::newRow( "newline2" ) << scenario << "Folder1" << annotations;
+ }
+ {
+ QList<QByteArray> scenario;
+ scenario << FakeServer::preauth()
+ << "C: A000001 SETMETADATA \"Folder1\" (\"/public/comment\" {3}\r\nNIL \"/shared/comment\" {12}\r\ncomment\ntest)"
+ << "S: A000001 OK SETMETADATA complete";
+ QMap<QByteArray, QByteArray> annotations;
+ annotations.insert("/shared/comment", "comment\ntest");
+ annotations.insert("/public/comment","");
+ QTest::newRow( "newline2" ) << scenario << "Folder1" << annotations;
+ }
}
void metadata()
More information about the commits
mailing list