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

0001 /*
0002  * SPDX-FileCopyrightText: 2005 Till Adam <adam@kde.org>
0003  * SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0004  */
0005 
0006 #pragma once
0007 
0008 #include "messageviewer_export.h"
0009 #include <Akonadi/Item>
0010 #include <KMime/Content>
0011 #include <KService>
0012 #include <QStringConverter>
0013 class QUrl;
0014 class QWidget;
0015 class QActionGroup;
0016 class QAction;
0017 
0018 namespace KMime
0019 {
0020 class Message;
0021 }
0022 
0023 namespace MessageViewer
0024 {
0025 /**
0026  * The Util namespace contains a collection of helper functions use in
0027  * various places.
0028  */
0029 namespace Util
0030 {
0031 // return true if we should proceed, false if we should abort
0032 [[nodiscard]] MESSAGEVIEWER_EXPORT bool containsExternalReferences(const QString &str, const QString &extraHead);
0033 [[nodiscard]] bool MESSAGEVIEWER_EXPORT checkOverwrite(const QUrl &url, QWidget *w);
0034 [[nodiscard]] MESSAGEVIEWER_EXPORT bool
0035 saveMessageInMboxAndGetUrl(QUrl &url, const Akonadi::Item::List &retrievedMsgs, QWidget *parent, bool appendMessages = false);
0036 [[nodiscard]] MESSAGEVIEWER_EXPORT bool saveMessageInMbox(const Akonadi::Item::List &retrievedMsgs, QWidget *parent, bool appendMessages = false);
0037 [[nodiscard]] MESSAGEVIEWER_EXPORT bool excludeExtraHeader(const QString &s);
0038 [[nodiscard]] MESSAGEVIEWER_EXPORT QString generateMboxFileName(const Akonadi::Item &msgBase);
0039 [[nodiscard]] MESSAGEVIEWER_EXPORT bool saveAttachments(const KMime::Content::List &contents, QWidget *parent, QList<QUrl> &saveUrl);
0040 /**
0041  * @brief Replaces the @c node message part by an empty attachment with information about deleted attachment.
0042  *
0043  * @param node A message part representing an attachment. The part will be replaced by a new empty party with
0044  *             filename "Deleted: <original attachment name>". Must not be @p null.
0045  * @return Returns whether the message was actually modified.
0046  */
0047 [[nodiscard]] MESSAGEVIEWER_EXPORT bool deleteAttachment(KMime::Content *node);
0048 /**
0049  * @brief Calls deleteAttachment() for each node in the @p contents list.
0050  *
0051  * @param contents List of attachments to replace by an empty part (see deleteAttachment())
0052  * @return Returns number of attachments that have actually been replaced.
0053  * @see deleteAttachment()
0054  */
0055 [[nodiscard]] MESSAGEVIEWER_EXPORT int deleteAttachments(const KMime::Content::List &contents);
0056 
0057 [[nodiscard]] MESSAGEVIEWER_EXPORT QAction *createAppAction(const KService::Ptr &service, bool singleOffer, QActionGroup *actionGroup, QObject *parent);
0058 /** Return a QTextCodec for the specified charset.
0059  * This function is a bit more tolerant, than QTextCodec::codecForName */
0060 MESSAGEVIEWER_EXPORT QStringConverter::Encoding htmlEncoding(const QByteArray &data, const QByteArray &codec);
0061 struct HtmlMessageInfo {
0062     QString htmlSource;
0063     QString extraHead;
0064     QString bodyStyle;
0065     [[nodiscard]] bool operator==(const HtmlMessageInfo &other) const
0066     {
0067         return other.htmlSource == htmlSource && other.extraHead == extraHead && other.bodyStyle == bodyStyle;
0068     }
0069 };
0070 
0071 [[nodiscard]] MESSAGEVIEWER_EXPORT HtmlMessageInfo processHtml(const QString &htmlSource);
0072 [[nodiscard]] MESSAGEVIEWER_EXPORT QByteArray htmlCodec(const QByteArray &data, const QByteArray &currentCodec);
0073 [[nodiscard]] MESSAGEVIEWER_EXPORT QString generateFileNameForExtension(const Akonadi::Item &msgBase, const QString &extension);
0074 [[nodiscard]] MESSAGEVIEWER_EXPORT QString parseBodyStyle(const QString &style);
0075 }
0076 }
0077 Q_DECLARE_TYPEINFO(MessageViewer::Util::HtmlMessageInfo, Q_RELOCATABLE_TYPE);
0078 Q_DECLARE_METATYPE(MessageViewer::Util::HtmlMessageInfo)
0079 MESSAGEVIEWER_EXPORT QDebug operator<<(QDebug d, const MessageViewer::Util::HtmlMessageInfo &t);
0080 Q_DECLARE_METATYPE(KService::Ptr)