2026-05-24 00:02:19 +02:00
|
|
|
#include "emailmanager.h"
|
2026-06-17 22:44:27 +02:00
|
|
|
#include <QDebug>
|
2026-05-24 00:02:19 +02:00
|
|
|
#include <QFile>
|
2026-08-17 15:34:49 +02:00
|
|
|
#include <QStandardPaths>
|
|
|
|
|
#include "db/dao/mailitemdao.h"
|
|
|
|
|
#include "services/mimestorage.h"
|
2026-06-04 18:29:16 +02:00
|
|
|
|
2026-05-17 03:08:16 +02:00
|
|
|
EmailManager::EmailManager(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MailItem EmailManager::getMailItemById(qint64 id) const
|
|
|
|
|
{
|
2026-08-17 15:34:49 +02:00
|
|
|
const auto item = MailItemDao::findById(id);
|
|
|
|
|
return item.value_or(MailItem());
|
2026-05-17 03:08:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString EmailManager::getStorageDirectory() const
|
|
|
|
|
{
|
2026-08-17 15:34:49 +02:00
|
|
|
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/mails");
|
2026-05-24 00:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-24 21:01:05 +02:00
|
|
|
QString EmailManager::getEmailHtmlById(qint64 id) const
|
|
|
|
|
{
|
2026-08-17 15:34:49 +02:00
|
|
|
const auto item = MailItemDao::findById(id);
|
|
|
|
|
if (!item) return QString();
|
|
|
|
|
if (!item->bodyHtml().isEmpty()) return item->bodyHtml();
|
|
|
|
|
if (item->fileId().isEmpty()) return QString();
|
|
|
|
|
MimeStorageService storage;
|
|
|
|
|
ParsedMimeMessage parsed;
|
|
|
|
|
return storage.parseMessage(storage.readEmlFile(item->fileId()), parsed) ? parsed.bodyHtml : QString();
|
2026-05-24 21:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-24 00:02:19 +02:00
|
|
|
QString EmailManager::convertEmlToHtml(const QString& emlFilePath) const
|
|
|
|
|
{
|
2026-08-17 15:34:49 +02:00
|
|
|
QFile file(emlFilePath);
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) return QString();
|
|
|
|
|
MimeStorageService storage;
|
|
|
|
|
ParsedMimeMessage parsed;
|
|
|
|
|
return storage.parseMessage(file.readAll(), parsed) ? parsed.bodyHtml : QString();
|
2026-05-24 21:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EmailManager::sendEmail(const QString& to, const QString& subject, const QString& body)
|
|
|
|
|
{
|
2026-06-17 22:44:27 +02:00
|
|
|
Q_UNUSED(to);
|
|
|
|
|
Q_UNUSED(subject);
|
|
|
|
|
Q_UNUSED(body);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-17 15:34:49 +02:00
|
|
|
#include "emailmanager.moc"
|