Commit 0a74f296 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move mdnstateattribute here

parent da65f9f8
Pipeline #194826 failed with stage
in 3 minutes and 45 seconds
......@@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(PIM_VERSION "5.20.40")
set(PIM_VERSION "5.20.41")
project(Akonadi-Mime VERSION ${PIM_VERSION})
# ECM setup
......
......@@ -52,3 +52,8 @@ ecm_add_test(addressattributetest.cpp addressattributetest.h
TEST_NAME addressattributetest
)
ecm_add_test(mdnstateattributetest.cpp mdnstateattributetest.h
LINK_LIBRARIES KF5::AkonadiMime KF5::AkonadiCore Qt${QT_MAJOR_VERSION}::Test
TEST_NAME mdnstateattributetest
)
/*
SPDX-FileCopyrightText: 2014-2022 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-only
*/
#include "mdnstateattributetest.h"
#include "mdnstateattribute.h"
#include <QTest>
MDNStateAttributeTest::MDNStateAttributeTest(QObject *parent)
: QObject(parent)
{
}
MDNStateAttributeTest::~MDNStateAttributeTest() = default;
void MDNStateAttributeTest::shouldHaveDefaultValue()
{
Akonadi::MDNStateAttribute attr;
QCOMPARE(attr.mdnState(), Akonadi::MDNStateAttribute::MDNStateUnknown);
}
void MDNStateAttributeTest::shouldHaveType()
{
Akonadi::MDNStateAttribute attr;
QCOMPARE(attr.type(), QByteArray("MDNStateAttribute"));
}
void MDNStateAttributeTest::shouldSerializedAttribute()
{
Akonadi::MDNStateAttribute attr;
attr.setMDNState(Akonadi::MDNStateAttribute::MDNDenied);
QCOMPARE(attr.mdnState(), Akonadi::MDNStateAttribute::MDNDenied);
const QByteArray ba = attr.serialized();
Akonadi::MDNStateAttribute result;
result.deserialize(ba);
QVERIFY(attr == result);
}
void MDNStateAttributeTest::shouldCloneAttribute()
{
Akonadi::MDNStateAttribute attr;
attr.setMDNState(Akonadi::MDNStateAttribute::MDNDenied);
Akonadi::MDNStateAttribute *result = attr.clone();
QVERIFY(attr == *result);
delete result;
}
QTEST_MAIN(MDNStateAttributeTest)
/*
SPDX-FileCopyrightText: 2014-2022 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-only
*/
#pragma once
#include <QObject>
class MDNStateAttributeTest : public QObject
{
Q_OBJECT
public:
explicit MDNStateAttributeTest(QObject *parent = nullptr);
~MDNStateAttributeTest() override;
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldHaveType();
void shouldSerializedAttribute();
void shouldCloneAttribute();
};
......@@ -69,6 +69,9 @@ set(akonadimime_SRCS
specialmailcollections.h
metatype.h
messageparts.h
mdnstateattribute.h
mdnstateattribute.cpp
)
ecm_qt_declare_logging_category(akonadimime_SRCS HEADER akonadi_mime_debug.h IDENTIFIER AKONADIMIME_LOG CATEGORY_NAME log_akonadi_mime)
......@@ -129,6 +132,7 @@ ecm_generate_headers(AkonadiMime_CamelCase_HEADERS
AddressAttribute
CommandBase
MDNStateAttribute
MessageFlags
MessageFolderAttribute
MessageModel
......
/******************************************************************************
*
* SPDX-FileCopyrightText: 2010 Leo Franchi <lfranchi@kde.org>
* SPDX-FileCopyrightText: 2010 KDAB
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*
*****************************************************************************/
#include "mdnstateattribute.h"
#include <Akonadi/AttributeFactory>
#include <QByteArray>
using namespace Akonadi;
/**
* @internal
*/
class Q_DECL_HIDDEN MDNStateAttribute::MDNStateAttributePrivate
{
public:
MDNSentState dataToState(const QByteArray &data)
{
MDNSentState state = MDNStateUnknown;
switch (data.at(0)) {
case 'N':
state = MDNNone;
break;
case 'I':
state = MDNIgnore;
break;
case 'R':
state = MDNDisplayed;
break;
case 'D':
state = MDNDeleted;
break;
case 'F':
state = MDNDispatched;
break;
case 'P':
state = MDNProcessed;
break;
case 'X':
state = MDNDenied;
break;
case 'E':
state = MDNFailed;
break;
case 'U':
default:
state = MDNStateUnknown;
break;
}
return state;
}
QByteArray stateToData(MDNSentState state)
{
QByteArray data = "U"; // Unknown
switch (state) {
case MDNNone:
data = "N";
break;
case MDNIgnore:
data = "I";
break;
case MDNDisplayed:
data = "R";
break;
case MDNDeleted:
data = "D";
break;
case MDNDispatched:
data = "F";
break;
case MDNProcessed:
data = "P";
break;
case MDNDenied:
data = "X";
break;
case MDNFailed:
data = "E";
break;
case MDNStateUnknown:
data = "U";
break;
}
return data;
}
QByteArray mSentState;
};
MDNStateAttribute::MDNStateAttribute(MDNSentState state)
: d(new MDNStateAttributePrivate)
{
d->mSentState = d->stateToData(state);
}
MDNStateAttribute::MDNStateAttribute(const QByteArray &stateData)
: d(new MDNStateAttributePrivate)
{
d->mSentState = stateData;
}
MDNStateAttribute::~MDNStateAttribute() = default;
MDNStateAttribute *MDNStateAttribute::clone() const
{
return new MDNStateAttribute(d->mSentState);
}
QByteArray MDNStateAttribute::type() const
{
static const QByteArray sType("MDNStateAttribute");
return sType;
}
QByteArray MDNStateAttribute::serialized() const
{
return d->mSentState;
}
void MDNStateAttribute::deserialize(const QByteArray &data)
{
d->mSentState = data;
}
void MDNStateAttribute::setMDNState(MDNSentState state)
{
d->mSentState = d->stateToData(state);
}
MDNStateAttribute::MDNSentState MDNStateAttribute::mdnState() const
{
return d->dataToState(d->mSentState);
}
bool MDNStateAttribute::operator==(const MDNStateAttribute &other) const
{
return mdnState() == other.mdnState();
}
// Register the attribute when the library is loaded.
namespace
{
bool dummyMDNStateAttribute()
{
using namespace Akonadi;
Akonadi::AttributeFactory::registerAttribute<MDNStateAttribute>();
return true;
}
const bool registeredMDNStateAttribute = dummyMDNStateAttribute();
}
/******************************************************************************
*
* SPDX-FileCopyrightText: 2010 Leo Franchi <lfranchi@kde.org>
* SPDX-FileCopyrightText: 2010 KDAB
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*
*****************************************************************************/
#pragma once
#include "akonadi-mime_export.h"
#include <Akonadi/Attribute>
#include <memory>
namespace Akonadi
{
/**
* @short An Attribute that keeps track of the MDN state of a mail message.
*
* Once a mail that contains a Message Disposition Notification is processed,
* the outcome of the user action will be stored in this attribute.
*
* @author Leo Franchi <lfranchi@kde.org>
* @see Akonadi::Attribute
* @since 4.6
*/
class AKONADI_MIME_EXPORT MDNStateAttribute : public Akonadi::Attribute
{
public:
/**
* Describes the "MDN sent" state.
*/
enum MDNSentState {
MDNStateUnknown, ///< The state is unknown.
MDNNone, ///< No MDN has been set.
MDNIgnore, ///< Ignore sending a MDN.
MDNDisplayed, ///< The message has been displayed by the UA to someone reading the recipient's mailbox.
MDNDeleted, ///< The message has been deleted.
MDNDispatched, ///< The message has been sent somewhere in some manner without necessarily having been previously displayed to the user.
MDNProcessed, ///< The message has been processed in some manner without being displayed to the user.
MDNDenied, ///< The recipient does not wish the sender to be informed of the message's disposition.
MDNFailed ///< A failure occurred that prevented the proper generation of an MDN.
};
/**
* Creates a new MDN state attribute.
*
* @param state The state the attribute will have.
*/
explicit MDNStateAttribute(MDNSentState state = MDNStateUnknown);
/**
* Creates a new MDN state attribute.
*
* @param state The string representation of the state the attribute will have.
*/
explicit MDNStateAttribute(const QByteArray &state);
/**
* Destroys the MDN state attribute.
*/
~MDNStateAttribute() override;
/**
* Reimplemented from Attribute
*/
QByteArray type() const override;
/**
* Reimplemented from Attribute
*/
MDNStateAttribute *clone() const override;
/**
* Reimplemented from Attribute
*/
QByteArray serialized() const override;
/**
* Reimplemented from Attribute
*/
void deserialize(const QByteArray &data) override;
/**
* Sets the MDN @p state.
*/
void setMDNState(MDNSentState state);
/**
* Returns the MDN state.
*/
MDNStateAttribute::MDNSentState mdnState() const;
bool operator==(const MDNStateAttribute &other) const;
private:
//@cond PRIVATE
class MDNStateAttributePrivate;
std::unique_ptr<MDNStateAttributePrivate> const d;
//@endcond
};
}
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