1 #ifndef MESSAGE_PART_DATA_H
2 #define MESSAGE_PART_DATA_H
3 
4 #include "message-part.h"
5 
6 #define MESSAGE_PART_DEFAULT_CHARSET "us-ascii"
7 
8 struct message_header_line;
9 
10 struct message_part_param {
11 	const char *name;
12 	const char *value;
13 };
14 
15 struct message_part_envelope {
16 	const char *date, *subject;
17 	struct message_address *from, *sender, *reply_to;
18 	struct message_address *to, *cc, *bcc;
19 
20 	const char *in_reply_to, *message_id;
21 };
22 
23 struct message_part_data {
24 	const char *content_type, *content_subtype;
25 	const struct message_part_param *content_type_params;
26 	unsigned int content_type_params_count;
27 
28 	const char *content_transfer_encoding;
29 	const char *content_id;
30 	const char *content_description;
31 	const char *content_disposition;
32 	const struct message_part_param *content_disposition_params;
33 	unsigned int content_disposition_params_count;
34 	const char *content_md5;
35 	const char *const *content_language;
36 	const char *content_location;
37 
38 	struct message_part_envelope *envelope;
39 };
40 
41 struct message_part_attachment_settings {
42 	/* By default, all attachments with content-disposition=attachment
43 	   or content-disposition=inline;filename=... are consired as an
44 	   attachment.
45 
46 	   If content_type_filter is set to an array of masks, then
47 	   anything starting with ! is excluded, and anything without
48 	   is considered negating exclusion. Setting foo/bar alone will */
49 //	   not do anything, but setting !foo/*, foo/bar, will exclude
50 	/* all attachments with foo/anything content type, but will
51 	   accept foo/bar.
52 
53 	   Setting exclude_inlined, will exclude **any** inlined attachment
54 	   regardless of what content_type_filter is.
55 	*/
56 	const char *const *content_type_filter;
57 	bool exclude_inlined;
58 };
59 
60 extern const char *message_part_envelope_headers[];
61 
62 /*
63  *
64  */
65 
66 /* Returns TRUE if this message part has content-type "text/plain",
67    charset "us-ascii" and content-transfer-encoding "7bit" */
68 bool message_part_data_is_plain_7bit(const struct message_part *part)
69 	ATTR_PURE;
70 
71 /* Returns TRUE if this message part has a filename. The filename is
72    returned in filename_r. */
73 bool message_part_data_get_filename(const struct message_part *part,
74 	const char **filename_r);
75 
76 /* See message_part_attachment_settings */
77 bool message_part_has_content_types(struct message_part *part, const char *const *types);
78 
79 /* Returns TRUE if message part has given parameter, and has non-empty
80    value if has_value is TRUE. */
81 bool message_part_has_parameter(struct message_part *part, const char *parameter,
82 				bool has_value);
83 
84 /* Check if part is attachment according to given settings */
85 bool message_part_is_attachment(struct message_part *part,
86 				const struct message_part_attachment_settings *set);
87 /*
88  * Header parsing
89  */
90 
91 /* Update envelope data based from given header field */
92 void message_part_envelope_parse_from_header(pool_t pool,
93 	struct message_part_envelope **_data,
94 	struct message_header_line *hdr);
95 
96 /* Parse a single header. Note that this modifies part->context. */
97 void message_part_data_parse_from_header(pool_t pool,
98 	struct message_part *part,
99 	struct message_header_line *hdr);
100 
101 #endif
102