Messagelib

mailinglist.h
1/*
2 * SPDX-License-Identifier: LGPL-2.1-or-later
3 *
4 */
5
6#pragma once
7
8#include "messagecore_export.h"
9
10#include <KMime/Message>
11#include <QUrl>
12
13#include <QByteArray>
14#include <QSharedDataPointer>
15#include <QString>
16
17class KConfigGroup;
18
19namespace MessageCore
20{
21/**
22 * @short A class to extract information about mailing lists from emails.
23 *
24 * The mailing list header fields are defined as the following:
25 * - "List-*" in RFC2369
26 * - "List-ID" in RFC2919.
27 * - "Archive-At" in RFC5064
28 *
29 * @author Zack Rusin <zack@kde.org>
30 */
31class MESSAGECORE_EXPORT MailingList
32{
33public:
34 /**
35 * Defines what entity should manage the mailing list.
36 */
37 enum Handler : uint8_t {
38 KMail, ///< The list is handled by KMail
39 Browser, ///< The list is handled by a browser.
40 };
41
42 /**
43 * Defines the features a mailinglist can support.
44 */
45 enum Feature {
46 None = 0 << 0, ///< No mailing list fields exist.
47 Post = 1 << 0, ///< List-Post header exists.
48 Subscribe = 1 << 1, ///< List-Subscribe header exists.
49 Unsubscribe = 1 << 2, ///< List-Unsubscribe header exists.
50 Help = 1 << 3, ///< List-Help header exists.
51 Archive = 1 << 4, ///< List-Archive header exists.
52 Id = 1 << 5, ///< List-ID header exists.
53 Owner = 1 << 6, ///< List-Owner header exists.
54 ArchivedAt = 1 << 7 ///< Archive-At header exists.
55 };
56 Q_DECLARE_FLAGS(Features, Feature)
57
58public:
59 /**
60 * Extracts the information about a mailing list from the given @p message.
61 */
62 static MailingList detect(const KMime::Message::Ptr &message);
63
64 static QString name(const KMime::Message::Ptr &message, QByteArray &headerName, QString &headerValue);
65
66public:
67 /**
68 * Creates an empty mailing list.
69 */
71
72 /**
73 * Creates a mailing list from an @p other mailing list.
74 */
75 MailingList(const MailingList &other);
76
77 /**
78 * Overwrites this mailing list with an @p other mailing list.
79 */
80 MailingList &operator=(const MailingList &other);
81
82 [[nodiscard]] bool operator==(const MailingList &other) const;
83 /**
84 * Destroys the mailing list.
85 */
87
88 /**
89 * Returns the features the mailing list supports.
90 */
91 [[nodiscard]] Features features() const;
92
93 /**
94 * Sets the @p handler for the mailing list.
95 */
96 void setHandler(Handler handler);
97
98 /**
99 * Returns the handler for the mailing list.
100 */
101 [[nodiscard]] Handler handler() const;
102
103 /**
104 * Sets the list of List-Post @p urls.
105 */
106 void setPostUrls(const QList<QUrl> &urls);
107
108 /**
109 * Returns the list of List-Post urls.
110 */
111 [[nodiscard]] QList<QUrl> postUrls() const;
112
113 /**
114 * Sets the list of List-Subscribe @p urls.
115 */
116 void setSubscribeUrls(const QList<QUrl> &urls);
117
118 /**
119 * Returns the list of List-Subscribe urls.
120 */
121 [[nodiscard]] QList<QUrl> subscribeUrls() const;
122
123 /**
124 * Sets the list of List-Unsubscribe @p urls.
125 */
126 void setUnsubscribeUrls(const QList<QUrl> &urls);
127
128 /**
129 * Returns the list of List-Unsubscribe urls.
130 */
131 [[nodiscard]] QList<QUrl> unsubscribeUrls() const;
132
133 /**
134 * Sets the list of List-Help @p urls.
135 */
136 void setHelpUrls(const QList<QUrl> &urls);
137
138 /**
139 * Returns the list of List-Help urls.
140 */
141 [[nodiscard]] QList<QUrl> helpUrls() const;
142
143 /**
144 * Sets the list of List-Archive @p urls.
145 */
146 void setArchiveUrls(const QList<QUrl> &urls);
147
148 /**
149 * Returns the list of List-Archive urls.
150 */
151 [[nodiscard]] QList<QUrl> archiveUrls() const;
152
153 /**
154 * Sets the list of List-Owner @p urls.
155 */
156 void setOwnerUrls(const QList<QUrl> &urls);
157
158 /**
159 * Returns the list of List-Owner urls.
160 */
161 [[nodiscard]] QList<QUrl> ownerUrls() const;
162
163 /**
164 * Sets the Archived-At @p url.
165 */
166 void setArchivedAtUrls(const QList<QUrl> &url);
167
168 /**
169 * Returns the Archived-At @p url.
170 */
171 [[nodiscard]] QList<QUrl> archivedAtUrls() const;
172
173 /**
174 * Sets the @p id of the mailing list.
175 */
176 void setId(const QString &id);
177
178 /**
179 * Returns the @p id of the mailing list.
180 */
181 [[nodiscard]] QString id() const;
182
183 /**
184 * Saves the configuration for the mailing list to the config @p group.
185 */
186 void writeConfig(KConfigGroup &group) const;
187
188 /**
189 * Restores the configuration for the mailing list from the config @p group.
190 */
191 void readConfig(const KConfigGroup &group);
192
193private:
194 class MailingListPrivate;
196};
197}
198
199Q_DECLARE_OPERATORS_FOR_FLAGS(MessageCore::MailingList::Features)
200Q_DECLARE_METATYPE(MessageCore::MailingList::Features)
A class to extract information about mailing lists from emails.
Definition mailinglist.h:32
Handler
Defines what entity should manage the mailing list.
Definition mailinglist.h:37
@ Browser
The list is handled by a browser.
Definition mailinglist.h:39
@ KMail
The list is handled by KMail.
Definition mailinglist.h:38
~MailingList()
Destroys the mailing list.
MailingList(const MailingList &other)
Creates a mailing list from an other mailing list.
Feature
Defines the features a mailinglist can support.
Definition mailinglist.h:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.