-
Notifications
You must be signed in to change notification settings - Fork 0
/
unsubscribemanager.h
127 lines (109 loc) · 3.58 KB
/
unsubscribemanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef _UNSUBSCRIBEMANAGER_H_
#define _UNSUBSCRIBEMANAGER_H_
#include <QObject>
#include <Akonadi/Item>
#include <KMime/KMimeMessage>
#include <MessageCore/MailingList>
#include <MessageViewer/DKIMManager>
#define LIST_UNSUBSCRIBE_POST_HDR "List-Unsubscribe-Post"
#define LIST_UNSUBSCRIBE_POST_VALUE "List-Unsubscribe=One-Click"
namespace MessageViewer
{
class UnsubscribeManager : public QObject
{
Q_OBJECT
public:
explicit UnsubscribeManager(QObject *parent = nullptr);
~UnsubscribeManager() override;
struct Result
{
enum _errorType
{
None = 0,
NetworkError,
SslError,
} Type;
QString ErrorString;
};
enum Status
{
/// @brief No unsubscribe method is available.
None,
/// @brief Unsubscribe is available, but not as one-click unsubscribe.
NoOneClick,
/**
* @brief One-Click Unsubscribe is available, but DKIM didn't verify.
*
* Note: This state is considered non-compliant with RFC 8058.
*/
InvalidOneClick,
/// @brief One-Click Unsubscribe is available.
ValidOneClick,
};
/**
* @brief Sets the current message item.
*
* @param item The current message item.
*/
void setMessageItem(const Akonadi::Item &item);
/**
* @brief Tests whether the current message item has been set.
*/
bool hasMessage();
/**
* @brief Tests if the message has information to programmatically unsubscribe
*
* @return true if the message can be unsubscribed from.
* @return false if the message cannot be unsubscribed from.
*/
Status unsubscribeStatus();
/**
* @brief Performs a One-Click unsubscribe.
*/
void doOneClick();
/**
* @brief Get the URL for One-Click Unsubscribe.
*
* @return QUrl The URL. If none was found, the URL will be empty.
*/
QUrl oneClickUrl();
/**
* @brief Get the best Unsubscribe URL.
* Unlike oneClickUrl, this will check for any usable Unsubscribe URL.
* The search order is currently HTTPS, MAILTO, and HTTP URLs.
*
* @return QUrl The best available Unsubscribe URL, per the above heuristic
*/
QUrl getUrl();
/**
* @brief Resets the object's state.
* @remark This does not cancel any running One-Click Unsubscribe jobs.
*
*/
void reset();
public slots:
/**
* @brief This is used as a slot for DKIMManager::result.
* This signal can only be signalled once-- further signals will be
* ignored.
*
* @param checkResult
* @param id
*/
void getDkimResult(const MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult &checkResult, Akonadi::Item::Id id);
void checkResult(const Result &result);
signals:
void oneClickResult(bool isSuccess, const QString &resultString);
private:
// message info
KMime::Message::Ptr mMessage = nullptr;
MessageCore::MailingList mList;
Akonadi::Item::Id mItemId = -1;
// Cached by oneClickUrl()
QUrl mPostUrl;
// Used to check DKIM, for RFC 8058 compliance
DKIMManager mDkimMgr;
bool mDKIMValid = false;
};
}
#endif /* !_UNSUBSCRIBEMANAGER_H_ */