File indexing completed on 2025-03-09 04:54:35

0001 /*
0002    SPDX-FileCopyrightText: 2015 Sandro Knauß <sknauss@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "messageviewer_export.h"
0010 
0011 #include <QSharedPointer>
0012 #include <QString>
0013 
0014 namespace KMime
0015 {
0016 class Content;
0017 }
0018 
0019 namespace MessageViewer
0020 {
0021 class HtmlWriter;
0022 /**
0023  * @brief The HTMLBlock class
0024  */
0025 class MESSAGEVIEWER_EXPORT HTMLBlock
0026 {
0027 public:
0028     using Ptr = QSharedPointer<HTMLBlock>;
0029 
0030     HTMLBlock();
0031 
0032     virtual ~HTMLBlock();
0033 
0034     [[nodiscard]] QString enter();
0035     [[nodiscard]] QString exit();
0036 
0037 protected:
0038     [[nodiscard]] QString dir() const;
0039     virtual QString enterString() const = 0;
0040     virtual QString exitString() const = 0;
0041 
0042 private:
0043     bool entered = false;
0044 };
0045 
0046 // The attachment mark is a div that is placed around the attachment. It is used for drawing
0047 // a yellow border around the attachment when scrolling to it. When scrolling to it, the border
0048 // color of the div is changed, see KMReaderWin::scrollToAttachment().
0049 /**
0050  * @brief The AttachmentMarkBlock class
0051  */
0052 class MESSAGEVIEWER_EXPORT AttachmentMarkBlock : public HTMLBlock
0053 {
0054 public:
0055     AttachmentMarkBlock(HtmlWriter *writer, KMime::Content *node);
0056     ~AttachmentMarkBlock() override;
0057 
0058 protected:
0059     [[nodiscard]] QString enterString() const override;
0060     [[nodiscard]] QString exitString() const override;
0061 
0062 private:
0063     void internalEnter();
0064     void internalExit();
0065 
0066     KMime::Content *const mNode;
0067     HtmlWriter *const mWriter;
0068 };
0069 
0070 // Make sure the whole content is relative, so that nothing is painted over the header
0071 // if a malicious message uses absolute positioning.
0072 // Also force word wrapping, which is useful for printing, see https://issues.kolab.org/issue3992.
0073 class RootBlock : public HTMLBlock
0074 {
0075 public:
0076     explicit RootBlock(HtmlWriter *writer);
0077     ~RootBlock() override;
0078 
0079 protected:
0080     QString enterString() const override;
0081     QString exitString() const override;
0082 
0083 private:
0084     void internalEnter();
0085     void internalExit();
0086 
0087     HtmlWriter *mWriter = nullptr;
0088 };
0089 }