MailJD nbsp;·nbsp; Test Dashboard nbsp;·nbsp; Coverage
LCOV - code coverage report
Current view: top level - service - Rfc2822Builder.h (source / functions) Coverage Total Hit
Test: MailJD Coverage (Unit + E2E) Lines: 100.0 % 3 3
Test Date: 2026-06-21 21:10:19 Functions: 100.0 % 3 3
Legend: Lines:     hit not hit

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : #include <QByteArray>
       4              : #include <QDateTime>
       5              : #include <QString>
       6              : #include <QStringList>
       7              : 
       8              : // T-183: Builds RFC-2822 compliant email messages.
       9              : // Used by ComposeWindow for sending (SMTP), Draft saving (IMAP APPEND),
      10              : // and Sent-folder copies (IMAP APPEND).
      11              : class Rfc2822Builder {
      12              : public:
      13           69 :   Rfc2822Builder() = default;
      14              : 
      15              :   // Header setters
      16              :   void setFrom(const QString &name, const QString &email);
      17              :   void setTo(const QStringList &recipients);
      18              :   void setCc(const QStringList &cc);
      19              :   void setBcc(const QStringList &bcc);
      20              :   void setSubject(const QString &subject);
      21              :   void setDate(const QDateTime &date = QDateTime::currentDateTimeUtc());
      22              :   void setMessageId(const QString &messageId = {});
      23              :   void setInReplyTo(const QString &messageId);
      24              :   void setReferences(const QStringList &messageIds);
      25              : 
      26              :   // T-502: Control whether Bcc header is included in build output
      27           37 :   void setIncludeBcc(bool include) { m_includeBcc = include; }
      28              : 
      29              :   // Body
      30              :   void setBodyText(const QString &plainText);
      31              : 
      32              :   // Attachments
      33              :   struct Attachment {
      34              :     QString filename;
      35              :     QByteArray data;
      36              :     QByteArray mimeType; // e.g. "application/octet-stream"
      37              :   };
      38              :   void addAttachment(const Attachment &attachment);
      39              :   // T-622/FUNC-07: Returns false if file cannot be opened
      40              :   bool addAttachmentFromFile(const QString &filePath);
      41              : 
      42              :   // Build the final RFC-2822 message (CRLF line-endings, proper encoding)
      43              :   QByteArray build() const;
      44              : 
      45              :   // Access generated Message-ID (valid after build())
      46           42 :   QString messageId() const { return m_messageId; }
      47              : 
      48              :   // Utility: RFC 2047 encode a header value if it contains non-ASCII
      49              :   static QByteArray encodeHeader(const QString &value);
      50              : 
      51              :   // Utility: Encode address "Name <email>" with RFC-2047 for the name part
      52              :   static QByteArray encodeAddress(const QString &name, const QString &email);
      53              : 
      54              :   // Utility: Encode a list of addresses for To/Cc/Bcc headers
      55              :   static QByteArray encodeAddressList(const QStringList &addresses);
      56              : 
      57              :   // Utility: Quoted-Printable encode a UTF-8 body
      58              :   static QByteArray encodeQuotedPrintable(const QByteArray &data);
      59              : 
      60              : private:
      61              :   QByteArray generateBoundary() const;
      62              :   static QByteArray generateMessageId();
      63              : 
      64              :   QString m_fromName;
      65              :   QString m_fromEmail;
      66              :   QStringList m_to;
      67              :   QStringList m_cc;
      68              :   QStringList m_bcc;
      69              :   QString m_subject;
      70              :   QDateTime m_date;
      71              :   mutable QString m_messageId;
      72              :   QString m_inReplyTo;
      73              :   QStringList m_references;
      74              :   QString m_bodyText;
      75              :   QList<Attachment> m_attachments;
      76              :   bool m_includeBcc = true; // T-502: default true for backward compat
      77              : };
        

Generated by: LCOV version 2.0-1