2026-06-17 22:44:27 +02:00
|
|
|
#ifndef MIMESTORAGESERVICE_H
|
|
|
|
|
#define MIMESTORAGESERVICE_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
2026-08-17 15:34:49 +02:00
|
|
|
#include <QByteArray>
|
|
|
|
|
#include <QVector>
|
2026-06-17 22:44:27 +02:00
|
|
|
#include "core/mailitem.h"
|
|
|
|
|
|
2026-08-17 15:34:49 +02:00
|
|
|
struct ParsedMimeAttachment
|
|
|
|
|
{
|
|
|
|
|
QString fileName;
|
|
|
|
|
QString mimeType;
|
|
|
|
|
QString contentId;
|
|
|
|
|
QByteArray data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ParsedMimeMessage
|
|
|
|
|
{
|
|
|
|
|
QString messageId;
|
|
|
|
|
QString subject;
|
|
|
|
|
QString from;
|
|
|
|
|
QString to;
|
|
|
|
|
QString cc;
|
|
|
|
|
QString bcc;
|
|
|
|
|
QDateTime date;
|
|
|
|
|
QString bodyHtml;
|
|
|
|
|
QVector<ParsedMimeAttachment> attachments;
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-17 22:44:27 +02:00
|
|
|
class MimeStorageService : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
explicit MimeStorageService(QObject *parent = nullptr);
|
|
|
|
|
~MimeStorageService() override = default;
|
|
|
|
|
|
|
|
|
|
QString saveEmlFile(const QString &accountId, const QString &folderId, const MailItem &mail);
|
2026-08-17 15:34:49 +02:00
|
|
|
QString saveRawEmlFile(const QString &accountId, const QString &folderId,
|
|
|
|
|
const QByteArray &rawMime, const QString &stableId = QString());
|
|
|
|
|
bool storeMessage(const QString &accountId, const QString &folderId,
|
|
|
|
|
MailItem &mail, const QByteArray &rawMime,
|
|
|
|
|
QVector<QString> *storedAttachmentPaths = nullptr);
|
|
|
|
|
bool parseMessage(const QByteArray &rawMime, ParsedMimeMessage &message) const;
|
2026-06-17 22:44:27 +02:00
|
|
|
QString getEmlFilePath(const QString &fileId) const;
|
|
|
|
|
QByteArray readEmlFile(const QString &fileId) const;
|
|
|
|
|
bool deleteEmlFile(const QString &fileId);
|
|
|
|
|
|
|
|
|
|
QStringList listAttachments(const QString &mailItemId) const;
|
2026-08-17 15:34:49 +02:00
|
|
|
QString saveAttachment(const QString &fileId, const QString &fileName,
|
|
|
|
|
const QByteArray &data);
|
2026-06-17 22:44:27 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString storagePath() const;
|
|
|
|
|
QString ensureDirectory(const QString &path) const;
|
2026-08-17 15:34:49 +02:00
|
|
|
QString safeComponent(const QString &value) const;
|
|
|
|
|
QString decodeHeaderValue(const QString &value) const;
|
|
|
|
|
QByteArray decodeTransfer(const QByteArray &data, const QString &encoding) const;
|
|
|
|
|
void parseMimePart(const QByteArray &part, ParsedMimeMessage &message,
|
|
|
|
|
QString *plainText, QString *htmlText) const;
|
2026-06-17 22:44:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // MIMESTORAGESERVICE_H
|