-
Notifications
You must be signed in to change notification settings - Fork 1
/
classrfc5322.h
158 lines (148 loc) · 4.14 KB
/
classrfc5322.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*************************************************************
**
** Copyright (C) 2021 Timothy Millea <cyberlord@cyber-wizard.com>
**
** License: GPLv3.0 or later
**
*************************************************************/
#ifndef CLASSRFC5322_H
#define CLASSRFC5322_H
#include <QObject>
#include <QHash>
#include <QDebug>
#include <QDateTime>
#include <QCryptographicHash>
/**
* @brief The RFC5322HeaderFieldStruct struct - contains the header field info
*/
struct RFC5322HeaderFieldStruct
{
/**
* @brief fieldName - stores the field name
*/
QString fieldName;
/**
* @brief fieldBody - stores the field data
*/
QString fieldBody;
};
/**
* @brief The RFC5322MessageStruct struct - RFC5322 message structure
*/
struct RFC5322MessageStruct
{
/**
* @brief body - stores the message body
*/
QByteArray body;
/**
* @brief headerFields - stores the message header fields
*/
QList<RFC5322HeaderFieldStruct> headerFields;
//TODO MIME attachments???
};
/**
* @brief The PARSE_STATE enum - state of the parser
*/
enum PARSE_STATE {
PS_NONE,
PS_HEADER,
PS_FWS,
PS_BODY,
PS_ATTACHMENT
};
/**
* @brief The ClassRFC5322 class - class to handle RFC5322 messages
*/
class ClassRFC5322 : public QObject
{
Q_OBJECT
private:
/**
* @brief parseBody - parse the line and store in message.body
* @param line
* @param message
*/
static void parseBody(const QString &line, RFC5322MessageStruct &message);
/**
* @brief parseHeader - parse the line and store in message header
* @param headerLine
* @param message
*/
static void parseHeader(const QString &headerLine, RFC5322MessageStruct &message);
/**
* @brief getJulianDate
* @return - the current datatimeUTC in day of year format
*/
static QString getJulianDate();
/**
* @brief removeAllWhiteSpace - remove all white space from string
* @param string
* @return
*/
static QString removeAllWhiteSpace(QString string);
/**
* @brief getDomainAddress - get the domain address from string
* @param string
* @return
*/
static QString getDomainAddress(QString string);
public:
/**
* @brief parseMessage - parse received data and store in message
* @param receivedData
* @param message
*/
static void parseMessage(const QString &receivedData, RFC5322MessageStruct &message);
/**
* @brief parseMessage - parse received data and store in message
* @param receivedData
* @return
*/
static RFC5322MessageStruct parseMessage(const QString &receivedData);
/**
* @brief composeMessage - compose RFC5322 message from message structure
* @param message
* @return
*/
static QByteArray composeMessage(const RFC5322MessageStruct message);
/**
* @brief generateMessageID - generate a messageID
* @param from
* @param msgNumber
* @return
*/
static QString generateMessageID(QString from, int msgNumber);
/**
* @brief generateMessageID - generate a messageID
* @param from
* @return
*/
static QString generateMessageID(QString from);
/**
* @brief generateDigest - generate an MD5 digest from message body
* @param messageBody
* @return
*/
static QByteArray generateDigest(QString messageBody);
/**
* @brief getCurrentDate - get the current date in RFC5322 format
* @return
*/
static QString getCurrentDate();
/**
* @brief getFieldData - get data from fieldname in message struct
* @param fieldName
* @param messageStructure
* @return
*/
static QString getFieldData(const QString fieldName, RFC5322MessageStruct &messageStructure);
/**
* @brief getHeaderData - get header data in RFC5322 format from message struct
* @param messageStructure
* @return
*/
static QString getHeaderData(RFC5322MessageStruct &messageStructure);
signals:
};
#endif // CLASSRFC5322_H