summaryrefslogtreecommitdiffstats
path: root/src/lib-mail/message-part-data.h
blob: 7ec878de68ed5d1105fbf6ec1f51235f0e3326eb (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
#ifndef MESSAGE_PART_DATA_H
#define MESSAGE_PART_DATA_H

#include "message-part.h"
#include "message-address.h"

#define MESSAGE_PART_DEFAULT_CHARSET "us-ascii"

struct message_header_line;

struct message_part_param {
	const char *name;
	const char *value;
};

struct message_part_envelope {
	const char *date, *subject;

	struct message_address_list from, sender, reply_to;
	struct message_address_list to, cc, bcc;

	const char *in_reply_to, *message_id;
};

struct message_part_data {
	const char *content_type, *content_subtype;
	const struct message_part_param *content_type_params;
	unsigned int content_type_params_count;

	const char *content_transfer_encoding;
	const char *content_id;
	const char *content_description;
	const char *content_disposition;
	const struct message_part_param *content_disposition_params;
	unsigned int content_disposition_params_count;
	const char *content_md5;
	const char *const *content_language;
	const char *content_location;

	struct message_part_envelope *envelope;
};

struct message_part_attachment_settings {
	/* By default, all attachments with content-disposition=attachment
	   or content-disposition=inline;filename=... are consired as an
	   attachment.

	   If content_type_filter is set to an array of masks, then
	   anything starting with ! is excluded, and anything without
	   is considered negating exclusion. Setting foo/bar alone will */
//	   not do anything, but setting !foo/*, foo/bar, will exclude
	/* all attachments with foo/anything content type, but will
	   accept foo/bar.

	   Setting exclude_inlined, will exclude **any** inlined attachment
	   regardless of what content_type_filter is.
	*/
	const char *const *content_type_filter;
	bool exclude_inlined;
};

extern const char *message_part_envelope_headers[];

/*
 *
 */

/* Returns TRUE if this message part has content-type "text/plain",
   charset "us-ascii" and content-transfer-encoding "7bit" */
bool message_part_data_is_plain_7bit(const struct message_part *part)
	ATTR_PURE;

/* Returns TRUE if this message part has a filename. The filename is
   returned in filename_r. */
bool message_part_data_get_filename(const struct message_part *part,
	const char **filename_r);

/* See message_part_attachment_settings */
bool message_part_has_content_types(struct message_part *part, const char *const *types);

/* Returns TRUE if message part has given parameter, and has non-empty
   value if has_value is TRUE. */
bool message_part_has_parameter(struct message_part *part, const char *parameter,
				bool has_value);

/* Check if part is attachment according to given settings */
bool message_part_is_attachment(struct message_part *part,
				const struct message_part_attachment_settings *set);
/*
 * Header parsing
 */

/* Update envelope data based from given header field */
void message_part_envelope_parse_from_header(pool_t pool,
	struct message_part_envelope **_data,
	struct message_header_line *hdr);

/* Parse a single header. Note that this modifies part->context. */
void message_part_data_parse_from_header(pool_t pool,
	struct message_part *part,
	struct message_header_line *hdr);

#endif