2026-05-24 00:02:19 +02:00
|
|
|
#include "emailmanager.h"
|
2026-05-17 03:08:16 +02:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
#include "../db/dao/mailitemdao.h"
|
2026-05-24 00:02:19 +02:00
|
|
|
#include <QFile>
|
2026-05-17 03:08:16 +02:00
|
|
|
|
|
|
|
|
EmailManager::EmailManager(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MailItem EmailManager::getMailItemById(qint64 id) const
|
|
|
|
|
{
|
|
|
|
|
// Use the DAO to fetch the MailItem by id
|
2026-05-24 00:02:19 +02:00
|
|
|
auto optItem = MailItemDao::findById(id);
|
2026-05-17 03:08:16 +02:00
|
|
|
if (optItem.has_value()) {
|
|
|
|
|
return optItem.value();
|
|
|
|
|
}
|
|
|
|
|
// Return an empty MailItem if not found
|
|
|
|
|
return MailItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString EmailManager::getStorageDirectory() const
|
|
|
|
|
{
|
|
|
|
|
// Define where .eml files are stored (e.g., in the application data directory)
|
|
|
|
|
QString storagePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
|
|
|
QDir dir(storagePath);
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
|
dir.mkpath("."); // create if it doesn't exist
|
|
|
|
|
}
|
|
|
|
|
// Assuming .eml files are stored directly in this directory
|
|
|
|
|
return storagePath;
|
2026-05-24 00:02:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString EmailManager::convertEmlToHtml(const QString& emlFilePath) const
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement actual MIME to HTML conversion using gmime or similar
|
|
|
|
|
// For now, return a placeholder indicating the feature is not yet implemented
|
|
|
|
|
QFile file(emlFilePath);
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
return "<html><body><h2>Error: Email file not found</h2></body></html>";
|
|
|
|
|
}
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
|
return "<html><body><h2>Error: Cannot open email file</h2></body></html>";
|
|
|
|
|
}
|
|
|
|
|
QByteArray data = file.readAll();
|
|
|
|
|
file.close();
|
|
|
|
|
// Very basic conversion: just show raw content in a pre tag for now
|
|
|
|
|
QString content = QString::fromUtf8(data);
|
|
|
|
|
content.replace("&", "&").replace("<", "<").replace(">", ">");
|
|
|
|
|
return QString("<html><body style='font-family: monospace;'><h2>Email Content (raw)</h2><pre>%1</pre></body></html>")
|
|
|
|
|
.arg(content);
|
2026-05-17 03:08:16 +02:00
|
|
|
}
|