diff --git a/autotests/parsertest.cpp b/autotests/parsertest.cpp index a8c13ca..f34650b 100644 --- a/autotests/parsertest.cpp +++ b/autotests/parsertest.cpp @@ -1,800 +1,801 @@ /* -*- c++ -*- tests/parsertest.cpp This file is part of the testsuite of KSieve, the KDE internet mail/usenet news message filtering library. Copyright (c) 2003 Marc Mutz KSieve is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. KSieve 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include // SIZEOF_UNSIGNED_LONG #include <../src/ksieve/parser.h> using KSieve::Parser; #include <../src/ksieve/error.h> #include <../src/ksieve/scriptbuilder.h> #include #include #include using std::cout; using std::cerr; using std::endl; #include enum BuilderMethod { TaggedArgument, StringArgument, NumberArgument, CommandStart, CommandEnd, TestStart, TestEnd, TestListStart, TestListEnd, BlockStart, BlockEnd, StringListArgumentStart, StringListEntry, StringListArgumentEnd, HashComment, BracketComment, Error, Finished }; static const unsigned int MAX_RESPONSES = 100; struct TestCase { const char *name; const char *script; struct Response { BuilderMethod method; const char *string; bool boolean; } responses[MAX_RESPONSES]; } testCases[] = { // // single commands: // { "Null script", nullptr, { { Finished, nullptr, false } } }, { "Empty script", "", { { Finished, nullptr, false } } }, { "WS-only script", " \t\n\r\n", { { Finished, nullptr, false } } }, { "Bare hash comment", "#comment", { { HashComment, "comment", false }, { Finished, nullptr, false }} }, { "Bare bracket comment", "/*comment*/", { { BracketComment, "comment", false }, { Finished, nullptr, false }} }, { "Bare command", "command;", { { CommandStart, "command", false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "Bare command - missing semicolon", "command", { { CommandStart, "command", false }, { Error, "MissingSemicolonOrBlock", false }} }, { "surrounded by bracket comments", "/*comment*/command/*comment*/;/*comment*/", { { BracketComment, "comment", false }, { CommandStart, "command", false }, { BracketComment, "comment", false }, { CommandEnd, nullptr, false }, { BracketComment, "comment", false }, { Finished, nullptr, false }} }, { "surrounded by hash comments", "#comment\ncommand#comment\n;#comment", { { HashComment, "comment", false }, { CommandStart, "command", false }, { HashComment, "comment", false }, { CommandEnd, nullptr, false }, { HashComment, "comment", false }, { Finished, nullptr, false }} }, { "single tagged argument", "command :tag;", { { CommandStart, "command", false }, { TaggedArgument, "tag", false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single tagged argument - missing semicolon", "command :tag", { { CommandStart, "command", false }, { TaggedArgument, "tag", false }, { Error, "MissingSemicolonOrBlock", false }} }, { "single string argument - quoted string", "command \"string\";", { { CommandStart, "command", false }, { StringArgument, "string", false /*quoted*/ }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single string argument - multi-line string", "command text:\nstring\n.\n;", { { CommandStart, "command", false }, { StringArgument, "string", true /*multiline*/ }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single number argument - 100", "command 100;", { { CommandStart, "command", false }, { NumberArgument, "100 ", false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single number argument - 100k", "command 100k;", { { CommandStart, "command", false }, { NumberArgument, "102400k", false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single number argument - 100M", "command 100M;", { { CommandStart, "command", false }, { NumberArgument, "104857600M", false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single number argument - 2G", "command 2G;", { { CommandStart, "command", false }, { NumberArgument, "2147483648G", false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, #if SIZEOF_UNSIGNED_LONG == 8 # define ULONG_MAX_STRING "18446744073709551615" # define ULONG_MAXP1_STRING "18446744073709551616" #elif SIZEOF_UNSIGNED_LONG == 4 # define ULONG_MAX_STRING "4294967295" # define ULONG_MAXP1_STRING "4G" #else # error sizeof( unsigned long ) != 4 && sizeof( unsigned long ) != 8 ??? #endif { "single number argument - ULONG_MAX + 1", "command " ULONG_MAXP1_STRING ";", { { CommandStart, "command", false }, { Error, "NumberOutOfRange", false }} }, { "single number argument - ULONG_MAX", "command " ULONG_MAX_STRING ";", { { CommandStart, "command", false }, { NumberArgument, ULONG_MAX_STRING " ", false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single one-element string list argument - quoted string", "command [\"string\"];", { { CommandStart, "command", false }, { StringListArgumentStart, nullptr, false }, { StringListEntry, "string", false /*quoted*/ }, { StringListArgumentEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single one-element string list argument - multi-line string", "command [text:\nstring\n.\n];", { { CommandStart, "command", false }, { StringListArgumentStart, nullptr, false }, { StringListEntry, "string", true /*multiline*/ }, { StringListArgumentEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single two-element string list argument - quoted strings", "command [\"string\",\"string\"];", { { CommandStart, "command", false }, { StringListArgumentStart, nullptr, false }, { StringListEntry, "string", false /*quoted*/ }, { StringListEntry, "string", false /*quoted*/ }, { StringListArgumentEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single two-element string list argument - multi-line strings", "command [text:\nstring\n.\n,text:\nstring\n.\n];", { { CommandStart, "command", false }, { StringListArgumentStart, nullptr, false }, { StringListEntry, "string", true /*multiline*/ }, { StringListEntry, "string", true /*multiline*/ }, { StringListArgumentEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single two-element string list argument - quoted + multi-line strings", "command [\"string\",text:\nstring\n.\n];", { { CommandStart, "command", false }, { StringListArgumentStart, nullptr, false }, { StringListEntry, "string", false /*quoted*/ }, { StringListEntry, "string", true /*multiline*/ }, { StringListArgumentEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single two-element string list argument - multi-line + quoted strings", "command [text:\nstring\n.\n,\"string\"];", { { CommandStart, "command", false }, { StringListArgumentStart, nullptr, false }, { StringListEntry, "string", true /*multiline*/ }, { StringListEntry, "string", false /*quoted*/ }, { StringListArgumentEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "single bare test argument", "command test;", { { CommandStart, "command", false }, { TestStart, "test", false }, { TestEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "one-element test list argument", "command(test);", { { CommandStart, "command", false }, { TestListStart, nullptr, false }, { TestStart, "test", false }, { TestEnd, nullptr, false }, { TestListEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "two-element test list argument", "command(test,test);", { { CommandStart, "command", false }, { TestListStart, nullptr, false }, { TestStart, "test", false }, { TestEnd, nullptr, false }, { TestStart, "test", false }, { TestEnd, nullptr, false }, { TestListEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "zero-element block", "command{}", { { CommandStart, "command", false }, { BlockStart, nullptr, false }, { BlockEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "one-element block", "command{command;}", { { CommandStart, "command", false }, { BlockStart, nullptr, false }, { CommandStart, "command", false }, { CommandEnd, nullptr, false }, { BlockEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "two-element block", "command{command;command;}", { { CommandStart, "command", false }, { BlockStart, nullptr, false }, { CommandStart, "command", false }, { CommandEnd, nullptr, false }, { CommandStart, "command", false }, { CommandEnd, nullptr, false }, { BlockEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, { "command with a test with a test with a test", "command test test test;", { { CommandStart, "command", false }, { TestStart, "test", false }, { TestStart, "test", false }, { TestStart, "test", false }, { TestEnd, nullptr, false }, { TestEnd, nullptr, false }, { TestEnd, nullptr, false }, { CommandEnd, nullptr, false }, { Finished, nullptr, false }} }, }; static const int numTestCases = sizeof testCases / sizeof *testCases; // Prints out the parse tree in XML-like format. For visual inspection // (manual tests). class PrintingScriptBuilder : public KSieve::ScriptBuilder { public: PrintingScriptBuilder() : KSieve::ScriptBuilder() , indent(0) { write(""); } private: int indent; void write(const char *msg) { for (int i = 2 * indent; i > 0; --i) { cout << " "; } cout << msg << endl; } void write(const QByteArray &key, const QString &value) { if (value.isEmpty()) { write(QByteArray(QByteArray("<") + key + QByteArray("/>")).constData()); return; } write(QByteArray(QByteArray("<") + key + QByteArray(">")).constData()); ++indent; write(value.toUtf8().data()); --indent; write(QByteArray(QByteArray("")).constData()); } }; // verifes that methods get called with expected arguments (and in // expected sequence) as specified by the TestCase. For automated // tests. class VerifyingScriptBuilder : public KSieve::ScriptBuilder { public: VerifyingScriptBuilder(const TestCase &testCase) : KSieve::ScriptBuilder() , mNextResponse(0) , mTestCase(testCase) , mOk(true) { } - virtual ~VerifyingScriptBuilder() + ~VerifyingScriptBuilder() override { } bool ok() const { return mOk; } void taggedArgument(const QString &tag) override { checkIs(TaggedArgument); checkEquals(tag); ++mNextResponse; } void stringArgument(const QString &string, bool multiline, const QString & /*fixme*/) override { checkIs(StringArgument); checkEquals(string); checkEquals(multiline); ++mNextResponse; } void numberArgument(unsigned long number, char quantifier) override { checkIs(NumberArgument); checkEquals(QString::number(number) + QLatin1Char(quantifier ? quantifier : ' ')); ++mNextResponse; } void commandStart(const QString &identifier, int lineNumber) override { Q_UNUSED(lineNumber); checkIs(CommandStart); checkEquals(identifier); ++mNextResponse; } void commandEnd(int lineNumber) override { Q_UNUSED(lineNumber); checkIs(CommandEnd); ++mNextResponse; } void testStart(const QString &identifier) override { checkIs(TestStart); checkEquals(identifier); ++mNextResponse; } void testEnd() override { checkIs(TestEnd); ++mNextResponse; } void testListStart() override { checkIs(TestListStart); ++mNextResponse; } void testListEnd() override { checkIs(TestListEnd); ++mNextResponse; } void blockStart(int lineNumber) override { Q_UNUSED(lineNumber); checkIs(BlockStart); ++mNextResponse; } void blockEnd(int lineNumber) override { Q_UNUSED(lineNumber); checkIs(BlockEnd); ++mNextResponse; } void stringListArgumentStart() override { checkIs(StringListArgumentStart); ++mNextResponse; } void stringListEntry(const QString &string, bool multiLine, const QString & /*fixme*/) override { checkIs(StringListEntry); checkEquals(string); checkEquals(multiLine); ++mNextResponse; } void stringListArgumentEnd() override { checkIs(StringListArgumentEnd); ++mNextResponse; } void hashComment(const QString &comment) override { checkIs(HashComment); checkEquals(comment); ++mNextResponse; } void bracketComment(const QString &comment) override { checkIs(BracketComment); checkEquals(comment); ++mNextResponse; } void lineFeed() override { // FIXME } void error(const KSieve::Error &error) override { checkIs(Error); checkEquals(QString::fromLatin1(KSieve::Error::typeToString(error.type()))); ++mNextResponse; } void finished() override { checkIs(Finished); //++mNextResponse (no!) } private: + Q_DISABLE_COPY(VerifyingScriptBuilder) const TestCase::Response ¤tResponse() const { assert(mNextResponse <= MAX_RESPONSES); return mTestCase.responses[mNextResponse]; } void checkIs(BuilderMethod m) { if (currentResponse().method != m) { cerr << " expected method " << (int)currentResponse().method << ", got " << (int)m; mOk = false; } } void checkEquals(const QString &s) { if (s != QString::fromUtf8(currentResponse().string)) { cerr << " expected string arg \"" << (currentResponse().string ? currentResponse().string : "") << "\", got \"" << (s.isNull() ? "" : s.toUtf8().data()) << "\""; mOk = false; } } void checkEquals(bool b) { if (b != currentResponse().boolean) { cerr << " expected boolean arg <" << currentResponse().boolean << ">, got <" << b << ">"; mOk = false; } } unsigned int mNextResponse; const TestCase &mTestCase; bool mOk; }; int main(int argc, char *argv[]) { if (argc == 2) { // manual test const char *scursor = argv[1]; const char *const send = argv[1] + qstrlen(argv[1]); Parser parser(scursor, send); PrintingScriptBuilder psb; parser.setScriptBuilder(&psb); if (parser.parse()) { cout << "ok" << endl; } else { cout << "bad" << endl; } } else if (argc == 1) { // automated test bool success = true; for (int i = 0; i < numTestCases; ++i) { const TestCase &t = testCases[i]; cerr << t.name << ":"; VerifyingScriptBuilder v(t); Parser p(t.script, t.script + qstrlen(t.script)); p.setScriptBuilder(&v); const bool ok = p.parse(); if (v.ok()) { if (ok) { cerr << " ok"; } else { cerr << " xfail"; } } else { success = false; } cerr << endl; } if (!success) { exit(1); } } else { // usage error cerr << "usage: parsertest [ ]" << endl; exit(1); } return 0; } diff --git a/src/ksieveui/sieveimapinstance/sieveimapinstance.cpp b/src/ksieveui/sieveimapinstance/sieveimapinstance.cpp index 748d397..0253283 100644 --- a/src/ksieveui/sieveimapinstance/sieveimapinstance.cpp +++ b/src/ksieveui/sieveimapinstance/sieveimapinstance.cpp @@ -1,84 +1,84 @@ /* Copyright (C) 2017-2019 Laurent Montel 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 "sieveimapinstance.h" using namespace KSieveUi; SieveImapInstance::SieveImapInstance() : mStatus(Idle) { } QString SieveImapInstance::name() const { return mName; } void SieveImapInstance::setName(const QString &name) { mName = name; } QString SieveImapInstance::identifier() const { return mIdentifier; } void SieveImapInstance::setIdentifier(const QString &identifier) { mIdentifier = identifier; } KSieveUi::SieveImapInstance::Status SieveImapInstance::status() const { return mStatus; } -void SieveImapInstance::setStatus(const Status &status) +void SieveImapInstance::setStatus(Status status) { mStatus = status; } QStringList SieveImapInstance::mimeTypes() const { return mMimeTypes; } void SieveImapInstance::setMimeTypes(const QStringList &mimeTypes) { mMimeTypes = mimeTypes; } QStringList SieveImapInstance::capabilities() const { return mCapabilities; } void SieveImapInstance::setCapabilities(const QStringList &capabilities) { mCapabilities = capabilities; } bool SieveImapInstance::operator==(const SieveImapInstance &other) const { return (name() == other.name()) && (identifier() == other.identifier()) && (status() == other.status()) && (mimeTypes() == other.mimeTypes()) && (capabilities() == other.capabilities()); } diff --git a/src/ksieveui/sieveimapinstance/sieveimapinstance.h b/src/ksieveui/sieveimapinstance/sieveimapinstance.h index cf93321..a317d78 100644 --- a/src/ksieveui/sieveimapinstance/sieveimapinstance.h +++ b/src/ksieveui/sieveimapinstance/sieveimapinstance.h @@ -1,67 +1,67 @@ /* Copyright (C) 2017-2019 Laurent Montel 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 SIEVEIMAPINSTANCE_H #define SIEVEIMAPINSTANCE_H #include "ksieveui_export.h" #include namespace KSieveUi { class KSIEVEUI_EXPORT SieveImapInstance { public: SieveImapInstance(); ~SieveImapInstance() = default; //Same enum enum Status { Idle = 0, ///< The agent instance does currently nothing. Running, ///< The agent instance is working on something. Broken, ///< The agent instance encountered an error state. NotConfigured ///< The agent is lacking required configuration }; QString name() const; void setName(const QString &name); QString identifier() const; void setIdentifier(const QString &identifier); Status status() const; - void setStatus(const Status &status); + void setStatus(Status status); QStringList mimeTypes() const; void setMimeTypes(const QStringList &mimeTypes); QStringList capabilities() const; void setCapabilities(const QStringList &capabilities); bool operator==(const SieveImapInstance &other) const; private: QStringList mMimeTypes; QStringList mCapabilities; QString mName; QString mIdentifier; Status mStatus; }; } Q_DECLARE_TYPEINFO(KSieveUi::SieveImapInstance, Q_MOVABLE_TYPE); #endif // SIEVEIMAPINSTANCE_H diff --git a/src/ksieveui/util/abstractakonadiimapsettinginterface.h b/src/ksieveui/util/abstractakonadiimapsettinginterface.h index 98b8e21..c69bb7a 100644 --- a/src/ksieveui/util/abstractakonadiimapsettinginterface.h +++ b/src/ksieveui/util/abstractakonadiimapsettinginterface.h @@ -1,47 +1,49 @@ /* Copyright (C) 2017-2019 Laurent Montel 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 ABSTRACTAKONADIIMAPSETTINGINTERFACE_H #define ABSTRACTAKONADIIMAPSETTINGINTERFACE_H #include "ksieveui_private_export.h" #include namespace KSieveUi { class KSIEVEUI_TESTS_EXPORT AbstractAkonadiImapSettingInterface { public: AbstractAkonadiImapSettingInterface(); virtual ~AbstractAkonadiImapSettingInterface(); Q_REQUIRED_RESULT virtual bool sieveSupport() const; Q_REQUIRED_RESULT virtual bool sieveReuseConfig() const; Q_REQUIRED_RESULT virtual QString imapServer() const; Q_REQUIRED_RESULT virtual QString userName() const; Q_REQUIRED_RESULT virtual int sievePort() const; Q_REQUIRED_RESULT virtual QString sieveCustomUsername() const; Q_REQUIRED_RESULT virtual QString sieveCustomAuthentification() const; Q_REQUIRED_RESULT virtual QString sieveVacationFilename() const; Q_REQUIRED_RESULT virtual QString safety() const; Q_REQUIRED_RESULT virtual int alternateAuthentication() const; Q_REQUIRED_RESULT virtual int authentication() const; Q_REQUIRED_RESULT virtual QString sieveAlternateUrl() const; Q_REQUIRED_RESULT virtual int imapPort() const; +private: + Q_DISABLE_COPY(AbstractAkonadiImapSettingInterface) }; } #endif // ABSTRACTAKONADIIMAPSETTINGINTERFACE_H diff --git a/src/ksieveui/util/sieveimapaccountsettings.cpp b/src/ksieveui/util/sieveimapaccountsettings.cpp index 204adec..1987887 100644 --- a/src/ksieveui/util/sieveimapaccountsettings.cpp +++ b/src/ksieveui/util/sieveimapaccountsettings.cpp @@ -1,117 +1,117 @@ /* Copyright (C) 2016-2019 Laurent Montel 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 "sieveimapaccountsettings.h" using namespace KSieveUi; SieveImapAccountSettings::SieveImapAccountSettings() { } QString SieveImapAccountSettings::identifier() const { return mUserName + QLatin1Char('_') + mServerName; } void SieveImapAccountSettings::setServerName(const QString &server) { mServerName = server; } QString SieveImapAccountSettings::serverName() const { return mServerName; } void SieveImapAccountSettings::setPort(int port) { mPort = port; } int SieveImapAccountSettings::port() const { return mPort; } void SieveImapAccountSettings::setUserName(const QString &userName) { mUserName = userName; } QString SieveImapAccountSettings::userName() const { return mUserName; } void SieveImapAccountSettings::setPassword(const QString &password) { mPassword = password; } QString SieveImapAccountSettings::password() const { return mPassword; } void SieveImapAccountSettings::setAuthenticationType(AuthenticationMode type) { mAuthenticationType = type; } KSieveUi::SieveImapAccountSettings::AuthenticationMode SieveImapAccountSettings::authenticationType() const { return mAuthenticationType; } bool SieveImapAccountSettings::operator==(const SieveImapAccountSettings &other) const { return (mServerName == other.serverName()) && (mPassword == other.password()) && (mPort == other.port()) && (mUserName == other.userName()) && (mAuthenticationType == other.authenticationType()) && (mEncryptionMode == other.encryptionMode()); } bool SieveImapAccountSettings::isValid() const { return !mServerName.isEmpty() && !mPassword.isEmpty() && (mPort != -1) && (!mUserName.isEmpty()); } SieveImapAccountSettings::EncryptionMode SieveImapAccountSettings::encryptionMode() const { return mEncryptionMode; } -void SieveImapAccountSettings::setEncryptionMode(const SieveImapAccountSettings::EncryptionMode &encryptionMode) +void SieveImapAccountSettings::setEncryptionMode(SieveImapAccountSettings::EncryptionMode encryptionMode) { mEncryptionMode = encryptionMode; } QDebug operator <<(QDebug d, const SieveImapAccountSettings &settings) { d << "serverName " << settings.serverName(); d << "userName " << settings.userName(); d << "password " << settings.password(); d << "authenticationType " << settings.authenticationType(); d << "port " << settings.port(); d << "encryptionMode : " << settings.encryptionMode(); return d; } diff --git a/src/ksieveui/util/sieveimapaccountsettings.h b/src/ksieveui/util/sieveimapaccountsettings.h index 11ee58e..7a7968b 100644 --- a/src/ksieveui/util/sieveimapaccountsettings.h +++ b/src/ksieveui/util/sieveimapaccountsettings.h @@ -1,87 +1,87 @@ /* Copyright (C) 2016-2019 Laurent Montel 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 SIEVEIMAPACCOUNTSETTINGS_H #define SIEVEIMAPACCOUNTSETTINGS_H #include "ksieveui_export.h" #include namespace KSieveUi { class KSIEVEUI_EXPORT SieveImapAccountSettings { public: //Keep sync with KIMAP settings. enum EncryptionMode { Unencrypted = 0, TlsV1, SslV2, SslV3, SslV3_1, AnySslVersion }; enum AuthenticationMode { Login = 0, Plain, CramMD5, DigestMD5, GSSAPI, NTLM, APOP, ClearText, Anonymous, XOAuth2 }; SieveImapAccountSettings(); Q_REQUIRED_RESULT QString identifier() const; void setServerName(const QString &serverName); Q_REQUIRED_RESULT QString serverName() const; void setPort(int port); Q_REQUIRED_RESULT int port() const; void setUserName(const QString &userName); Q_REQUIRED_RESULT QString userName() const; void setPassword(const QString &password); Q_REQUIRED_RESULT QString password() const; void setAuthenticationType(KSieveUi::SieveImapAccountSettings::AuthenticationMode type); Q_REQUIRED_RESULT AuthenticationMode authenticationType() const; Q_REQUIRED_RESULT bool operator==(const SieveImapAccountSettings &other) const; Q_REQUIRED_RESULT bool isValid() const; Q_REQUIRED_RESULT SieveImapAccountSettings::EncryptionMode encryptionMode() const; - void setEncryptionMode(const SieveImapAccountSettings::EncryptionMode &encryptionMode); + void setEncryptionMode(EncryptionMode encryptionMode); private: QString mServerName; QString mUserName; QString mPassword; SieveImapAccountSettings::AuthenticationMode mAuthenticationType = Plain; SieveImapAccountSettings::EncryptionMode mEncryptionMode = Unencrypted; int mPort = -1; }; } Q_DECLARE_METATYPE(KSieveUi::SieveImapAccountSettings) KSIEVEUI_EXPORT QDebug operator <<(QDebug d, const KSieveUi::SieveImapAccountSettings &settings); #endif // SIEVEIMAPACCOUNTSETTINGS_H diff --git a/src/ksieveui/vacation/vacationeditwidget.cpp b/src/ksieveui/vacation/vacationeditwidget.cpp index 85eaa09..3bf5b27 100644 --- a/src/ksieveui/vacation/vacationeditwidget.cpp +++ b/src/ksieveui/vacation/vacationeditwidget.cpp @@ -1,470 +1,470 @@ /* Copyright (C) 2013-2019 Laurent Montel 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 "vacationeditwidget.h" #include "vacationutils.h" #include "vacationmailactionwidget.h" #include "vacationmaillineedit.h" #include #include #include #include #include #include #include #include "libksieve_debug.h" #include #include #include #include #include using KMime::Types::AddrSpecList; using KMime::Types::AddressList; using KMime::Types::MailboxList; using KMime::HeaderParsing::parseAddressList; using namespace KSieveUi; VacationEditWidget::VacationEditWidget(QWidget *parent) : QWidget(parent) { int row = -1; QGridLayout *glay = new QGridLayout(this); glay->setContentsMargins(0, 0, 0, 0); glay->setColumnStretch(1, 1); // explanation label: ++row; QLabel *configureVacationLabel = new QLabel(i18n("Configure vacation " "notifications to be sent:"), this); configureVacationLabel->setObjectName(QStringLiteral("configureVacationLabel")); glay->addWidget(configureVacationLabel, row, 0, 1, 2); // Activate checkbox: ++row; mActiveCheck = new QCheckBox(i18n("&Activate vacation notifications"), this); mActiveCheck->setObjectName(QStringLiteral("mActiveCheck")); glay->addWidget(mActiveCheck, row, 0, 1, 2); // Message text edit: ++row; glay->setRowStretch(row, 1); mTextEdit = new KPIMTextEdit::PlainTextEditorWidget(this); mTextEdit->setObjectName(QStringLiteral("mTextEdit")); glay->addWidget(mTextEdit, row, 0, 1, 2); // Subject ++row; mSubject = new PimCommon::SpellCheckLineEdit(this, QString()); mSubject->setObjectName(QStringLiteral("mSubject")); //mSubject->setClearButtonEnabled(true); QLabel *subjectOfVacationLabel = new QLabel(i18n("&Subject of the vacation mail:"), this); subjectOfVacationLabel->setObjectName(QStringLiteral("subjectOfVacationLabel")); subjectOfVacationLabel->setBuddy(mSubject); glay->addWidget(subjectOfVacationLabel, row, 0); glay->addWidget(mSubject, row, 1); ++row; QHBoxLayout *timeLayout = new QHBoxLayout; // Start date mStartDate = new KDateComboBox(this); mStartDate->setObjectName(QStringLiteral("mStartDate")); mStartDate->setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords); mStartTime = new KTimeComboBox(this); mStartTime->setObjectName(QStringLiteral("mStartTime")); mStartTime->setOptions(KTimeComboBox::EditTime | KTimeComboBox::SelectTime | KTimeComboBox::EditTime | KTimeComboBox::WarnOnInvalid); mStartTime->setEnabled(false); // Disable by default - we need an extension to support this mStartTimeActive = new QCheckBox(this); mStartTimeActive->setObjectName(QStringLiteral("mStartTimeActive")); connect(mStartTimeActive, &QCheckBox::toggled, mStartTime, &KTimeComboBox::setEnabled); timeLayout->addWidget(mStartDate); timeLayout->addWidget(mStartTimeActive); timeLayout->addWidget(mStartTime); mStartDateLabel = new QLabel(i18n("Start date:"), this); mStartDateLabel->setObjectName(QStringLiteral("mStartDateLabel")); mStartDateLabel->setBuddy(mStartDate); glay->addWidget(mStartDateLabel, row, 0); glay->addLayout(timeLayout, row, 1); ++row; // End date timeLayout = new QHBoxLayout; mEndDate = new KDateComboBox(this); mEndDate->setObjectName(QStringLiteral("mEndDate")); mEndDate->setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords); mEndTime = new KTimeComboBox(this); mEndTime->setObjectName(QStringLiteral("mEndTime")); mEndTime->setOptions(KTimeComboBox::EditTime | KTimeComboBox::SelectTime | KTimeComboBox::EditTime | KTimeComboBox::WarnOnInvalid); mEndTime->setEnabled(false); // Disable by default - we need an extension to support this mEndTimeActive = new QCheckBox(this); mEndTimeActive->setObjectName(QStringLiteral("mEndTimeActive")); connect(mEndTimeActive, &QCheckBox::toggled, mEndTime, &KTimeComboBox::setEnabled); mEndDateLabel = new QLabel(i18n("End date:"), this); mEndDateLabel->setObjectName(QStringLiteral("mEndDateLabel")); mEndDateLabel->setBuddy(mEndDate); glay->addWidget(mEndDateLabel, row, 0); timeLayout->addWidget(mEndDate); timeLayout->addWidget(mEndTimeActive); timeLayout->addWidget(mEndTime); glay->addLayout(timeLayout, row, 1); // Hide the date edits by default - they must be enabled by caller when the // server supports this feature enableDates(false); // "Resent only after" spinbox and label: ++row; int defDayInterval = 7; //default day interval mIntervalSpin = new QSpinBox(this); mIntervalSpin->setMaximum(356); mIntervalSpin->setMinimum(1); mIntervalSpin->setSingleStep(1); mIntervalSpin->setValue(defDayInterval); mIntervalSpin->setObjectName(QStringLiteral("mIntervalSpin")); mIntervalSpin->setSuffix(i18np(" day", " days", defDayInterval)); connect(mIntervalSpin, QOverload::of(&QSpinBox::valueChanged), this, &VacationEditWidget::slotIntervalSpinChanged); QLabel *resendNotificationLabel = new QLabel(i18n("&Resend notification only after:"), this); resendNotificationLabel->setObjectName(QStringLiteral("resendNotificationLabel")); resendNotificationLabel->setBuddy(mIntervalSpin); glay->addWidget(resendNotificationLabel, row, 0); glay->addWidget(mIntervalSpin, row, 1); // "Send responses for these addresses" lineedit and label: ++row; mMailAliasesEdit = new KSieveUi::VacationMailLineEdit(this); mMailAliasesEdit->setObjectName(QStringLiteral("mMailAliasesEdit")); mMailAliasesEdit->setClearButtonEnabled(true); QLabel *sendResponseLabel = new QLabel(i18n("&Send responses for these addresses:"), this); sendResponseLabel->setObjectName(QStringLiteral("sendResponseLabel")); sendResponseLabel->setBuddy(mMailAliasesEdit); glay->addWidget(sendResponseLabel, row, 0); glay->addWidget(mMailAliasesEdit, row, 1); // Action for incoming mails mMailAction = new QComboBox(this); for (int i = 0; i < 4; ++i) { mMailAction->addItem(VacationUtils::mailAction(static_cast(i))); } mMailAction->setObjectName(QStringLiteral("mMailAction")); connect(mMailAction, QOverload::of(&QComboBox::currentIndexChanged), this, &VacationEditWidget::mailActionChanged); //Add imap select folder plugin here. mMailActionRecipient = new VacationMailActionWidget(this); mMailActionRecipient->setObjectName(QStringLiteral("mMailActionRecipient")); QHBoxLayout *hLayout = new QHBoxLayout; hLayout->addWidget(mMailAction); hLayout->addWidget(mMailActionRecipient); ++row; QLabel *actionIncomingMailsLabel = new QLabel(i18n("&Action for incoming mails:"), this); actionIncomingMailsLabel->setBuddy(mMailAction); actionIncomingMailsLabel->setObjectName(QStringLiteral("actionIncomingMailsLabel")); glay->addWidget(actionIncomingMailsLabel, row, 0); glay->addLayout(hLayout, row, 1); // "Send responses also to SPAM mail" checkbox: ++row; mSpamCheck = new QCheckBox(i18n("Do not send vacation replies to spam messages"), this); mSpamCheck->setObjectName(QStringLiteral("mSpamCheck")); mSpamCheck->setChecked(true); glay->addWidget(mSpamCheck, row, 0, 1, 2); // domain checkbox and linedit: ++row; mDomainCheck = new QCheckBox(i18n("Only react to mail coming from domain"), this); mDomainCheck->setObjectName(QStringLiteral("mDomainCheck")); mDomainCheck->setChecked(false); mDomainEdit = new QLineEdit(this); mDomainEdit->setObjectName(QStringLiteral("mDomainEdit")); mDomainEdit->setClearButtonEnabled(true); mDomainEdit->setEnabled(false); mDomainEdit->setValidator(new QRegularExpressionValidator(QRegularExpression(QStringLiteral("[a-zA-Z0-9+-]+(?:\\.[a-zA-Z0-9+-]+)*")), mDomainEdit)); glay->addWidget(mDomainCheck, row, 0); glay->addWidget(mDomainEdit, row, 1); connect(mDomainCheck, &QCheckBox::toggled, mDomainEdit, &QLineEdit::setEnabled); } VacationEditWidget::~VacationEditWidget() { } bool VacationEditWidget::activateVacation() const { return mActiveCheck->isChecked(); } void VacationEditWidget::setActivateVacation(bool activate) { mActiveCheck->setChecked(activate); } QString VacationEditWidget::messageText() const { return mTextEdit->toPlainText().trimmed(); } void VacationEditWidget::setMessageText(const QString &text) { mTextEdit->setPlainText(text); const int height = (mTextEdit->fontMetrics().lineSpacing() + 1) * 11; mTextEdit->setMinimumHeight(height); } int VacationEditWidget::notificationInterval() const { return mIntervalSpin->value(); } void VacationEditWidget::setNotificationInterval(int days) { mIntervalSpin->setValue(days); } AddrSpecList VacationEditWidget::mailAliases(bool &ok) const { QByteArray text = mMailAliasesEdit->text().toLatin1(); // ### IMAA: !ok AddressList al; const char *s = text.cbegin(); AddrSpecList asl; if (parseAddressList(s, text.cend(), al)) { AddressList::const_iterator end(al.constEnd()); for (AddressList::const_iterator it = al.constBegin(); it != end; ++it) { const MailboxList &mbl = (*it).mailboxList; MailboxList::const_iterator endJt = mbl.constEnd(); for (MailboxList::const_iterator jt = mbl.constBegin(); jt != endJt; ++jt) { asl.push_back((*jt).addrSpec()); } } ok = true; } else { qCWarning(LIBKSIEVE_LOG) << "Impossible to parse email!" << text; ok = false; } mMailAliasesEdit->setInvalidEmail(!ok); return asl; } void VacationEditWidget::setMailAliases(const AddrSpecList &aliases) { QStringList sl; AddrSpecList::const_iterator end(aliases.constEnd()); sl.reserve(aliases.count()); for (AddrSpecList::const_iterator it = aliases.constBegin(); it != end; ++it) { sl.push_back((*it).asString()); } mMailAliasesEdit->setText(sl.join(QStringLiteral(", "))); } void VacationEditWidget::setMailAliases(const QString &aliases) { mMailAliasesEdit->setText(aliases); } void VacationEditWidget::slotIntervalSpinChanged(int value) { mIntervalSpin->setSuffix(i18np(" day", " days", value)); } QString VacationEditWidget::domainName() const { return mDomainCheck->isChecked() ? mDomainEdit->text() : QString(); } void VacationEditWidget::setDomainName(const QString &domain) { if (!domain.isEmpty()) { mDomainEdit->setText(domain); mDomainCheck->setChecked(true); } } bool VacationEditWidget::domainCheck() const { return mDomainCheck->isChecked(); } void VacationEditWidget::setDomainCheck(bool check) { mDomainCheck->setChecked(check); } bool VacationEditWidget::sendForSpam() const { return !mSpamCheck->isChecked(); } void VacationEditWidget::setSendForSpam(bool enable) { mSpamCheck->setChecked(!enable); } QDate VacationEditWidget::endDate() const { if (mEndDate->isEnabled()) { return mEndDate->date(); } else { return QDate(); } } -void VacationEditWidget::setEndDate(const QDate &endDate) +void VacationEditWidget::setEndDate(QDate endDate) { mEndDate->setDate(endDate); } QTime VacationEditWidget::endTime() const { if (mEndTime->isEnabled()) { return mEndTime->time(); } else { return QTime(); } } -void VacationEditWidget::setEndTime(const QTime &endTime) +void VacationEditWidget::setEndTime(QTime endTime) { mEndTimeActive->setChecked(endTime.isValid()); mEndTime->setEnabled(endTime.isValid()); mEndTime->setTime(endTime); } QDate VacationEditWidget::startDate() const { if (mStartDate->isEnabled()) { return mStartDate->date(); } else { return QDate(); } } -void VacationEditWidget::setStartDate(const QDate &startDate) +void VacationEditWidget::setStartDate(QDate startDate) { mStartDate->setDate(startDate); } QTime VacationEditWidget::startTime() const { if (mStartTime->isEnabled()) { return mStartTime->time(); } else { return QTime(); } } -void VacationEditWidget::setStartTime(const QTime &startTime) +void VacationEditWidget::setStartTime(QTime startTime) { mStartTimeActive->setChecked(startTime.isValid()); mStartTime->setEnabled(startTime.isValid()); mStartTime->setTime(startTime); } void VacationEditWidget::setSubject(const QString &subject) { mSubject->setText(subject); } QString VacationEditWidget::subject() const { if (mSubject->isEnabled()) { return mSubject->toPlainText(); } else { return QString(); } } void VacationEditWidget::enableDates(bool enable) { mStartDate->setVisible(enable); mStartDateLabel->setVisible(enable); mEndDate->setVisible(enable); mEndDateLabel->setVisible(enable); mStartTime->setVisible(enable); mStartTimeActive->setVisible(enable); mEndTime->setVisible(enable); mEndTimeActive->setVisible(enable); } void VacationEditWidget::mailActionChanged(int action) { mMailActionRecipient->mailActionChanged(static_cast(action)); } void VacationEditWidget::setMailAction(VacationUtils::MailAction action, const QString &recipient) { mMailAction->setCurrentIndex(action); mMailActionRecipient->setMailAction(action, recipient); } void VacationEditWidget::setSieveImapAccountSettings(const SieveImapAccountSettings &account) { mMailActionRecipient->setSieveImapAccountSettings(account); } VacationUtils::MailAction VacationEditWidget::mailAction() const { return static_cast(mMailAction->currentIndex()); } QString VacationEditWidget::mailActionRecipient(bool &valid) const { return mMailActionRecipient->mailActionRecipient(valid); } void VacationEditWidget::enableDomainAndSendForSpam(bool enable) { mDomainCheck->setEnabled(enable); mDomainEdit->setEnabled(enable && mDomainCheck->isChecked()); mSpamCheck->setEnabled(enable); } void VacationEditWidget::setDefault() { setActivateVacation(true); setMessageText(VacationUtils::defaultMessageText()); setSubject(VacationUtils::defaultSubject()); setNotificationInterval(VacationUtils::defaultNotificationInterval()); setMailAliases(VacationUtils::defaultMailAliases()); setSendForSpam(VacationUtils::defaultSendForSpam()); setDomainName(VacationUtils::defaultDomainName()); setMailAction(VacationUtils::defaultMailAction(), QString()); mStartTimeActive->setChecked(false); mEndTimeActive->setChecked(false); mStartTime->setTime(QTime()); mEndTime->setTime(QTime()); mStartDate->setDate(QDate()); mEndDate->setDate(QDate()); setDomainCheck(false); mDomainEdit->clear(); } diff --git a/src/ksieveui/vacation/vacationeditwidget.h b/src/ksieveui/vacation/vacationeditwidget.h index 9815ce0..089bbaa 100644 --- a/src/ksieveui/vacation/vacationeditwidget.h +++ b/src/ksieveui/vacation/vacationeditwidget.h @@ -1,140 +1,140 @@ /* Copyright (C) 2013-2019 Laurent Montel 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 VACATIONEDITWIDGET_H #define VACATIONEDITWIDGET_H #include #include "vacationutils.h" class KDateComboBox; class KTimeComboBox; class QComboBox; class QDate; class QTime; class QLabel; class QSpinBox; class QLineEdit; class KDateComboBox; class QDate; namespace KPIMTextEdit { class PlainTextEditorWidget; } class QCheckBox; namespace KMime { namespace Types { struct AddrSpec; typedef QVector AddrSpecList; } } namespace PimCommon { class SpellCheckLineEdit; } namespace KSieveUi { class VacationMailActionWidget; class SieveImapAccountSettings; class VacationMailLineEdit; class VacationEditWidget : public QWidget { Q_OBJECT public: explicit VacationEditWidget(QWidget *parent = nullptr); ~VacationEditWidget(); void enableDomainAndSendForSpam(bool enable = true); void enableDates(bool enable = true); bool activateVacation() const; void setActivateVacation(bool activate); bool domainCheck() const; void setDomainCheck(bool check); QString messageText() const; void setMessageText(const QString &text); int notificationInterval() const; void setNotificationInterval(int days); KMime::Types::AddrSpecList mailAliases(bool &ok) const; void setMailAliases(const KMime::Types::AddrSpecList &aliases); void setMailAliases(const QString &aliases); QString domainName() const; void setDomainName(const QString &domain); QString subject() const; void setSubject(const QString &subject); bool sendForSpam() const; void setSendForSpam(bool enable); QDate startDate() const; - void setStartDate(const QDate &startDate); + void setStartDate(QDate startDate); QTime startTime() const; - void setStartTime(const QTime &startTime); + void setStartTime(QTime startTime); QDate endDate() const; - void setEndDate(const QDate &endDate); + void setEndDate(QDate endDate); QTime endTime() const; - void setEndTime(const QTime &endTime); + void setEndTime(QTime endTime); VacationUtils::MailAction mailAction() const; QString mailActionRecipient(bool &valid) const; void setMailAction(VacationUtils::MailAction action, const QString &recipient); void setSieveImapAccountSettings(const KSieveUi::SieveImapAccountSettings &account); void setDefault(); private Q_SLOTS: void slotIntervalSpinChanged(int value); void mailActionChanged(int index); protected: QCheckBox *mActiveCheck = nullptr; QSpinBox *mIntervalSpin = nullptr; VacationMailLineEdit *mMailAliasesEdit = nullptr; KPIMTextEdit::PlainTextEditorWidget *mTextEdit = nullptr; QCheckBox *mSpamCheck = nullptr; QCheckBox *mDomainCheck = nullptr; QLineEdit *mDomainEdit = nullptr; PimCommon::SpellCheckLineEdit *mSubject = nullptr; QComboBox *mMailAction = nullptr; VacationMailActionWidget *mMailActionRecipient = nullptr; KDateComboBox *mStartDate = nullptr; KTimeComboBox *mStartTime = nullptr; QCheckBox *mStartTimeActive = nullptr; QLabel *mStartDateLabel = nullptr; KDateComboBox *mEndDate = nullptr; KTimeComboBox *mEndTime = nullptr; QCheckBox *mEndTimeActive = nullptr; QLabel *mEndDateLabel = nullptr; }; } #endif // VACATIONEDITWIDGET_H