diff --git a/src/core/messagepart.h b/src/core/messagepart.h index e18186b..b5dde51 100644 --- a/src/core/messagepart.h +++ b/src/core/messagepart.h @@ -1,371 +1,376 @@ // SPDX-FileCopyrightText: 2015 Sandro Knauß // SPDX-License-Identifier: LGPL-2.0-or-later #pragma once #include "mimetreeparser_core_export.h" #include "partmetadata.h" #include #include #include #include #include #include #include namespace KMime { class Content; } namespace QGpgME { class Protocol; } namespace MimeTreeParser { /** Flags for the encryption state. */ typedef enum { KMMsgEncryptionStateUnknown, KMMsgNotEncrypted, KMMsgPartiallyEncrypted, KMMsgFullyEncrypted, KMMsgEncryptionProblematic } KMMsgEncryptionState; /** Flags for the signature state. */ typedef enum { KMMsgSignatureStateUnknown, KMMsgNotSigned, KMMsgPartiallySigned, KMMsgFullySigned, KMMsgSignatureProblematic } KMMsgSignatureState; class ObjectTreeParser; class MultiPartAlternativeBodyPartFormatter; class SignedMessagePart; class EncryptedMessagePart; class MIMETREEPARSER_CORE_EXPORT MessagePart : public QObject { Q_OBJECT Q_PROPERTY(bool attachment READ isAttachment CONSTANT) Q_PROPERTY(bool root READ isRoot CONSTANT) Q_PROPERTY(bool isHtml READ isHtml CONSTANT) Q_PROPERTY(QString plaintextContent READ plaintextContent CONSTANT) Q_PROPERTY(QString htmlContent READ htmlContent CONSTANT) public: enum Disposition { Inline, Attachment, Invalid }; using Ptr = QSharedPointer; using List = QList; MessagePart(ObjectTreeParser *otp, const QString &text, KMime::Content *node = nullptr); virtual ~MessagePart(); virtual QString text() const; void setText(const QString &text); virtual bool isAttachment() const; void setIsRoot(bool root); bool isRoot() const; void setParentPart(MessagePart *parentPart); MessagePart *parentPart() const; virtual QString plaintextContent() const; virtual QString htmlContent() const; virtual bool isHtml() const; - QByteArray mimeType() const; - QByteArray charset() const; - QString filename() const; - Disposition disposition() const; - bool isText() const; - - enum Error { NoError = 0, PassphraseError, NoKeyError, UnknownError }; + [[nodiscard]] QByteArray mimeType() const; + [[nodiscard]] QByteArray charset() const; + [[nodiscard]] QString filename() const; + [[nodiscard]] Disposition disposition() const; + [[nodiscard]] bool isText() const; + + enum Error { + NoError = 0, + PassphraseError, + NoKeyError, + UnknownError, + }; - Error error() const; - QString errorString() const; + [[nodiscard]] Error error() const; + [[nodiscard]] QString errorString() const; PartMetaData *partMetaData(); void appendSubPart(const MessagePart::Ptr &messagePart); const QList &subParts() const; - bool hasSubParts() const; + [[nodiscard]] bool hasSubParts() const; KMime::Content *node() const; virtual KMMsgSignatureState signatureState() const; virtual KMMsgEncryptionState encryptionState() const; - QList signatures() const; - QList encryptions() const; + [[nodiscard]] QList signatures() const; + [[nodiscard]] QList encryptions() const; /** * Retrieve the header @header in this part or any parent parent. * * Useful for MemoryHole support. */ KMime::Headers::Base *header(const char *header) const; void bindLifetime(KMime::Content *); protected: void parseInternal(KMime::Content *node, bool onlyOneMimePart = false); void parseInternal(const QByteArray &data); - QString renderInternalText() const; + [[nodiscard]] QString renderInternalText() const; QString mText; ObjectTreeParser *mOtp; PartMetaData mMetaData; MessagePart *mParentPart; KMime::Content *mNode; QList mNodesToDelete; Error mError; private: QList mBlocks; bool mRoot; }; class MIMETREEPARSER_CORE_EXPORT MimeMessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; MimeMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool onlyOneMimePart = false); virtual ~MimeMessagePart(); QString text() const Q_DECL_OVERRIDE; QString plaintextContent() const Q_DECL_OVERRIDE; QString htmlContent() const Q_DECL_OVERRIDE; private: friend class AlternativeMessagePart; }; class MIMETREEPARSER_CORE_EXPORT MessagePartList : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; MessagePartList(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node); virtual ~MessagePartList() = default; QString text() const Q_DECL_OVERRIDE; QString plaintextContent() const Q_DECL_OVERRIDE; QString htmlContent() const Q_DECL_OVERRIDE; }; class MIMETREEPARSER_CORE_EXPORT TextMessagePart : public MessagePartList { Q_OBJECT public: typedef QSharedPointer Ptr; TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node); virtual ~TextMessagePart() = default; KMMsgSignatureState signatureState() const Q_DECL_OVERRIDE; KMMsgEncryptionState encryptionState() const Q_DECL_OVERRIDE; private: void parseContent(); KMMsgSignatureState mSignatureState; KMMsgEncryptionState mEncryptionState; friend class ObjectTreeParser; }; class MIMETREEPARSER_CORE_EXPORT AttachmentMessagePart : public TextMessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; AttachmentMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node); virtual ~AttachmentMessagePart() = default; virtual bool isAttachment() const Q_DECL_OVERRIDE { return true; } }; class MIMETREEPARSER_CORE_EXPORT HtmlMessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; HtmlMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node); virtual ~HtmlMessagePart() = default; bool isHtml() const Q_DECL_OVERRIDE { return true; }; }; class MIMETREEPARSER_CORE_EXPORT AlternativeMessagePart : public MessagePart { Q_OBJECT public: enum HtmlMode { Normal, ///< A normal plaintext message, non-multipart Html, ///< A HTML message, non-multipart MultipartPlain, ///< A multipart/alternative message, the plain text part is currently displayed MultipartHtml, ///< A multipart/altervative message, the HTML part is currently displayed MultipartIcal ///< A multipart/altervative message, the ICal part is currently displayed }; typedef QSharedPointer Ptr; AlternativeMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node); virtual ~AlternativeMessagePart(); QString text() const Q_DECL_OVERRIDE; bool isHtml() const Q_DECL_OVERRIDE; QString plaintextContent() const Q_DECL_OVERRIDE; QString htmlContent() const Q_DECL_OVERRIDE; QString icalContent() const; QList availableModes(); private: QMap mChildParts; friend class ObjectTreeParser; friend class MultiPartAlternativeBodyPartFormatter; }; class MIMETREEPARSER_CORE_EXPORT CertMessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; CertMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, QGpgME::Protocol *cryptoProto); virtual ~CertMessagePart(); QString text() const Q_DECL_OVERRIDE; private: const QGpgME::Protocol *mCryptoProto; GpgME::ImportResult mInportResult; }; class MIMETREEPARSER_CORE_EXPORT EncapsulatedRfc822MessagePart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; EncapsulatedRfc822MessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, const KMime::Message::Ptr &message); virtual ~EncapsulatedRfc822MessagePart() = default; QString text() const Q_DECL_OVERRIDE; QString from() const; QDateTime date() const; private: const KMime::Message::Ptr mMessage; }; class MIMETREEPARSER_CORE_EXPORT EncryptedMessagePart : public MessagePart { Q_OBJECT Q_PROPERTY(bool decryptMessage READ decryptMessage WRITE setDecryptMessage) Q_PROPERTY(bool isEncrypted READ isEncrypted) Q_PROPERTY(bool isNoSecKey READ isNoSecKey) Q_PROPERTY(bool passphraseError READ passphraseError) public: typedef QSharedPointer Ptr; EncryptedMessagePart(ObjectTreeParser *otp, const QString &text, const QGpgME::Protocol *protocol, KMime::Content *node, KMime::Content *encryptedNode = nullptr, bool parseAfterDecryption = true); virtual ~EncryptedMessagePart() = default; QString text() const Q_DECL_OVERRIDE; void setDecryptMessage(bool decrypt); [[nodiscard]] bool decryptMessage() const; void setIsEncrypted(bool encrypted); [[nodiscard]] bool isEncrypted() const; [[nodiscard]] bool isDecryptable() const; [[nodiscard]] bool isNoSecKey() const; [[nodiscard]] bool passphraseError() const; void startDecryption(KMime::Content *data); void startDecryption(); QByteArray mDecryptedData; QString plaintextContent() const override; QString htmlContent() const override; const QGpgME::Protocol *cryptoProto() const; std::vector> decryptRecipients() const; private: bool decrypt(KMime::Content &data); bool mParseAfterDecryption{true}; protected: bool mPassphraseError; bool mNoSecKey; bool mDecryptMessage; const QGpgME::Protocol *mCryptoProto; QByteArray mVerifiedText; std::vector> mDecryptRecipients; KMime::Content *mEncryptedNode; }; class MIMETREEPARSER_CORE_EXPORT SignedMessagePart : public MessagePart { Q_OBJECT Q_PROPERTY(bool isSigned READ isSigned CONSTANT) public: typedef QSharedPointer Ptr; SignedMessagePart(ObjectTreeParser *otp, const QGpgME::Protocol *protocol, KMime::Content *node, KMime::Content *signedData, bool parseAfterDecryption = true); virtual ~SignedMessagePart(); void setIsSigned(bool isSigned); bool isSigned() const; void startVerification(); QString plaintextContent() const Q_DECL_OVERRIDE; QString htmlContent() const Q_DECL_OVERRIDE; const QGpgME::Protocol *cryptoProto() const; private: void sigStatusToMetaData(); void setVerificationResult(const GpgME::VerificationResult &result, const QByteArray &signedData); bool mParseAfterDecryption{true}; protected: const QGpgME::Protocol *mCryptoProto; KMime::Content *mSignedData; std::vector mSignatures; friend EncryptedMessagePart; }; class MIMETREEPARSER_CORE_EXPORT HeadersPart : public MessagePart { Q_OBJECT public: typedef QSharedPointer Ptr; HeadersPart(ObjectTreeParser *otp, KMime::Content *node); virtual ~HeadersPart() = default; }; } diff --git a/src/core/objecttreeparser.h b/src/core/objecttreeparser.h index 0525f0b..f6818ff 100644 --- a/src/core/objecttreeparser.h +++ b/src/core/objecttreeparser.h @@ -1,105 +1,105 @@ // SPDX-FileCopyrightText: 2016 Sandro Knauß // SPDX-FileCopyrightText: 2003 Marc Mutz // SPDX-FileCopyrightText: 2002-2003, 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net // SPDX-FileCopyrightText: 2009 Andras Mantia // SPDX-License-Identifier: LGPL-2.0-or-later #pragma once #include "messagepart.h" #include "mimetreeparser_core_export.h" #include #include class QString; namespace KMime { class Content; } namespace MimeTreeParser { /** Entry point to parse mime messages. Content returned by the ObjectTreeParser (including messageparts), is normalized to not contain any CRLF's but only LF's (just like KMime). */ class MIMETREEPARSER_CORE_EXPORT ObjectTreeParser { // Disable copy ObjectTreeParser(const ObjectTreeParser &other); public: explicit ObjectTreeParser() = default; virtual ~ObjectTreeParser() = default; - QString structureAsString() const; + [[nodiscard]] QString structureAsString() const; void print(); /// The text of the message, ie. what would appear in the /// composer's text editor if this was edited or replied to. /// This is usually the content of the first text/plain MIME part. - QString plainTextContent(); + [[nodiscard]] QString plainTextContent(); /// Similar to plainTextContent(), but returns the HTML source of /// the first text/html MIME part. - QString htmlContent(); + [[nodiscard]] QString htmlContent(); /// Returns whether the parsed message contains encrypted parts. - bool hasEncryptedParts() const; + [[nodiscard]] bool hasEncryptedParts() const; /// Returns whether the parsed message contains signed parts. /// /// \warning This doesn't check whether signed parts exists inside /// encrypted parts that have not been decrypted yet. - bool hasSignedParts() const; + [[nodiscard]] bool hasSignedParts() const; /** Parse beginning at a given node and recursively parsing the children of that node and it's next sibling. */ void parseObjectTree(KMime::Content *node); void parseObjectTree(const QByteArray &mimeMessage); MessagePart::Ptr parsedPart() const; KMime::Content *find(const std::function &select); - MessagePart::List collectContentParts(); - MessagePart::List collectContentParts(MessagePart::Ptr start); - MessagePart::List collectAttachmentParts(); + [[nodiscard]] MessagePart::List collectContentParts(); + [[nodiscard]] MessagePart::List collectContentParts(MessagePart::Ptr start); + [[nodiscard]] MessagePart::List collectAttachmentParts(); /** Decrypt parts and verify signatures */ void decryptAndVerify(); /** Embedd content referenced by cid by inlining */ - QString resolveCidLinks(const QString &html); + [[nodiscard]] QString resolveCidLinks(const QString &html); private: /** * Does the actual work for parseObjectTree. Unlike parseObjectTree(), this does not change the * top-level content. */ - MessagePart::Ptr parseObjectTreeInternal(KMime::Content *node, bool mOnlyOneMimePart); - MessagePart::List processType(KMime::Content *node, const QByteArray &mediaType, const QByteArray &subType); + MIMETREEPARSER_CORE_NO_EXPORT MessagePart::Ptr parseObjectTreeInternal(KMime::Content *node, bool mOnlyOneMimePart); + MIMETREEPARSER_CORE_NO_EXPORT MessagePart::List processType(KMime::Content *node, const QByteArray &mediaType, const QByteArray &subType); - MessagePart::List defaultHandling(KMime::Content *node); + MIMETREEPARSER_CORE_NO_EXPORT MessagePart::List defaultHandling(KMime::Content *node); - QByteArray codecNameFor(KMime::Content *node) const; + MIMETREEPARSER_CORE_NO_EXPORT QByteArray codecNameFor(KMime::Content *node) const; KMime::Content *mTopLevelContent{nullptr}; MessagePart::Ptr mParsedPart; KMime::Message::Ptr mMsg; friend class MessagePart; friend class EncryptedMessagePart; friend class SignedMessagePart; friend class EncapsulatedRfc822MessagePart; friend class TextMessagePart; friend class HtmlMessagePart; friend class TextPlainBodyPartFormatter; friend class MultiPartSignedBodyPartFormatter; friend class ApplicationPkcs7MimeBodyPartFormatter; }; } diff --git a/src/core/partmodel.h b/src/core/partmodel.h index 435a49c..cd3af56 100644 --- a/src/core/partmodel.h +++ b/src/core/partmodel.h @@ -1,132 +1,132 @@ // SPDX-FileCopyrightText: 2016 Christian Mollekopf // SPDX-License-Identifier: LGPL-2.0-or-later #pragma once #include #include #include #include #include "mimetreeparser_core_export.h" #include namespace QGpgME { class Protocol; } namespace MimeTreeParser { class ObjectTreeParser; } class PartModelPrivate; class MIMETREEPARSER_CORE_EXPORT PartModel : public QAbstractItemModel { Q_OBJECT Q_PROPERTY(bool showHtml READ showHtml WRITE setShowHtml NOTIFY showHtmlChanged) Q_PROPERTY(bool containsHtml READ containsHtml NOTIFY containsHtmlChanged) Q_PROPERTY(bool trimMail READ trimMail WRITE setTrimMail NOTIFY trimMailChanged) Q_PROPERTY(bool isTrimmed READ isTrimmed NOTIFY trimMailChanged) public: PartModel(std::shared_ptr parser); ~PartModel(); static std::pair trim(const QString &text); public: enum class Types : quint8 { Error, Encapsulated, Ical, Plain, None, Html, }; Q_ENUM(Types); enum Roles { TypeRole = Qt::UserRole + 1, ContentRole, IsEmbeddedRole, IsEncryptedRole, IsSignedRole, IsErrorRole, SecurityLevelRole, EncryptionSecurityLevelRole, SignatureSecurityLevelRole, SignatureDetails, EncryptionDetails, ErrorType, ErrorString, SenderRole, DateRole }; enum SecurityLevel { Unknow, Good, NotSoGood, Bad, }; Q_ENUM(SecurityLevel); QHash roleNames() const Q_DECL_OVERRIDE; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; void setShowHtml(bool html); - bool showHtml() const; - bool containsHtml() const; + [[nodiscard]] bool showHtml() const; + [[nodiscard]] bool containsHtml() const; void setTrimMail(bool trim); bool trimMail() const; bool isTrimmed() const; Q_SIGNALS: void showHtmlChanged(); void trimMailChanged(); void containsHtmlChanged(); private: std::unique_ptr d; }; class MIMETREEPARSER_CORE_EXPORT SignatureInfo { Q_GADGET Q_PROPERTY(QByteArray keyId MEMBER keyId CONSTANT) Q_PROPERTY(bool keyMissing MEMBER keyMissing CONSTANT) Q_PROPERTY(bool keyRevoked MEMBER keyRevoked CONSTANT) Q_PROPERTY(bool keyExpired MEMBER keyExpired CONSTANT) Q_PROPERTY(bool sigExpired MEMBER sigExpired CONSTANT) Q_PROPERTY(bool crlMissing MEMBER crlMissing CONSTANT) Q_PROPERTY(bool crlTooOld MEMBER crlTooOld CONSTANT) Q_PROPERTY(QString signer MEMBER signer CONSTANT) Q_PROPERTY(QStringList signerMailAddresses MEMBER signerMailAddresses CONSTANT) Q_PROPERTY(bool signatureIsGood MEMBER signatureIsGood CONSTANT) Q_PROPERTY(bool isCompliant MEMBER isCompliant CONSTANT) Q_PROPERTY(GpgME::Signature::Validity keyTrust MEMBER keyTrust CONSTANT) public: bool keyRevoked = false; bool keyExpired = false; bool sigExpired = false; bool keyMissing = false; bool crlMissing = false; bool crlTooOld = false; bool isCompliant = false; GpgME::Signature::Validity keyTrust; QByteArray keyId; const QGpgME::Protocol *cryptoProto = nullptr; std::vector> decryptRecipients; QString signer; QStringList signerMailAddresses; bool signatureIsGood = false; }; diff --git a/src/widgets/messagecontainerwidget_p.h b/src/widgets/messagecontainerwidget_p.h index 6694d02..5670e76 100644 --- a/src/widgets/messagecontainerwidget_p.h +++ b/src/widgets/messagecontainerwidget_p.h @@ -1,52 +1,52 @@ // SPDX-FileCopyrightText: 2023 g10 Code GmbH // SPDX-FileContributor: Carl Schwan // SPDX-License-Identifier: LGPL-2.0-or-later #pragma once #include "mimetreeparser_widgets_export.h" #include #include class SignatureInfo; class QPaintEvent; class UrlHandler; /// \internal class MIMETREEPARSER_WIDGETS_EXPORT MessageWidgetContainer : public QFrame { Q_OBJECT public: explicit MessageWidgetContainer(bool isSigned, const SignatureInfo &signatureInfo, PartModel::SecurityLevel signatureSecurityLevel, bool displaySignatureInfo, bool isEncrypted, const SignatureInfo &encryptionInfo, PartModel::SecurityLevel encryptionSecurityLevel, bool displayEncryptionInfo, UrlHandler *urlHandler, QWidget *parent = nullptr); ~MessageWidgetContainer() override; protected: void paintEvent(QPaintEvent *event) override; bool event(QEvent *event) override; private: - void createLayout(); + MIMETREEPARSER_WIDGETS_NO_EXPORT void createLayout(); bool m_isSigned; SignatureInfo const m_signatureInfo; PartModel::SecurityLevel m_signatureSecurityLevel; bool m_displaySignatureInfo; bool m_isEncrypted; SignatureInfo const m_encryptionInfo; PartModel::SecurityLevel m_encryptionSecurityLevel; bool m_displayEncryptionInfo; UrlHandler *const m_urlHandler; }; diff --git a/src/widgets/messageviewer.h b/src/widgets/messageviewer.h index 8258c7e..b3b60ec 100644 --- a/src/widgets/messageviewer.h +++ b/src/widgets/messageviewer.h @@ -1,44 +1,44 @@ // SPDX-FileCopyrightText: 2023 Carl Schwan // SPDX-License-Identifier: LGPL-2.0-or-later #pragma once #include "mimetreeparser_widgets_export.h" #include #include #include #include class QPainter; namespace MimeTreeParser { namespace Widgets { /// MessageViewer that displays the given KMime::Message::Ptr /// \author Carl Schwan class MIMETREEPARSER_WIDGETS_EXPORT MessageViewer : public QSplitter { public: explicit MessageViewer(QWidget *parent = nullptr); ~MessageViewer() override; - KMime::Message::Ptr message() const; + [[nodiscard]] KMime::Message::Ptr message() const; void setMessage(const KMime::Message::Ptr message); /// Return the message subject - QString subject() const; + [[nodiscard]] QString subject() const; void print(QPainter *painter, int width); private: class Private; std::unique_ptr d; }; } // end namespace Widgets } // end namespace MimeTreeParser diff --git a/src/widgets/messageviewerdialog.h b/src/widgets/messageviewerdialog.h index 809b0b2..36c90a7 100644 --- a/src/widgets/messageviewerdialog.h +++ b/src/widgets/messageviewerdialog.h @@ -1,46 +1,46 @@ // SPDX-FileCopyrightText: 2023 g10 Code GmbH // SPDX-FileContributor: Carl Schwan // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "mimetreeparser_widgets_export.h" #include #include #include class QToolBar; namespace MimeTreeParser { namespace Widgets { /// MessageViewerDialog that displays the given email stored in the /// file. /// /// \author Carl Schwan class MIMETREEPARSER_WIDGETS_EXPORT MessageViewerDialog : public QDialog { Q_OBJECT public: MessageViewerDialog(const QList &messages, QWidget *parent = nullptr); MessageViewerDialog(const QString &fileName, QWidget *parent = nullptr); ~MessageViewerDialog() override; QToolBar *toolBar() const; - QList messages() const; + [[nodiscard]] QList messages() const; private: - void initGUI(); + MIMETREEPARSER_WIDGETS_NO_EXPORT void initGUI(); class Private; std::unique_ptr const d; }; } // end namespace Widgets } // end namespace MimeTreeParser