File indexing completed on 2025-03-09 04:54:13
0001 /* 0002 * SPDX-License-Identifier: LGPL-2.1-or-later 0003 * 0004 */ 0005 0006 #pragma once 0007 0008 #include "messagecore_export.h" 0009 0010 #include <KMime/KMimeMessage> 0011 #include <QUrl> 0012 0013 #include <QByteArray> 0014 #include <QSharedDataPointer> 0015 #include <QString> 0016 0017 class KConfigGroup; 0018 0019 namespace MessageCore 0020 { 0021 /** 0022 * @short A class to extract information about mailing lists from emails. 0023 * 0024 * The mailing list header fields are defined as the following: 0025 * - "List-*" in RFC2369 0026 * - "List-ID" in RFC2919. 0027 * - "Archive-At" in RFC5064 0028 * 0029 * @author Zack Rusin <zack@kde.org> 0030 */ 0031 class MESSAGECORE_EXPORT MailingList 0032 { 0033 public: 0034 /** 0035 * Defines what entity should manage the mailing list. 0036 */ 0037 enum Handler { 0038 KMail, ///< The list is handled by KMail 0039 Browser, ///< The list is handled by a browser. 0040 }; 0041 0042 /** 0043 * Defines the features a mailinglist can support. 0044 */ 0045 enum Feature { 0046 None = 0 << 0, ///< No mailing list fields exist. 0047 Post = 1 << 0, ///< List-Post header exists. 0048 Subscribe = 1 << 1, ///< List-Subscribe header exists. 0049 Unsubscribe = 1 << 2, ///< List-Unsubscribe header exists. 0050 Help = 1 << 3, ///< List-Help header exists. 0051 Archive = 1 << 4, ///< List-Archive header exists. 0052 Id = 1 << 5, ///< List-ID header exists. 0053 Owner = 1 << 6, ///< List-Owner header exists. 0054 ArchivedAt = 1 << 7 ///< Archive-At header exists. 0055 }; 0056 Q_DECLARE_FLAGS(Features, Feature) 0057 0058 public: 0059 /** 0060 * Extracts the information about a mailing list from the given @p message. 0061 */ 0062 static MailingList detect(const KMime::Message::Ptr &message); 0063 0064 static QString name(const KMime::Message::Ptr &message, QByteArray &headerName, QString &headerValue); 0065 0066 public: 0067 /** 0068 * Creates an empty mailing list. 0069 */ 0070 MailingList(); 0071 0072 /** 0073 * Creates a mailing list from an @p other mailing list. 0074 */ 0075 MailingList(const MailingList &other); 0076 0077 /** 0078 * Overwrites this mailing list with an @p other mailing list. 0079 */ 0080 MailingList &operator=(const MailingList &other); 0081 0082 [[nodiscard]] bool operator==(const MailingList &other) const; 0083 /** 0084 * Destroys the mailing list. 0085 */ 0086 ~MailingList(); 0087 0088 /** 0089 * Returns the features the mailing list supports. 0090 */ 0091 [[nodiscard]] Features features() const; 0092 0093 /** 0094 * Sets the @p handler for the mailing list. 0095 */ 0096 void setHandler(Handler handler); 0097 0098 /** 0099 * Returns the handler for the mailing list. 0100 */ 0101 [[nodiscard]] Handler handler() const; 0102 0103 /** 0104 * Sets the list of List-Post @p urls. 0105 */ 0106 void setPostUrls(const QList<QUrl> &urls); 0107 0108 /** 0109 * Returns the list of List-Post urls. 0110 */ 0111 [[nodiscard]] QList<QUrl> postUrls() const; 0112 0113 /** 0114 * Sets the list of List-Subscribe @p urls. 0115 */ 0116 void setSubscribeUrls(const QList<QUrl> &urls); 0117 0118 /** 0119 * Returns the list of List-Subscribe urls. 0120 */ 0121 [[nodiscard]] QList<QUrl> subscribeUrls() const; 0122 0123 /** 0124 * Sets the list of List-Unsubscribe @p urls. 0125 */ 0126 void setUnsubscribeUrls(const QList<QUrl> &urls); 0127 0128 /** 0129 * Returns the list of List-Unsubscribe urls. 0130 */ 0131 [[nodiscard]] QList<QUrl> unsubscribeUrls() const; 0132 0133 /** 0134 * Sets the list of List-Help @p urls. 0135 */ 0136 void setHelpUrls(const QList<QUrl> &urls); 0137 0138 /** 0139 * Returns the list of List-Help urls. 0140 */ 0141 [[nodiscard]] QList<QUrl> helpUrls() const; 0142 0143 /** 0144 * Sets the list of List-Archive @p urls. 0145 */ 0146 void setArchiveUrls(const QList<QUrl> &urls); 0147 0148 /** 0149 * Returns the list of List-Archive urls. 0150 */ 0151 [[nodiscard]] QList<QUrl> archiveUrls() const; 0152 0153 /** 0154 * Sets the list of List-Owner @p urls. 0155 */ 0156 void setOwnerUrls(const QList<QUrl> &urls); 0157 0158 /** 0159 * Returns the list of List-Owner urls. 0160 */ 0161 [[nodiscard]] QList<QUrl> ownerUrls() const; 0162 0163 /** 0164 * Sets the Archived-At @p url. 0165 */ 0166 void setArchivedAtUrls(const QList<QUrl> &url); 0167 0168 /** 0169 * Returns the Archived-At @p url. 0170 */ 0171 [[nodiscard]] QList<QUrl> archivedAtUrls() const; 0172 0173 /** 0174 * Sets the @p id of the mailing list. 0175 */ 0176 void setId(const QString &id); 0177 0178 /** 0179 * Returns the @p id of the mailing list. 0180 */ 0181 [[nodiscard]] QString id() const; 0182 0183 /** 0184 * Saves the configuration for the mailing list to the config @p group. 0185 */ 0186 void writeConfig(KConfigGroup &group) const; 0187 0188 /** 0189 * Restores the configuration for the mailing list from the config @p group. 0190 */ 0191 void readConfig(const KConfigGroup &group); 0192 0193 private: 0194 class MailingListPrivate; 0195 QSharedDataPointer<MailingListPrivate> d; 0196 }; 0197 } 0198 0199 Q_DECLARE_OPERATORS_FOR_FLAGS(MessageCore::MailingList::Features) 0200 Q_DECLARE_METATYPE(MessageCore::MailingList::Features)