aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime/content_type.h
blob: 9d5393e0996fc257857fc75365335291fd653217 (plain)
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
/*-
 * 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_CONTENT_TYPE_H_
#define SRC_LIBMIME_CONTENT_TYPE_H_

#include "config.h"
#include "libutil/fstring.h"
#include "libutil/mem_pool.h"

enum rspamd_content_type_flags {
	RSPAMD_CONTENT_TYPE_VALID = 0,
	RSPAMD_CONTENT_TYPE_BROKEN = 1 << 0,
	RSPAMD_CONTENT_TYPE_MULTIPART = 1 << 1,
	RSPAMD_CONTENT_TYPE_TEXT = 1 << 2,
	RSPAMD_CONTENT_TYPE_MESSAGE = 1 << 3,
	RSPAMD_CONTENT_TYPE_DSN = 1 << 4,
	RSPAMD_CONTENT_TYPE_MISSING = 1 << 5,
};

#define IS_CT_MULTIPART(ct) ((ct)->flags & RSPAMD_CONTENT_TYPE_MULTIPART)
#define IS_CT_TEXT(ct) ((ct)->flags & RSPAMD_CONTENT_TYPE_TEXT)
#define IS_CT_MESSAGE(ct) (((ct)->flags & RSPAMD_CONTENT_TYPE_MESSAGE))

struct rspamd_content_type_param {
	rspamd_ftok_t name;
	rspamd_ftok_t value;
	struct rspamd_content_type_param *prev, *next;
};

struct rspamd_content_type {
	gchar *lc_data;
	rspamd_ftok_t type;
	rspamd_ftok_t subtype;
	rspamd_ftok_t charset;
	rspamd_ftok_t boundary;
	enum rspamd_content_type_flags flags;
	GHashTable *attrs; /* Can be empty */
};

enum rspamd_contetn_disposition_type {
	RSPAMD_CT_UNKNOWN = 0,
	RSPAMD_CT_INLINE = 1,
	RSPAMD_CT_ATTACHMENT = 2,
};

struct rspamd_content_disposition {
	gchar *lc_data;
	enum rspamd_contetn_disposition_type type;
	rspamd_ftok_t filename;
	GHashTable *attrs; /* Can be empty */
};

/**
 * Adds new parameter to content type structure
 * @param ct
 * @param name_start
 * @param name_end
 * @param value_start
 * @param value_end
 */
void
rspamd_content_type_add_param (rspamd_mempool_t *pool,
		struct rspamd_content_type *ct,
		const gchar *name_start, const gchar *name_end,
		const gchar *value_start, const gchar *value_end);

/**
 * Parse content type from the header (performs copy + lowercase)
 * @param in
 * @param len
 * @param pool
 * @return
 */
struct rspamd_content_type * rspamd_content_type_parse (const gchar *in,
		gsize len, rspamd_mempool_t *pool);

/**
 * Adds new param for content disposition header
 * @param pool
 * @param cd
 * @param name_start
 * @param name_end
 * @param value_start
 * @param value_end
 */
void
rspamd_content_disposition_add_param (rspamd_mempool_t *pool,
		struct rspamd_content_disposition *cd,
		const gchar *name_start, const gchar *name_end,
		const gchar *value_start, const gchar *value_end);

/**
 * Parse content-disposition header
 * @param in
 * @param len
 * @param pool
 * @return
 */
struct rspamd_content_disposition * rspamd_content_disposition_parse (const gchar *in,
		gsize len, rspamd_mempool_t *pool);

#endif /* SRC_LIBMIME_CONTENT_TYPE_H_ */