summaryrefslogtreecommitdiffstats
path: root/examples/maildirresource
diff options
context:
space:
mode:
Diffstat (limited to 'examples/maildirresource')
-rw-r--r--examples/maildirresource/CMakeLists.txt2
-rw-r--r--examples/maildirresource/maildirresource.cpp8
-rw-r--r--examples/maildirresource/tests/CMakeLists.txt2
-rw-r--r--examples/maildirresource/tests/data/maildir1/test/cur/1365777830.R28.localhost.localdomain:2,S72
-rw-r--r--examples/maildirresource/tests/maildirmailsynctest.cpp132
5 files changed, 214 insertions, 2 deletions
diff --git a/examples/maildirresource/CMakeLists.txt b/examples/maildirresource/CMakeLists.txt
index 3a1430c..e4d113c 100644
--- a/examples/maildirresource/CMakeLists.txt
+++ b/examples/maildirresource/CMakeLists.txt
@@ -11,5 +11,7 @@ target_link_libraries(${PROJECT_NAME} sink maildir KF5::Mime)
11 11
12install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SINK_RESOURCE_PLUGINS_PATH}) 12install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SINK_RESOURCE_PLUGINS_PATH})
13 13
14add_definitions(-DTESTDATAPATH="${CMAKE_CURRENT_SOURCE_DIR}/tests/data")
15
14add_subdirectory(libmaildir) 16add_subdirectory(libmaildir)
15add_subdirectory(tests) 17add_subdirectory(tests)
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index ca20fa3..268f506 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -373,7 +373,11 @@ public:
373 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE 373 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE
374 { 374 {
375 Log() << " Synchronizing"; 375 Log() << " Synchronizing";
376 return KAsync::start<void>([this]() { 376 return KAsync::start<void, KAsync::Job<void> >([this]() {
377 KPIM::Maildir maildir(mMaildirPath, true);
378 if (!maildir.isValid(false)) {
379 return KAsync::error<void>(1, "Maildir path doesn't point to a valid maildir: " + mMaildirPath);
380 }
377 synchronizeFolders(); 381 synchronizeFolders();
378 //The next sync needs the folders available 382 //The next sync needs the folders available
379 commit(); 383 commit();
@@ -385,6 +389,7 @@ public:
385 commitSync(); 389 commitSync();
386 } 390 }
387 Log() << "Done Synchronizing"; 391 Log() << "Done Synchronizing";
392 return KAsync::null<void>();
388 }); 393 });
389 } 394 }
390 395
@@ -410,7 +415,6 @@ public:
410 }); 415 });
411 } else if (operation == Sink::Operation_Removal) { 416 } else if (operation == Sink::Operation_Removal) {
412 Trace() << "Removing a mail: " << oldRemoteId; 417 Trace() << "Removing a mail: " << oldRemoteId;
413 // QFile::remove(oldRemoteId);
414 return KAsync::null<QByteArray>(); 418 return KAsync::null<QByteArray>();
415 } else if (operation == Sink::Operation_Modification) { 419 } else if (operation == Sink::Operation_Modification) {
416 Trace() << "Modifying a mail: " << oldRemoteId; 420 Trace() << "Modifying a mail: " << oldRemoteId;
diff --git a/examples/maildirresource/tests/CMakeLists.txt b/examples/maildirresource/tests/CMakeLists.txt
index ffe9286..d6f0fe7 100644
--- a/examples/maildirresource/tests/CMakeLists.txt
+++ b/examples/maildirresource/tests/CMakeLists.txt
@@ -7,5 +7,7 @@ include(SinkTest)
7 7
8auto_tests ( 8auto_tests (
9 maildirmailtest 9 maildirmailtest
10 maildirmailsynctest
10) 11)
11target_link_libraries(maildirmailtest sink_resource_maildir) 12target_link_libraries(maildirmailtest sink_resource_maildir)
13target_link_libraries(maildirmailsynctest sink_resource_maildir)
diff --git a/examples/maildirresource/tests/data/maildir1/test/cur/1365777830.R28.localhost.localdomain:2,S b/examples/maildirresource/tests/data/maildir1/test/cur/1365777830.R28.localhost.localdomain:2,S
new file mode 100644
index 0000000..91231b5
--- /dev/null
+++ b/examples/maildirresource/tests/data/maildir1/test/cur/1365777830.R28.localhost.localdomain:2,S
@@ -0,0 +1,72 @@
1Return-Path: <nepomuk-bounces@kde.org>
2Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44])
3 by slots3a1p1 (Cyrus git2.5+0-git-fastmail-8998) with LMTPA;
4 Mon, 11 Mar 2013 14:28:42 -0400
5X-Sieve: CMU Sieve 2.4
6X-Spam-score: 0.0
7X-Spam-hits: BAYES_00 -1.9, RCVD_IN_DNSWL_MED -2.3, RP_MATCHES_RCVD -0.704,
8 LANGUAGES unknown, BAYES_USED global, SA_VERSION 3.3.1
9X-Spam-source: IP='46.4.96.248', Host='postbox.kde.org', Country='unk', FromHeader='org',
10 MailFrom='org'
11X-Spam-charsets: plain='us-ascii'
12X-Resolved-to: chrigi_1@fastmail.fm
13X-Delivered-to: chrigi_1@fastmail.fm
14X-Mail-from: nepomuk-bounces@kde.org
15Received: from mx4.nyi.mail.srv.osa ([10.202.2.203])
16 by compute4.internal (LMTPProxy); Mon, 11 Mar 2013 14:28:42 -0400
17Received: from postbox.kde.org (postbox.kde.org [46.4.96.248])
18 by mx4.messagingengine.com (Postfix) with ESMTP id 1C9D2440F88
19 for <chrigi_1@fastmail.fm>; Mon, 11 Mar 2013 14:28:42 -0400 (EDT)
20Received: from postbox.kde.org (localhost [IPv6:::1])
21 by postbox.kde.org (Postfix) with ESMTP id 00FFEB3732B;
22 Mon, 11 Mar 2013 18:28:40 +0000 (UTC)
23DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=kde.org; s=default;
24 t=1363026520; bh=cOdvyBAJJ8ho64q0H7rxkl+cB2y6TiyVOX0fO3yZ64U=;
25 h=Date:From:To:Message-ID:In-Reply-To:References:MIME-Version:
26 Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:
27 List-Subscribe:Content-Type:Content-Transfer-Encoding:Sender; b=dv
28 dJAFu+6JCuNun5WIuP4ysfKpLh0DeuhEEfy2cQavUGMICJ27k7tI73x6gN37V5Q/evJ
29 NDFna3/IhNBsAQeLiXs28HKxzcVhbnq5jdFR6fbyo6k1fOKt5vTT1GTDZ+3zIGPD1CU
30 ioDBGxPb/Ds6gee90tjadOj6o+Oc+2ZSq94=
31X-Original-To: nepomuk@kde.org
32X-Remote-Delivered-To: nepomuk@localhost.kde.org
33Received: from build.kde.org (build.kde.org [IPv6:2a01:4f8:160:9363::5])
34 by postbox.kde.org (Postfix) with ESMTP id 4491CB3732B
35 for <nepomuk@kde.org>; Mon, 11 Mar 2013 18:28:27 +0000 (UTC)
36Received: from localhost ([127.0.0.1]) by build.kde.org with esmtp (Exim 4.72)
37 (envelope-from <null@kde.org>) id 1UF7SV-0000gs-11
38 for nepomuk@kde.org; Mon, 11 Mar 2013 18:28:27 +0000
39Date: Mon, 11 Mar 2013 18:28:27 +0000 (UTC)
40From: KDE CI System <null@kde.org>
41To: nepomuk@kde.org
42Message-ID: <1977027405.27.1363026507008.JavaMail.jenkins@build>
43In-Reply-To: <880663748.26.1363026023717.JavaMail.jenkins@build>
44References: <880663748.26.1363026023717.JavaMail.jenkins@build>
45MIME-Version: 1.0
46X-Jenkins-Job: nepomuk-core_stable
47X-Jenkins-Result: UNSTABLE
48X-Scanned-By: MIMEDefang 2.71 on 46.4.96.248
49Subject: [Nepomuk] Jenkins build is still unstable: nepomuk-core_stable #158
50X-BeenThere: nepomuk@kde.org
51X-Mailman-Version: 2.1.14
52Precedence: list
53List-Id: The Semantic KDE <nepomuk.kde.org>
54List-Unsubscribe: <https://mail.kde.org/mailman/options/nepomuk>,
55 <mailto:nepomuk-request@kde.org?subject=unsubscribe>
56List-Archive: <http://mail.kde.org/pipermail/nepomuk>
57List-Post: <mailto:nepomuk@kde.org>
58List-Help: <mailto:nepomuk-request@kde.org?subject=help>
59List-Subscribe: <https://mail.kde.org/mailman/listinfo/nepomuk>,
60 <mailto:nepomuk-request@kde.org?subject=subscribe>
61Content-Type: text/plain; charset="us-ascii"
62Content-Transfer-Encoding: 7bit
63Errors-To: nepomuk-bounces@kde.org
64Sender: nepomuk-bounces@kde.org
65X-Truedomain: NotChecked
66
67See <http://build.kde.org/job/nepomuk-core_stable/changes>
68
69_______________________________________________
70Nepomuk mailing list
71Nepomuk@kde.org
72https://mail.kde.org/mailman/listinfo/nepomuk
diff --git a/examples/maildirresource/tests/maildirmailsynctest.cpp b/examples/maildirresource/tests/maildirmailsynctest.cpp
new file mode 100644
index 0000000..444fb42
--- /dev/null
+++ b/examples/maildirresource/tests/maildirmailsynctest.cpp
@@ -0,0 +1,132 @@
1/*
2 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#include <QtTest>
20
21#include <tests/mailsynctest.h>
22#include "../maildirresource.h"
23#include "../libmaildir/maildir.h"
24
25#include "common/test.h"
26#include "common/domain/applicationdomaintype.h"
27
28using namespace Sink;
29using namespace Sink::ApplicationDomain;
30
31static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
32{
33 QFileInfo srcFileInfo(srcFilePath);
34 if (srcFileInfo.isDir()) {
35 QDir targetDir(tgtFilePath);
36 targetDir.cdUp();
37 if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) {
38 qWarning() << "Failed to create directory " << tgtFilePath;
39 return false;
40 }
41 QDir sourceDir(srcFilePath);
42 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
43 foreach (const QString &fileName, fileNames) {
44 const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName;
45 const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName;
46 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
47 return false;
48 }
49 } else {
50 if (!QFile::copy(srcFilePath, tgtFilePath)) {
51 qWarning() << "Failed to copy file " << tgtFilePath;
52 return false;
53 }
54 }
55 return true;
56}
57
58/**
59 * Test of complete system using the maildir resource.
60 *
61 * This test requires the maildir resource installed.
62 */
63class MaildirMailSyncTest : public Sink::MailSyncTest
64{
65 Q_OBJECT
66
67 QTemporaryDir tempDir;
68 QString targetPath;
69
70protected:
71 void resetTestEnvironment() Q_DECL_OVERRIDE
72 {
73 targetPath = tempDir.path() + "/maildir1/";
74 QDir dir(targetPath);
75 dir.removeRecursively();
76 copyRecursively(TESTDATAPATH "/maildir1", targetPath);
77 }
78
79 Sink::ApplicationDomain::SinkResource createResource() Q_DECL_OVERRIDE
80 {
81 auto resource = ApplicationDomain::MaildirResource::create("account1");
82 resource.setProperty("path", targetPath);
83 return resource;
84 }
85
86 Sink::ApplicationDomain::SinkResource createFaultyResource() Q_DECL_OVERRIDE
87 {
88 auto resource = ApplicationDomain::MaildirResource::create("account1");
89 resource.setProperty("path", "");
90 return resource;
91 }
92
93 void removeResourceFromDisk(const QByteArray &identifier) Q_DECL_OVERRIDE
94 {
95 ::MaildirResource::removeFromDisk(identifier);
96 }
97
98 void createFolder(const QStringList &folderPath) Q_DECL_OVERRIDE
99 {
100 auto rootPath = tempDir.path() + "/maildir1/";
101 KPIM::Maildir maildir(rootPath + folderPath.join('/'), false);
102 maildir.create();
103 }
104
105 void removeFolder(const QStringList &folderPath) Q_DECL_OVERRIDE
106 {
107 auto rootPath = tempDir.path() + "/maildir1/";
108 KPIM::Maildir maildir(rootPath + folderPath.join('/'), false);
109 maildir.remove();
110 QDir dir(rootPath + folderPath.join('/'));
111 dir.removeRecursively();
112 // QVERIFY(maildir.removeSubFolder(name));
113 }
114
115 QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE
116 {
117 auto rootPath = tempDir.path() + "/maildir1/";
118 KPIM::Maildir maildir(rootPath + folderPath.join('/'));
119 return maildir.addEntry(message).toUtf8();
120 }
121
122 void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE
123 {
124 auto rootPath = tempDir.path() + "/maildir1/";
125 KPIM::Maildir maildir(rootPath + folderPath.join('/'));
126 maildir.removeEntry(messageIdentifier);
127 }
128};
129
130QTEST_MAIN(MaildirMailSyncTest)
131
132#include "maildirmailsynctest.moc"