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
|
/*-
* Copyright 2016 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SRC_LIBMIME_MIME_HEADERS_H_
#define SRC_LIBMIME_MIME_HEADERS_H_
#include "config.h"
#include "libutil/mem_pool.h"
#include "libutil/addr.h"
#ifdef __cplusplus
extern "C" {
#endif
struct rspamd_task;
enum rspamd_rfc2047_encoding {
RSPAMD_RFC2047_QP = 0,
RSPAMD_RFC2047_BASE64,
};
enum rspamd_mime_header_flags {
RSPAMD_HEADER_GENERIC = 0u,
RSPAMD_HEADER_RECEIVED = 1u << 0u,
RSPAMD_HEADER_TO = 1u << 2u,
RSPAMD_HEADER_CC = 1u << 3u,
RSPAMD_HEADER_BCC = 1u << 4u,
RSPAMD_HEADER_FROM = 1u << 5u,
RSPAMD_HEADER_MESSAGE_ID = 1u << 6u,
RSPAMD_HEADER_SUBJECT = 1u << 7u,
RSPAMD_HEADER_RETURN_PATH = 1u << 8u,
RSPAMD_HEADER_DELIVERED_TO = 1u << 9u,
RSPAMD_HEADER_SENDER = 1u << 10u,
RSPAMD_HEADER_RCPT = 1u << 11u,
RSPAMD_HEADER_UNIQUE = 1u << 12u,
RSPAMD_HEADER_EMPTY_SEPARATOR = 1u << 13u,
RSPAMD_HEADER_TAB_SEPARATED = 1u << 14u,
};
struct rspamd_mime_header {
gchar *name;
gchar *value;
const gchar *raw_value; /* As it is in the message (unfolded and unparsed) */
gsize raw_len;
guint order;
int flags; /* see enum rspamd_mime_header_flags */
gchar *separator;
gchar *decoded;
struct rspamd_mime_header *prev, *next; /* Headers with the same name */
struct rspamd_mime_header *ord_prev, *ord_next; /* Overall order of headers */
};
enum rspamd_received_type {
RSPAMD_RECEIVED_SMTP = 0,
RSPAMD_RECEIVED_ESMTP = 1u << 0u,
RSPAMD_RECEIVED_ESMTPA = 1u << 1u,
RSPAMD_RECEIVED_ESMTPS = 1u << 2u,
RSPAMD_RECEIVED_ESMTPSA = 1u << 3u,
RSPAMD_RECEIVED_LMTP = 1u << 4u,
RSPAMD_RECEIVED_IMAP = 1u << 5u,
RSPAMD_RECEIVED_LOCAL = 1u << 6u,
RSPAMD_RECEIVED_HTTP = 1u << 7u,
RSPAMD_RECEIVED_MAPI = 1u << 8u,
RSPAMD_RECEIVED_UNKNOWN = 1u << 9u,
RSPAMD_RECEIVED_FLAG_ARTIFICIAL = (1u << 10u),
RSPAMD_RECEIVED_FLAG_SSL = (1u << 11u),
RSPAMD_RECEIVED_FLAG_AUTHENTICATED = (1u << 12u),
};
struct received_header {
const gchar *from_hostname;
const gchar *from_ip;
const gchar *real_hostname;
const gchar *real_ip;
const gchar *by_hostname;
const gchar *for_mbox;
rspamd_inet_addr_t *addr;
struct rspamd_mime_header *hdr;
time_t timestamp;
gint flags; /* See enum rspamd_received_type */
struct received_header *prev, *next;
};
/**
* Process headers and store them in `target`
* @param task
* @param target
* @param in
* @param len
* @param check_newlines
*/
void rspamd_mime_headers_process (struct rspamd_task *task,
GHashTable *target,
struct rspamd_mime_header **order_ptr,
const gchar *in, gsize len,
gboolean check_newlines);
/**
* Perform rfc2047 decoding of a header
* @param pool
* @param in
* @param inlen
* @return
*/
gchar *rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in,
gsize inlen, gboolean *invalid_utf);
/**
* Encode mime header if needed
* @param in
* @param len
* @return newly allocated encoded header
*/
gchar *rspamd_mime_header_encode (const gchar *in, gsize len);
/**
* Generate new unique message id
* @param fqdn
* @return
*/
gchar *rspamd_mime_message_id_generate (const gchar *fqdn);
#ifdef __cplusplus
}
#endif
#endif /* SRC_LIBMIME_MIME_HEADERS_H_ */
|