Commit f7c4c111 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Start to implement mailmerge agent

parent af1d2877
Pipeline #52643 skipped
......@@ -3,3 +3,4 @@ add_subdirectory(archivemailagent)
add_subdirectory(mailfilteragent)
add_subdirectory(followupreminderagent)
add_subdirectory(unifiedmailboxagent)
add_subdirectory(mailmergeagent)
# SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
# SPDX-License-Identifier: BSD-3-Clause
add_definitions(-DTRANSLATION_DOMAIN=\"akonadi_mailmerge_agent\")
#! /bin/sh
# SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
# SPDX-License-Identifier: BSD-3-Clause
$EXTRACTRC ui/*.ui >> rc.cpp
$XGETTEXT `find . -name '*.h' -o -name '*.cpp' | grep -v '/tests/' | grep -v '/autotests/' ` -o $podir/akonadi_mailmerge_agent.pot
rm -f rc.cpp
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "mailmergeagent.h"
#include <AgentInstance>
#include <AgentManager>
#include <Akonadi/KMime/SpecialMailCollections>
#include <AkonadiCore/ServerManager>
#include <AkonadiCore/session.h>
#include <AttributeFactory>
#include <CollectionFetchScope>
#include <KMime/Message>
#include <QDBusConnection>
#include <changerecorder.h>
#include <itemfetchscope.h>
#include <KWindowSystem>
#include <QPointer>
//#define DEBUG_MailMergeAgent 1
MailMergeAgent::MailMergeAgent(const QString &id)
: Akonadi::AgentBase(id)
{
#if 0
connect(mManager, &SendLaterManager::needUpdateConfigDialogBox, this, &MailMergeAgent::needUpdateConfigDialogBox);
new MailMergeAgentAdaptor(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/MailMergeAgent"), this, QDBusConnection::ExportAdaptors);
const QString service = Akonadi::ServerManager::self()->agentServiceName(Akonadi::ServerManager::Agent, QStringLiteral("akonadi_sendlater_agent"));
QDBusConnection::sessionBus().registerService(service);
changeRecorder()->setMimeTypeMonitored(KMime::Message::mimeType());
changeRecorder()->itemFetchScope().setCacheOnly(true);
changeRecorder()->itemFetchScope().setFetchModificationTime(false);
changeRecorder()->setChangeRecordingEnabled(false);
changeRecorder()->ignoreSession(Akonadi::Session::defaultSession());
setNeedsNetwork(true);
if (MailMergeAgentSettings::enabled()) {
#ifdef DEBUG_MailMergeAgent
QTimer::singleShot(1000, this, &MailMergeAgent::slotStartAgent);
#else
QTimer::singleShot(1000 * 60 * 4, this, &MailMergeAgent::slotStartAgent);
#endif
}
// For extra safety, check list every hour, in case we didn't properly get
// notified about the network going up or down.
auto reloadListTimer = new QTimer(this);
connect(reloadListTimer, &QTimer::timeout, this, &MailMergeAgent::reload);
reloadListTimer->start(1000 * 60 * 60); // 1 hour
#endif
}
MailMergeAgent::~MailMergeAgent() = default;
void MailMergeAgent::slotStartAgent()
{
mAgentInitialized = true;
if (isOnline()) {
// mManager->load();
}
}
void MailMergeAgent::doSetOnline(bool online)
{
if (mAgentInitialized) {
if (online) {
reload();
} else {
// mManager->stopAll();
}
}
}
void MailMergeAgent::reload()
{
// qCDebug(MailMergeAgent_LOG) << " void MailMergeAgent::reload()";
// if (MailMergeAgentSettings::enabled()) {
// mManager->load(true);
// }
}
void MailMergeAgent::setEnableAgent(bool enabled)
{
// if (MailMergeAgentSettings::enabled() == enabled) {
// return;
// }
// MailMergeAgentSettings::setEnabled(enabled);
// MailMergeAgentSettings::self()->save();
// if (enabled) {
// mManager->load();
// } else {
// mManager->stopAll();
// }
}
bool MailMergeAgent::enabledAgent() const
{
// return MailMergeAgentSettings::enabled();
return false;
}
void MailMergeAgent::configure(WId windowId)
{
// QPointer<SendLaterConfigureDialog> dialog = new SendLaterConfigureDialog();
// if (windowId) {
// dialog->setAttribute(Qt::WA_NativeWindow, true);
// KWindowSystem::setMainWindow(dialog->windowHandle(), windowId);
// }
// connect(this, &MailMergeAgent::needUpdateConfigDialogBox, dialog.data(), &SendLaterConfigureDialog::slotNeedToReloadConfig);
// connect(dialog.data(), &SendLaterConfigureDialog::sendNow, this, &MailMergeAgent::slotSendNow);
// if (dialog->exec()) {
// mManager->load();
// const QVector<Akonadi::Item::Id> listMessage = dialog->messagesToRemove();
// if (!listMessage.isEmpty()) {
// // Will delete in specific job when done.
// auto sendlaterremovejob = new SendLaterRemoveMessageJob(listMessage, this);
// sendlaterremovejob->start();
// }
// }
// delete dialog;
}
void MailMergeAgent::removeItem(qint64 item)
{
// if (mManager->itemRemoved(item)) {
// reload();
// }
}
void MailMergeAgent::addItem(qint64 timestamp,
bool recurrence,
int recurrenceValue,
int recurrenceUnit,
Akonadi::Item::Id id,
const QString &subject,
const QString &to)
{
// auto info = new MessageComposer::SendLaterInfo;
// info->setDateTime(QDateTime::fromSecsSinceEpoch(timestamp));
// info->setRecurrence(recurrence);
// info->setRecurrenceEachValue(recurrenceValue);
// info->setRecurrenceUnit(static_cast<MessageComposer::SendLaterInfo::RecurrenceUnit>(recurrenceUnit));
// info->setItemId(id);
// info->setSubject(subject);
// info->setTo(to);
// SendLaterUtil::writeSendLaterInfo(SendLaterUtil::defaultConfig(), info);
// reload();
}
void MailMergeAgent::slotSendNow(Akonadi::Item::Id id)
{
// mManager->sendNow(id);
}
void MailMergeAgent::itemsRemoved(const Akonadi::Item::List &items)
{
// bool needToReload = false;
// for (const Akonadi::Item &item : items) {
// if (mManager->itemRemoved(item.id())) {
// needToReload = true;
// }
// }
// if (needToReload) {
// reload();
// }
}
void MailMergeAgent::itemsMoved(const Akonadi::Item::List &items,
const Akonadi::Collection & /*sourceCollection*/,
const Akonadi::Collection &destinationCollection)
{
if (Akonadi::SpecialMailCollections::self()->specialCollectionType(destinationCollection) != Akonadi::SpecialMailCollections::Trash) {
return;
}
itemsRemoved(items);
}
QString MailMergeAgent::printDebugInfo() const
{
// return mManager->printDebugInfo();
}
AKONADI_AGENT_MAIN(MailMergeAgent)
[Desktop Entry]
Name=Mail Merge Agent
Comment=Mail Merge Agent
Type=AkonadiAgent
Exec=akonadi_mailmerge_agent
Icon=kmail
X-Akonadi-MimeTypes=message/rfc822
X-Akonadi-Capabilities=Unique,Autostart
X-Akonadi-Identifier=akonadi_mailmerge_agent
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <agentbase.h>
class SendLaterManager;
class MailMergeAgent : public Akonadi::AgentBase, public Akonadi::AgentBase::ObserverV3
{
Q_OBJECT
public:
explicit MailMergeAgent(const QString &id);
~MailMergeAgent() override;
Q_REQUIRED_RESULT QString printDebugInfo() const;
void setEnableAgent(bool b);
Q_REQUIRED_RESULT bool enabledAgent() const;
Q_SIGNALS:
void needUpdateConfigDialogBox();
public Q_SLOTS:
void reload();
void configure(WId windowId) override;
protected:
void itemsRemoved(const Akonadi::Item::List &item) override;
void itemsMoved(const Akonadi::Item::List &items, const Akonadi::Collection &sourceCollection, const Akonadi::Collection &destinationCollection) override;
void doSetOnline(bool online) override;
private:
void slotSendNow(Akonadi::Item::Id id);
void slotStartAgent();
bool mAgentInitialized = false;
};
Markdown is supported
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