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

0001 /*
0002   SPDX-FileCopyrightText: 2017 Sandro Knauß <sknauss@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "urlhandlermanager.h"
0010 #include <MessageViewer/URLHandler>
0011 #include <QHash>
0012 
0013 namespace KMime
0014 {
0015 class Content;
0016 }
0017 
0018 namespace MessageViewer
0019 {
0020 class MESSAGEVIEWER_TESTS_EXPORT BodyPartURLHandlerManager : public MimeTreeParser::URLHandler
0021 {
0022 public:
0023     BodyPartURLHandlerManager()
0024         : MimeTreeParser::URLHandler()
0025     {
0026     }
0027 
0028     ~BodyPartURLHandlerManager() override;
0029 
0030     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0031     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override;
0032     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override;
0033 
0034     void registerHandler(const Interface::BodyPartURLHandler *handler, const QString &mimeType);
0035     void unregisterHandler(const Interface::BodyPartURLHandler *handler);
0036 
0037 private:
0038     [[nodiscard]] QList<const Interface::BodyPartURLHandler *> handlersForPart(KMime::Content *node) const;
0039 
0040     using BodyPartHandlerList = QHash<QByteArray, QList<const Interface::BodyPartURLHandler *>>;
0041     BodyPartHandlerList mHandlers;
0042 };
0043 
0044 class MESSAGEVIEWER_TESTS_EXPORT KMailProtocolURLHandler : public MimeTreeParser::URLHandler
0045 {
0046 public:
0047     KMailProtocolURLHandler()
0048         : MimeTreeParser::URLHandler()
0049     {
0050     }
0051 
0052     ~KMailProtocolURLHandler() override = default;
0053 
0054     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0055     [[nodiscard]] bool handleContextMenuRequest(const QUrl &url, const QPoint &, ViewerPrivate *) const override
0056     {
0057         return url.scheme() == QLatin1StringView("kmail");
0058     }
0059 
0060     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override;
0061 };
0062 
0063 class MESSAGEVIEWER_TESTS_EXPORT ExpandCollapseQuoteURLManager : public MimeTreeParser::URLHandler
0064 {
0065 public:
0066     ExpandCollapseQuoteURLManager()
0067         : MimeTreeParser::URLHandler()
0068     {
0069     }
0070 
0071     ~ExpandCollapseQuoteURLManager() override = default;
0072 
0073     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0074     [[nodiscard]] bool handleDrag(const QUrl &url, ViewerPrivate *window) const override;
0075     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override
0076     {
0077         return false;
0078     }
0079 
0080     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override;
0081 };
0082 
0083 class MESSAGEVIEWER_TESTS_EXPORT SMimeURLHandler : public MimeTreeParser::URLHandler
0084 {
0085 public:
0086     SMimeURLHandler()
0087         : MimeTreeParser::URLHandler()
0088     {
0089     }
0090 
0091     ~SMimeURLHandler() override = default;
0092 
0093     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0094     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override
0095     {
0096         return false;
0097     }
0098 
0099     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override;
0100 };
0101 
0102 class MESSAGEVIEWER_TESTS_EXPORT MailToURLHandler : public MimeTreeParser::URLHandler
0103 {
0104 public:
0105     MailToURLHandler()
0106         : MimeTreeParser::URLHandler()
0107     {
0108     }
0109 
0110     ~MailToURLHandler() override = default;
0111 
0112     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override
0113     {
0114         return false;
0115     }
0116 
0117     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override
0118     {
0119         return false;
0120     }
0121 
0122     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override;
0123 };
0124 
0125 class MESSAGEVIEWER_TESTS_EXPORT ContactUidURLHandler : public MimeTreeParser::URLHandler
0126 {
0127 public:
0128     ContactUidURLHandler()
0129         : MimeTreeParser::URLHandler()
0130     {
0131     }
0132 
0133     ~ContactUidURLHandler() override = default;
0134 
0135     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0136     [[nodiscard]] bool handleContextMenuRequest(const QUrl &url, const QPoint &p, ViewerPrivate *) const override;
0137     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override;
0138 };
0139 
0140 class MESSAGEVIEWER_TESTS_EXPORT HtmlAnchorHandler : public MimeTreeParser::URLHandler
0141 {
0142 public:
0143     HtmlAnchorHandler()
0144         : MimeTreeParser::URLHandler()
0145     {
0146     }
0147 
0148     ~HtmlAnchorHandler() override = default;
0149 
0150     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0151     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override
0152     {
0153         return false;
0154     }
0155 
0156     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override
0157     {
0158         return {};
0159     }
0160 };
0161 
0162 class MESSAGEVIEWER_TESTS_EXPORT AttachmentURLHandler : public MimeTreeParser::URLHandler
0163 {
0164 public:
0165     AttachmentURLHandler()
0166         : MimeTreeParser::URLHandler()
0167     {
0168     }
0169 
0170     ~AttachmentURLHandler() override = default;
0171 
0172     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0173     [[nodiscard]] bool handleShiftClick(const QUrl &, ViewerPrivate *window) const override;
0174     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override;
0175     [[nodiscard]] bool handleDrag(const QUrl &url, ViewerPrivate *window) const override;
0176     [[nodiscard]] bool willHandleDrag(const QUrl &url, ViewerPrivate *window) const override;
0177     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override;
0178 
0179 private:
0180     KMime::Content *nodeForUrl(const QUrl &url, ViewerPrivate *w) const;
0181     bool attachmentIsInHeader(const QUrl &url) const;
0182 };
0183 
0184 class MESSAGEVIEWER_TESTS_EXPORT ShowAuditLogURLHandler : public MimeTreeParser::URLHandler
0185 {
0186 public:
0187     ShowAuditLogURLHandler()
0188         : MimeTreeParser::URLHandler()
0189     {
0190     }
0191 
0192     ~ShowAuditLogURLHandler() override = default;
0193 
0194     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0195     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override;
0196     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override;
0197     [[nodiscard]] bool handleDrag(const QUrl &url, ViewerPrivate *window) const override;
0198 };
0199 
0200 // Handler that prevents dragging of internal images added by KMail, such as the envelope image
0201 // in the enterprise header
0202 class MESSAGEVIEWER_TESTS_EXPORT InternalImageURLHandler : public MimeTreeParser::URLHandler
0203 {
0204 public:
0205     InternalImageURLHandler()
0206         : MimeTreeParser::URLHandler()
0207     {
0208     }
0209 
0210     ~InternalImageURLHandler() override = default;
0211 
0212     [[nodiscard]] bool handleDrag(const QUrl &url, ViewerPrivate *window) const override;
0213     [[nodiscard]] bool willHandleDrag(const QUrl &url, ViewerPrivate *window) const override;
0214     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override
0215     {
0216         return false;
0217     }
0218 
0219     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override
0220     {
0221         return false;
0222     }
0223 
0224     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override
0225     {
0226         return {};
0227     }
0228 };
0229 
0230 class MESSAGEVIEWER_TESTS_EXPORT EmbeddedImageURLHandler : public MimeTreeParser::URLHandler
0231 {
0232 public:
0233     EmbeddedImageURLHandler()
0234         : MimeTreeParser::URLHandler()
0235     {
0236     }
0237 
0238     ~EmbeddedImageURLHandler() override = default;
0239 
0240     [[nodiscard]] bool handleDrag(const QUrl &url, ViewerPrivate *window) const override;
0241     [[nodiscard]] bool willHandleDrag(const QUrl &url, ViewerPrivate *window) const override;
0242     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override
0243     {
0244         return false;
0245     }
0246 
0247     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override
0248     {
0249         return false;
0250     }
0251 
0252     [[nodiscard]] QString statusBarMessage(const QUrl &url, ViewerPrivate *) const override
0253     {
0254         Q_UNUSED(url)
0255         return {};
0256     }
0257 };
0258 
0259 class MESSAGEVIEWER_TESTS_EXPORT KRunURLHandler : public MimeTreeParser::URLHandler
0260 {
0261 public:
0262     KRunURLHandler()
0263         : MimeTreeParser::URLHandler()
0264     {
0265     }
0266 
0267     ~KRunURLHandler() override = default;
0268 
0269     [[nodiscard]] bool handleClick(const QUrl &, ViewerPrivate *) const override;
0270     [[nodiscard]] bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override
0271     {
0272         return false;
0273     }
0274 
0275     [[nodiscard]] QString statusBarMessage(const QUrl &, ViewerPrivate *) const override
0276     {
0277         return {};
0278     }
0279 };
0280 }