Branch 'kolab/integration/4.13.0' - 2 commits - mailcommon/CMakeLists.txt mailcommon/filter messageviewer/viewer
Sandro Knauß
knauss at kolabsys.com
Mon Mar 16 09:45:05 CET 2015
mailcommon/CMakeLists.txt | 1
mailcommon/filter/filteractionwithcommand.cpp | 12
mailcommon/filter/tests/CMakeLists.txt | 14 +
mailcommon/filter/tests/actionpipethrough.cpp | 338 ++++++++++++++++++++++++++
mailcommon/filter/tests/actionpipethrough.h | 45 +++
messageviewer/viewer/objecttreeparser.cpp | 18 -
6 files changed, 416 insertions(+), 12 deletions(-)
New commits:
commit e105bed31994700bae83755f5bba98efdcb84b19
Author: Sandro Knauà <knauss at kolabsys.com>
Date: Sat Mar 14 21:24:05 2015 +0100
use QString instead of const char*
diff --git a/messageviewer/viewer/objecttreeparser.cpp b/messageviewer/viewer/objecttreeparser.cpp
index 10e5f27..96af605 100644
--- a/messageviewer/viewer/objecttreeparser.cpp
+++ b/messageviewer/viewer/objecttreeparser.cpp
@@ -1018,22 +1018,22 @@ bool ObjectTreeParser::okDecryptMIME( KMime::Content& data,
QByteArray ciphertext = data.decodedContent();
#ifdef MARCS_DEBUG
QString cipherStr = QString::fromLatin1( ciphertext );
- bool cipherIsBinary = ( !cipherStr.contains("BEGIN ENCRYPTED MESSAGE", Qt::CaseInsensitive ) ) &&
- ( !cipherStr.contains("BEGIN PGP ENCRYPTED MESSAGE", Qt::CaseInsensitive ) ) &&
- ( !cipherStr.contains("BEGIN PGP MESSAGE", Qt::CaseInsensitive ) );
+ bool cipherIsBinary = ( !cipherStr.contains(QLatin1String("BEGIN ENCRYPTED MESSAGE"), Qt::CaseInsensitive ) ) &&
+ ( !cipherStr.contains(QLatin1String("BEGIN PGP ENCRYPTED MESSAGE"), Qt::CaseInsensitive ) ) &&
+ ( !cipherStr.contains(QLatin1String("BEGIN PGP MESSAGE"), Qt::CaseInsensitive ) );
dumpToFile( "dat_04_reader.encrypted", ciphertext.data(), ciphertext.size() );
QString deb;
- deb = "\n\nE N C R Y P T E D D A T A = ";
+ deb = QLatin1String("\n\nE N C R Y P T E D D A T A = ");
if ( cipherIsBinary )
- deb += "[binary data]";
+ deb += QLatin1String("[binary data]");
else {
- deb += "\"";
+ deb += QLatin1String("\"");
deb += cipherStr;
- deb += "\"";
+ deb += QLatin1String("\"");
}
- deb += "\n\n";
+ deb += QLatin1String("\n\n");
kDebug() << deb;
#endif
@@ -3438,7 +3438,7 @@ void ObjectTreeParser::dumpToFile( const char * filename, const char * start,
size_t len ) {
assert( filename );
- QFile f( filename );
+ QFile f( QString::fromAscii(filename) );
if ( f.open( QIODevice::WriteOnly ) ) {
if ( start ) {
QDataStream ds( &f );
commit 7735c9548eb43964b6b0daf12210c4df40869ecb
Author: Sandro Knauà <knauss at kolabsys.com>
Date: Sat Mar 14 21:14:15 2015 +0100
Do not change mails, if use pipe through filter.
For signed mails the body of the mail has not to change not even slightly.
BUG: 331991
FIXED-IN: 15.04
diff --git a/mailcommon/CMakeLists.txt b/mailcommon/CMakeLists.txt
index b602aa6..fcb00ae 100644
--- a/mailcommon/CMakeLists.txt
+++ b/mailcommon/CMakeLists.txt
@@ -212,6 +212,7 @@ set_target_properties(mailcommon PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVER
install(TARGETS mailcommon ${INSTALL_TARGETS_DEFAULT_ARGS})
add_subdirectory(filter/filterimporter/tests)
+add_subdirectory(filter/tests)
#install(FILES viewer/viewer.h viewer/attachmentstrategy.h header/headerstrategy.h messageviewer_export.h DESTINATION ${INCLUDE_INSTALL_DIR}/messageviewer COMPONENT devel)
diff --git a/mailcommon/filter/filteractionwithcommand.cpp b/mailcommon/filter/filteractionwithcommand.cpp
index 7b267d9..e15968b 100644
--- a/mailcommon/filter/filteractionwithcommand.cpp
+++ b/mailcommon/filter/filteractionwithcommand.cpp
@@ -233,7 +233,7 @@ FilterAction::ReturnCode FilterActionWithCommand::genericProcess( ItemContext &c
// read altered message:
const QByteArray msgText = shProc.readAllStandardOutput();
- if ( !msgText.isEmpty() ) {
+ if ( !msgText.isEmpty() && !msgText.trimmed().isEmpty() ) {
/* If the pipe through alters the message, it could very well
happen that it no longer has a X-UID header afterwards. That is
unfortunate, as we need to removed the original from the folder
@@ -241,10 +241,16 @@ FilterAction::ReturnCode FilterActionWithCommand::genericProcess( ItemContext &c
is uploaded, the header is stripped anyhow. */
const QString uid = aMsg->headerByType( "X-UID" ) ? aMsg->headerByType( "X-UID" )->asUnicodeString() : QString();
aMsg->setContent( KMime::CRLFtoLF( msgText ) );
+ aMsg->setFrozen(true);
aMsg->parse();
- KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-UID", aMsg.get(), uid, "utf-8" );
- aMsg->setHeader( header );
+ const QString newUid = aMsg->headerByType( "X-UID" ) ? aMsg->headerByType( "X-UID" )->asUnicodeString() : QString();
+ if (uid != newUid) {
+ aMsg->setFrozen(false);
+ KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-UID", aMsg.get(), uid, "utf-8" );
+ aMsg->setHeader( header );
+ aMsg->assemble();
+ }
context.setNeedsPayloadStore();
} else {
diff --git a/mailcommon/filter/tests/CMakeLists.txt b/mailcommon/filter/tests/CMakeLists.txt
new file mode 100644
index 0000000..9eb8c03
--- /dev/null
+++ b/mailcommon/filter/tests/CMakeLists.txt
@@ -0,0 +1,14 @@
+set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
+
+include_directories(
+ ../
+)
+
+macro( add_filter_test _source )
+ set( _test ${_source} ../filter${_source} ${ARGN})
+ get_filename_component( _name ${_source} NAME_WE )
+ kde4_add_unit_test( filter${_name}test TESTNAME filter-${_name} ${_test} )
+ target_link_libraries( filter${_name}test mailcommon kdepim ${KDEPIMLIBS_KMIME_LIBS} ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTXML_LIBRARY} ${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_KPIMIDENTITIES_LIBS})
+endmacro()
+
+add_filter_test(actionpipethrough.cpp ../filteractionwithcommand.cpp ../filteractionwithurl.cpp)
\ No newline at end of file
diff --git a/mailcommon/filter/tests/actionpipethrough.cpp b/mailcommon/filter/tests/actionpipethrough.cpp
new file mode 100644
index 0000000..090692d
--- /dev/null
+++ b/mailcommon/filter/tests/actionpipethrough.cpp
@@ -0,0 +1,338 @@
+/*
+ * Copyright (c) 2015 Sandro Knauà <bugs at sandroknauss.de>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "actionpipethrough.h"
+#include "filteractionpipethrough.h"
+#include <qtest_kde.h>
+#include <kdebug.h>
+
+using namespace MailCommon;
+
+QTEST_KDEMAIN( FilterActionPipeThroughTest, NoGUI )
+
+void FilterActionPipeThroughTest::setOutput(FilterAction *filter, const QByteArray &output)
+{
+ QByteArray sendData = output;
+ filter->argsFromString(QLatin1String("echo \"")+sendData.replace('"',"\\\"")+"\"");
+}
+
+
+void FilterActionPipeThroughTest::testWithNoCommand()
+{
+ /* No command to exceute -> no output -> error
+ */
+
+ FilterActionPipeThrough filter(this);
+ KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
+ Akonadi::Item item;
+ item.setPayload<KMime::Message::Ptr>(msgPtr);
+ ItemContext context(item, true);
+
+ filter.argsFromString("");
+ QCOMPARE(filter.process(context, false), FilterAction::ErrorButGoOn);
+ QCOMPARE(context.needsPayloadStore(), false);
+}
+
+void FilterActionPipeThroughTest::testCommandWithoutOutput()
+{
+ /* Valid command but no output -> error
+ */
+
+ FilterActionPipeThrough filter(this);
+ KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
+ Akonadi::Item item;
+ item.setPayload<KMime::Message::Ptr>(msgPtr);
+ ItemContext context(item, true);
+
+ filter.argsFromString("echo ''");
+ QCOMPARE(filter.process(context, false), FilterAction::ErrorButGoOn);
+ QCOMPARE(context.needsPayloadStore(), false);
+}
+
+void FilterActionPipeThroughTest::testWithMailOutput()
+{
+ /* Make sure that mail is not changed from output to KMIME::Message
+ * and also no assemble changes the mail
+ *
+ * Very important for not breake signatures from mails.
+ */
+ QByteArray data =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "Content-type: multipart/mixed;\n"
+ " boundary=\"simple boundary\"\n"
+ "\n"
+ "\n"
+ "--simple boundary\n"
+ "Content-type: text/plain;\n"
+ " charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n";
+
+ FilterActionPipeThrough filter(this);
+ KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
+ Akonadi::Item item;
+ item.setPayload<KMime::Message::Ptr>(msgPtr);
+ ItemContext context(item, true);
+
+ setOutput(&filter, data);
+ QCOMPARE(filter.process(context, false), FilterAction::GoOn);
+ QCOMPARE(context.needsPayloadStore(), true);
+ QByteArray expected = data + '\n';
+ QCOMPARE( msgPtr->encodedContent(), expected);
+ msgPtr->assemble(); //Make sure that the message isFrozen so no submimes do not change
+ QCOMPARE( msgPtr->encodedContent(), expected);
+}
+
+
+void FilterActionPipeThroughTest::testCopyMail()
+{
+ /* put a mail in the pipe and make sure we get the same output
+ */
+ QByteArray data =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "Content-type: multipart/mixed; boundary=\"simple boundary\"\n"
+ "\n"
+ "\n"
+ "--simple boundary\n"
+ "Content-type: text/plain; charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n";
+
+ FilterActionPipeThrough filter(this);
+ KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
+ Akonadi::Item item;
+ msgPtr->setContent(data);
+ item.setPayload<KMime::Message::Ptr>(msgPtr);
+ ItemContext context(item, true);
+
+ filter.argsFromString(QLatin1String("cat "));
+ QCOMPARE(filter.process(context, false), FilterAction::GoOn);
+ QCOMPARE(context.needsPayloadStore(), true);
+ QCOMPARE(msgPtr->encodedContent(), data);
+}
+
+void FilterActionPipeThroughTest::testXUidUnchange()
+{
+ // the X-UID header isn't changed -> mail isn't changed anyhow
+ QByteArray data =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "X-UID: XXXX1\n"
+ "Content-type: multipart/mixed;\n"
+ " boundary=\"simple boundary\"\n"
+ "\n"
+ "\n"
+ "--simple boundary\n"
+ "Content-type: text/plain;\n"
+ " charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n";
+
+ FilterActionPipeThrough filter(this);
+ KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
+ Akonadi::Item item;
+ msgPtr->setContent(data);
+ msgPtr->parse();
+ item.setPayload<KMime::Message::Ptr>(msgPtr);
+ ItemContext context(item, true);
+
+ filter.argsFromString(QLatin1String("cat "));
+ QCOMPARE(filter.process(context, false), FilterAction::GoOn);
+ QCOMPARE(context.needsPayloadStore(), true);
+ QCOMPARE(QString::fromAscii(msgPtr->encodedContent()), QString::fromAscii(data));
+}
+
+void FilterActionPipeThroughTest::testXUidRemoved()
+{
+ /* Make sure if the X-Uid is removed from pipe through, that we add it again
+ * but we have to assemble the mail, so we create some changes in the header.
+ * More important is, that the body isn't changed.
+ */
+
+ QByteArray data =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "X-UID: XXXX1\n"
+ "Content-type: multipart/mixed;\n"
+ " boundary=\"simple boundary\"\n"
+ "\n"
+ "\n"
+ "--simple boundary\n"
+ "Content-type: text/plain;\n"
+ " charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n";
+
+ QByteArray send =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "Content-type: multipart/mixed;\n"
+ " boundary=\"simple boundary\"\n"
+ "\n"
+ "\n"
+ "--simple boundary\n"
+ "Content-type: text/plain;\n"
+ " charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n";
+
+ QByteArray output =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800\n" // <- this is removed, because we assemble
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "Content-Type: multipart/mixed; boundary=\"simple boundary\"\n" // <- this nweline is removed, because we assemble
+ "X-UID: XXXX1\n"
+ "\n"
+ "\n"
+ "--simple boundary\n" // <- body isn't changed
+ "Content-type: text/plain;\n"
+ " charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n"
+ "\n";
+
+ FilterActionPipeThrough filter(this);
+ KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
+ Akonadi::Item item;
+ msgPtr->setContent(data);
+ msgPtr->parse();
+ item.setPayload<KMime::Message::Ptr>(msgPtr);
+ ItemContext context(item, true);
+ setOutput(&filter, send);
+ QCOMPARE(filter.process(context, false), FilterAction::GoOn);
+ QCOMPARE(context.needsPayloadStore(), true);
+ QCOMPARE(msgPtr->encodedContent(), output);
+}
+
+void FilterActionPipeThroughTest::testXUidChange()
+{
+ /* Make sure if the X-Uid is changed from pipe through, that we put is to the original value again.
+ * The mail is assembled again, so we create some changes in the header.
+ * More important is, that the body isn't changed.
+ */
+
+ QByteArray data =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "X-UID: XXXX1\n"
+ "Content-type: multipart/mixed;\n"
+ " boundary=\"simple boundary\"\n"
+ "\n"
+ "\n"
+ "--simple boundary\n"
+ "Content-type: text/plain;\n"
+ " charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n";
+
+ QByteArray send =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "X-UID: XXXX2\n"
+ "Content-type: multipart/mixed;\n"
+ " boundary=\"simple boundary\"\n"
+ "\n"
+ "\n"
+ "--simple boundary\n"
+ "Content-type: text/plain;\n"
+ " charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n";
+
+ QByteArray output =
+ "From: Nathaniel Borenstein <nsb at bellcore.com>\n"
+ "To: Ned Freed <ned at innosoft.com>\n"
+ "Date: Sun, 21 Mar 1993 23:56:48 -0800\n" // <- this is removed, because we assemble
+ "Subject: Sample message\n"
+ "MIME-Version: 1.0\n"
+ "Content-Type: multipart/mixed; boundary=\"simple boundary\"\n" // <- this nweline is removed, because we assemble
+ "X-UID: XXXX1\n"
+ "\n"
+ "\n"
+ "--simple boundary\n" // <- body isn't changed
+ "Content-type: text/plain;\n"
+ " charset=us-ascii\n"
+ "\n"
+ "This is explicitly typed plain US-ASCII text.\n"
+ "It DOES end with a linebreak.\n"
+ "\n"
+ "--simple boundary--\n"
+ "\n";
+
+ FilterActionPipeThrough filter(this);
+ KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
+ Akonadi::Item item;
+ msgPtr->setContent(data);
+ msgPtr->parse();
+ item.setPayload<KMime::Message::Ptr>(msgPtr);
+ ItemContext context(item, true);
+ setOutput(&filter, send);
+ QCOMPARE(filter.process(context, false), FilterAction::GoOn);
+ QCOMPARE(context.needsPayloadStore(), true);
+ QCOMPARE(msgPtr->encodedContent(), output);
+}
\ No newline at end of file
diff --git a/mailcommon/filter/tests/actionpipethrough.h b/mailcommon/filter/tests/actionpipethrough.h
new file mode 100644
index 0000000..f6ae086
--- /dev/null
+++ b/mailcommon/filter/tests/actionpipethrough.h
@@ -0,0 +1,45 @@
+/*
+ Copyright (c) 2015 Sandro Knauà <bugs at sandroknauss.de>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
+ License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#ifndef ACTIONPIPETHROUGH_TEST_H
+#define ACTIONPIPETHROUGH_TEST_H
+
+#include <QtCore/QObject>
+
+namespace MailCommon {
+ class FilterAction;
+}
+
+class FilterActionPipeThroughTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void testWithNoCommand();
+ void testCommandWithoutOutput();
+ void testWithMailOutput();
+ void testCopyMail();
+ void testXUidChange();
+ void testXUidUnchange();
+ void testXUidRemoved();
+private:
+ void setOutput(MailCommon::FilterAction *filter, const QByteArray &output);
+};
+
+
+#endif
More information about the commits
mailing list