annotate src/lib-mail/message-part-data.c @ 22884:77577228fd8f

lib-mail: Make sure parsers don't accidentally go much beyond end pointer
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 22 Dec 2017 18:42:53 +0200
parents a982d52a740b
children 075c48f8ffb5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21915
diff changeset
1 /* Copyright (c) 2014-2018 Dovecot authors, see the included COPYING file */
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
2
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
3 #include "lib.h"
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
4 #include "str.h"
22780
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
5 #include "wildcard-match.h"
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
6 #include "array.h"
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
7 #include "rfc822-parser.h"
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
8 #include "rfc2231-parser.h"
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
9 #include "message-address.h"
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
10 #include "message-header-parser.h"
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
11
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
12 #include "message-part-data.h"
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
13
21634
e2071511ef6d lib-imap: imap-envelope: Moved imap_envelope_headers to lib-mail/message-part-data as message_part_envelope_headers.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21633
diff changeset
14 const char *message_part_envelope_headers[] = {
e2071511ef6d lib-imap: imap-envelope: Moved imap_envelope_headers to lib-mail/message-part-data as message_part_envelope_headers.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21633
diff changeset
15 "Date", "Subject", "From", "Sender", "Reply-To",
e2071511ef6d lib-imap: imap-envelope: Moved imap_envelope_headers to lib-mail/message-part-data as message_part_envelope_headers.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21633
diff changeset
16 "To", "Cc", "Bcc", "In-Reply-To", "Message-ID",
e2071511ef6d lib-imap: imap-envelope: Moved imap_envelope_headers to lib-mail/message-part-data as message_part_envelope_headers.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21633
diff changeset
17 NULL
e2071511ef6d lib-imap: imap-envelope: Moved imap_envelope_headers to lib-mail/message-part-data as message_part_envelope_headers.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21633
diff changeset
18 };
e2071511ef6d lib-imap: imap-envelope: Moved imap_envelope_headers to lib-mail/message-part-data as message_part_envelope_headers.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21633
diff changeset
19
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
20 /*
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
21 *
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
22 */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
23
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
24 bool message_part_data_is_plain_7bit(const struct message_part *part)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
25 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
26 const struct message_part_data *data = part->data;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
27
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
28 i_assert(part->parent == NULL);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
29
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
30 /* if content-type is text/xxx we don't have to check any
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
31 multipart stuff */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
32 if ((part->flags & MESSAGE_PART_FLAG_TEXT) == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
33 return FALSE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
34 if (part->next != NULL || part->children != NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
35 return FALSE; /* shouldn't happen normally.. */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
36
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
37 /* must be text/plain */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
38 if (data->content_subtype != NULL &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
39 strcasecmp(data->content_subtype, "plain") != 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
40 return FALSE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
41
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
42 /* only allowed parameter is charset=us-ascii, which is also default */
21673
e4b2931f3566 lib-mail: Fix message_part_data_is_plain_7bit()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21636
diff changeset
43 if (data->content_type_params_count == 0) {
e4b2931f3566 lib-mail: Fix message_part_data_is_plain_7bit()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21636
diff changeset
44 /* charset defaults to us-ascii */
e4b2931f3566 lib-mail: Fix message_part_data_is_plain_7bit()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21636
diff changeset
45 } else if (data->content_type_params_count != 1 ||
e4b2931f3566 lib-mail: Fix message_part_data_is_plain_7bit()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21636
diff changeset
46 strcasecmp(data->content_type_params[0].name, "charset") != 0 ||
e4b2931f3566 lib-mail: Fix message_part_data_is_plain_7bit()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21636
diff changeset
47 strcasecmp(data->content_type_params[0].value,
e4b2931f3566 lib-mail: Fix message_part_data_is_plain_7bit()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21636
diff changeset
48 MESSAGE_PART_DEFAULT_CHARSET) != 0)
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
49 return FALSE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
50
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
51 if (data->content_id != NULL ||
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
52 data->content_description != NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
53 return FALSE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
54
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
55 if (data->content_transfer_encoding != NULL &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
56 strcasecmp(data->content_transfer_encoding, "7bit") != 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
57 return FALSE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
58
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
59 /* BODYSTRUCTURE checks: */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
60 if (data->content_md5 != NULL ||
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
61 data->content_disposition != NULL ||
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
62 data->content_language != NULL ||
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
63 data->content_location != NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
64 return FALSE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
65
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
66 return TRUE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
67 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
68
21636
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
69 bool message_part_data_get_filename(const struct message_part *part,
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
70 const char **filename_r)
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
71 {
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
72 const struct message_part_data *data = part->data;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
73 const struct message_part_param *params;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
74 unsigned int params_count, i;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
75
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
76 params = data->content_disposition_params;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
77 params_count = data->content_disposition_params_count;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
78
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
79 if (data->content_disposition != NULL &&
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
80 strcasecmp(data->content_disposition, "attachment") != 0) {
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
81 return FALSE;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
82 }
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
83 for (i = 0; i < params_count; i++) {
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
84 if (strcasecmp(params[i].name, "filename") == 0 &&
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
85 params[i].value != NULL) {
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
86 *filename_r = params[i].value;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
87 return TRUE;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
88 }
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
89 }
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
90 return FALSE;
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
91 }
c7b8d82390d4 lib-mail: message-part-data: Implemented message_part_data_get_filename().
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21635
diff changeset
92
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
93 /*
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
94 * Header parsing
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
95 */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
96
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
97 /* Message part envelope */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
98
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
99 enum envelope_field {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
100 ENVELOPE_FIELD_DATE = 0,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
101 ENVELOPE_FIELD_SUBJECT,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
102 ENVELOPE_FIELD_FROM,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
103 ENVELOPE_FIELD_SENDER,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
104 ENVELOPE_FIELD_REPLY_TO,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
105 ENVELOPE_FIELD_TO,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
106 ENVELOPE_FIELD_CC,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
107 ENVELOPE_FIELD_BCC,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
108 ENVELOPE_FIELD_IN_REPLY_TO,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
109 ENVELOPE_FIELD_MESSAGE_ID,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
110
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
111 ENVELOPE_FIELD_UNKNOWN
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
112 };
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
113
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
114 static enum envelope_field
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
115 envelope_get_field(const char *name)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
116 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
117 switch (*name) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
118 case 'B':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
119 case 'b':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
120 if (strcasecmp(name, "Bcc") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
121 return ENVELOPE_FIELD_BCC;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
122 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
123 case 'C':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
124 case 'c':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
125 if (strcasecmp(name, "Cc") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
126 return ENVELOPE_FIELD_CC;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
127 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
128 case 'D':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
129 case 'd':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
130 if (strcasecmp(name, "Date") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
131 return ENVELOPE_FIELD_DATE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
132 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
133 case 'F':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
134 case 'f':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
135 if (strcasecmp(name, "From") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
136 return ENVELOPE_FIELD_FROM;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
137 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
138 case 'I':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
139 case 'i':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
140 if (strcasecmp(name, "In-reply-to") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
141 return ENVELOPE_FIELD_IN_REPLY_TO;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
142 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
143 case 'M':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
144 case 'm':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
145 if (strcasecmp(name, "Message-id") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
146 return ENVELOPE_FIELD_MESSAGE_ID;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
147 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
148 case 'R':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
149 case 'r':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
150 if (strcasecmp(name, "Reply-to") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
151 return ENVELOPE_FIELD_REPLY_TO;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
152 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
153 case 'S':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
154 case 's':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
155 if (strcasecmp(name, "Subject") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
156 return ENVELOPE_FIELD_SUBJECT;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
157 if (strcasecmp(name, "Sender") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
158 return ENVELOPE_FIELD_SENDER;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
159 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
160 case 'T':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
161 case 't':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
162 if (strcasecmp(name, "To") == 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
163 return ENVELOPE_FIELD_TO;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
164 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
165 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
166
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
167 return ENVELOPE_FIELD_UNKNOWN;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
168 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
169
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
170 void message_part_envelope_parse_from_header(pool_t pool,
21635
30aacb0df12f lib-mail: message-part-data: Renamed struct message_part_envelope_data to message_part_envelope.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21634
diff changeset
171 struct message_part_envelope **data,
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
172 struct message_header_line *hdr)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
173 {
21635
30aacb0df12f lib-mail: message-part-data: Renamed struct message_part_envelope_data to message_part_envelope.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21634
diff changeset
174 struct message_part_envelope *d;
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
175 enum envelope_field field;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
176 struct message_address **addr_p;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
177 const char **str_p;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
178
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
179 if (*data == NULL) {
21635
30aacb0df12f lib-mail: message-part-data: Renamed struct message_part_envelope_data to message_part_envelope.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21634
diff changeset
180 *data = p_new(pool, struct message_part_envelope, 1);
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
181 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
182
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
183 if (hdr == NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
184 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
185 field = envelope_get_field(hdr->name);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
186 if (field == ENVELOPE_FIELD_UNKNOWN)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
187 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
188
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
189 if (hdr->continues) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
190 /* wait for full value */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
191 hdr->use_full_value = TRUE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
192 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
193 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
194
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
195 d = *data;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
196 addr_p = NULL; str_p = NULL;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
197 switch (field) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
198 case ENVELOPE_FIELD_DATE:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
199 str_p = &d->date;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
200 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
201 case ENVELOPE_FIELD_SUBJECT:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
202 str_p = &d->subject;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
203 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
204 case ENVELOPE_FIELD_MESSAGE_ID:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
205 str_p = &d->message_id;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
206 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
207 case ENVELOPE_FIELD_IN_REPLY_TO:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
208 str_p = &d->in_reply_to;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
209 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
210
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
211 case ENVELOPE_FIELD_CC:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
212 addr_p = &d->cc;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
213 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
214 case ENVELOPE_FIELD_BCC:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
215 addr_p = &d->bcc;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
216 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
217 case ENVELOPE_FIELD_FROM:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
218 addr_p = &d->from;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
219 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
220 case ENVELOPE_FIELD_SENDER:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
221 addr_p = &d->sender;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
222 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
223 case ENVELOPE_FIELD_TO:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
224 addr_p = &d->to;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
225 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
226 case ENVELOPE_FIELD_REPLY_TO:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
227 addr_p = &d->reply_to;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
228 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
229 case ENVELOPE_FIELD_UNKNOWN:
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
230 i_unreached();
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
231 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
232
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
233 if (addr_p != NULL) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
234 *addr_p = message_address_parse(pool, hdr->full_value,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
235 hdr->full_value_len,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
236 UINT_MAX, TRUE);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
237 } else if (str_p != NULL) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
238 *str_p = p_strndup(pool,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
239 hdr->full_value, hdr->full_value_len);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
240 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
241 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
242
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
243 /* Message part data */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
244
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
245 static void
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
246 parse_mime_parameters(struct rfc822_parser_context *parser,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
247 pool_t pool, const struct message_part_param **params_r,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
248 unsigned int *params_count_r)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
249 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
250 const char *const *results;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
251 struct message_part_param *params;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
252 unsigned int params_count, i;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
253
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
254 rfc2231_parse(parser, &results);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
255
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
256 params_count = str_array_length(results);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
257 i_assert((params_count % 2) == 0);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
258 params_count /= 2;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
259
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
260 if (params_count > 0) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
261 params = p_new(pool, struct message_part_param, params_count);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
262 for (i = 0; i < params_count; i++) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
263 params[i].name = p_strdup(pool, results[i*2+0]);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
264 params[i].value = p_strdup(pool, results[i*2+1]);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
265 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
266 *params_r = params;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
267 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
268
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
269 *params_count_r = params_count;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
270 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
271
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
272 static void
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
273 parse_content_type(struct message_part_data *data,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
274 pool_t pool, struct message_header_line *hdr)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
275 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
276 struct rfc822_parser_context parser;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
277 string_t *str;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
278 const char *value;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
279 unsigned int i;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
280 int ret;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
281
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
282 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
283 rfc822_skip_lwsp(&parser);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
284
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
285 str = t_str_new(256);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
286 ret = rfc822_parse_content_type(&parser, str);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
287
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
288 /* Save content type and subtype */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
289 value = str_c(str);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
290 for (i = 0; value[i] != '\0'; i++) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
291 if (value[i] == '/') {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
292 data->content_subtype = p_strdup(pool, value + i+1);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
293 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
294 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
295 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
296 str_truncate(str, i);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
297 data->content_type = p_strdup(pool, str_c(str));
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
298
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
299 if (ret < 0) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
300 /* Content-Type is broken, but we wanted to get it as well as
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
301 we could. Don't try to read the parameters anymore though.
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
302
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
303 We don't completely ignore a broken Content-Type, because
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
304 then it would be written as text/plain. This would cause a
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
305 mismatch with the message_part's MESSAGE_PART_FLAG_TEXT. */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
306 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
307 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
308
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
309 parse_mime_parameters(&parser, pool,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
310 &data->content_type_params,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
311 &data->content_type_params_count);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
312 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
313
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
314 static void
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
315 parse_content_transfer_encoding(struct message_part_data *data,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
316 pool_t pool, struct message_header_line *hdr)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
317 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
318 struct rfc822_parser_context parser;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
319 string_t *str;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
320
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
321 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
322 rfc822_skip_lwsp(&parser);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
323
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
324 str = t_str_new(256);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
325 if (rfc822_parse_mime_token(&parser, str) >= 0 &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
326 rfc822_skip_lwsp(&parser) == 0 && str_len(str) > 0) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
327 data->content_transfer_encoding =
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
328 p_strdup(pool, str_c(str));
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
329 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
330 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
331
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
332 static void
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
333 parse_content_disposition(struct message_part_data *data,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
334 pool_t pool, struct message_header_line *hdr)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
335 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
336 struct rfc822_parser_context parser;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
337 string_t *str;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
338
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
339 rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
340 rfc822_skip_lwsp(&parser);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
341
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
342 str = t_str_new(256);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
343 if (rfc822_parse_mime_token(&parser, str) < 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
344 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
345 data->content_disposition = p_strdup(pool, str_c(str));
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
346
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
347 parse_mime_parameters(&parser, pool,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
348 &data->content_disposition_params,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
349 &data->content_disposition_params_count);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
350 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
351
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
352 static void
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
353 parse_content_language(struct message_part_data *data,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
354 pool_t pool, const unsigned char *value, size_t value_len)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
355 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
356 struct rfc822_parser_context parser;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
357 ARRAY_TYPE(const_string) langs;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
358 string_t *str;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
359
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
360 /* Language-Header = "Content-Language" ":" 1#Language-tag
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
361 Language-Tag = Primary-tag *( "-" Subtag )
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
362 Primary-tag = 1*8ALPHA
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
363 Subtag = 1*8ALPHA */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
364
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
365 rfc822_parser_init(&parser, value, value_len, NULL);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
366
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
367 t_array_init(&langs, 16);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
368 str = t_str_new(128);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
369
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
370 rfc822_skip_lwsp(&parser);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
371 while (rfc822_parse_atom(&parser, str) >= 0) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
372 const char *lang = p_strdup(pool, str_c(str));
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
373
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
374 array_append(&langs, &lang, 1);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
375 str_truncate(str, 0);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
376
22884
77577228fd8f lib-mail: Make sure parsers don't accidentally go much beyond end pointer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22780
diff changeset
377 if (parser.data >= parser.end || *parser.data != ',')
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
378 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
379 parser.data++;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
380 rfc822_skip_lwsp(&parser);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
381 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
382
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
383 if (array_count(&langs) > 0) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
384 array_append_zero(&langs);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
385 data->content_language =
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
386 p_strarray_dup(pool, array_idx(&langs, 0));
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
387 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
388 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
389
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
390 static void
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
391 parse_content_header(struct message_part_data *data,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
392 pool_t pool, struct message_header_line *hdr)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
393 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
394 const char *name = hdr->name + strlen("Content-");
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
395 const char *value;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
396
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
397 if (hdr->continues) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
398 hdr->use_full_value = TRUE;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
399 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
400 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
401
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
402 value = t_strndup(hdr->full_value, hdr->full_value_len);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
403
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
404 switch (*name) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
405 case 'i':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
406 case 'I':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
407 if (strcasecmp(name, "ID") == 0 && data->content_id == NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
408 data->content_id = p_strdup(pool, value);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
409 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
410
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
411 case 'm':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
412 case 'M':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
413 if (strcasecmp(name, "MD5") == 0 && data->content_md5 == NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
414 data->content_md5 = p_strdup(pool, value);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
415 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
416
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
417 case 't':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
418 case 'T':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
419 if (strcasecmp(name, "Type") == 0 && data->content_type == NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
420 parse_content_type(data, pool, hdr);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
421 else if (strcasecmp(name, "Transfer-Encoding") == 0 &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
422 data->content_transfer_encoding == NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
423 parse_content_transfer_encoding(data, pool, hdr);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
424 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
425
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
426 case 'l':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
427 case 'L':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
428 if (strcasecmp(name, "Language") == 0 &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
429 data->content_language == NULL) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
430 parse_content_language(data, pool,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
431 hdr->full_value, hdr->full_value_len);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
432 } else if (strcasecmp(name, "Location") == 0 &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
433 data->content_location == NULL) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
434 data->content_location = p_strdup(pool, value);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
435 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
436 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
437
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
438 case 'd':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
439 case 'D':
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
440 if (strcasecmp(name, "Description") == 0 &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
441 data->content_description == NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
442 data->content_description = p_strdup(pool, value);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
443 else if (strcasecmp(name, "Disposition") == 0 &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
444 data->content_disposition_params == NULL)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
445 parse_content_disposition(data, pool, hdr);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
446 break;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
447 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
448 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
449
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
450 void message_part_data_parse_from_header(pool_t pool,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
451 struct message_part *part,
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
452 struct message_header_line *hdr)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
453 {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
454 struct message_part_data *part_data;
21635
30aacb0df12f lib-mail: message-part-data: Renamed struct message_part_envelope_data to message_part_envelope.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21634
diff changeset
455 struct message_part_envelope *envelope;
21633
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
456 bool parent_rfc822;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
457
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
458 if (hdr == NULL) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
459 if (part->data == NULL) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
460 /* no Content-* headers. add an empty context
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
461 structure anyway. */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
462 part->data = part_data =
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
463 p_new(pool, struct message_part_data, 1);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
464 } else if ((part->flags & MESSAGE_PART_FLAG_IS_MIME) == 0) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
465 /* If there was no Mime-Version, forget all
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
466 the Content-stuff */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
467 part_data = part->data;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
468 envelope = part_data->envelope;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
469
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
470 i_zero(part_data);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
471 part_data->envelope = envelope;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
472 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
473 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
474 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
475
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
476 if (hdr->eoh)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
477 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
478
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
479 parent_rfc822 = part->parent != NULL &&
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
480 (part->parent->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
481 if (!parent_rfc822 && strncasecmp(hdr->name, "Content-", 8) != 0)
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
482 return;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
483
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
484 if (part->data == NULL) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
485 /* initialize message part data */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
486 part->data = part_data =
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
487 p_new(pool, struct message_part_data, 1);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
488 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
489 part_data = part->data;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
490
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
491 if (strncasecmp(hdr->name, "Content-", 8) == 0) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
492 T_BEGIN {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
493 parse_content_header(part_data, pool, hdr);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
494 } T_END;
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
495 }
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
496
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
497 if (parent_rfc822) {
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
498 /* message/rfc822, we need the envelope */
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
499 message_part_envelope_parse_from_header(pool, &part_data->envelope, hdr);
3a88d30ad000 lib-imap: imap-bodystructure: Moved message_part_data header parsing and query functions to their own module in lib-mail.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
diff changeset
500 }
21915
6ba293f64b49 global: Make sure all files end with newline
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21673
diff changeset
501 }
22780
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
502
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
503 bool message_part_has_content_types(struct message_part *part,
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
504 const char *const *types)
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
505 {
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
506 struct message_part_data *data = part->data;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
507 bool ret = TRUE;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
508 const char *const *ptr;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
509 const char *content_type;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
510
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
511 if (data->content_type == NULL)
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
512 return FALSE;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
513 else if (data->content_subtype == NULL)
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
514 content_type = t_strdup_printf("%s/", data->content_type);
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
515 else
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
516 content_type = t_strdup_printf("%s/%s", data->content_type,
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
517 data->content_subtype);
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
518 for(ptr = types; *ptr != NULL; ptr++) {
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
519 bool exclude = (**ptr == '!');
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
520 if (wildcard_match_icase(content_type, (*ptr)+(exclude?1:0)))
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
521 ret = !exclude;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
522 }
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
523
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
524 return ret;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
525 }
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
526
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
527 bool message_part_has_parameter(struct message_part *part, const char *parameter,
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
528 bool has_value)
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
529 {
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
530 struct message_part_data *data = part->data;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
531
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
532 for (unsigned int i = 0; i < data->content_disposition_params_count; i++) {
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
533 const struct message_part_param *param =
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
534 &data->content_disposition_params[i];
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
535 if (strcasecmp(param->name, parameter) == 0 &&
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
536 (!has_value || *param->value != '\0')) {
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
537 return TRUE;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
538 }
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
539 }
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
540 return FALSE;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
541 }
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
542
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
543 bool message_part_is_attachment(struct message_part *part,
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
544 const struct message_part_attachment_settings *set)
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
545 {
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
546 struct message_part_data *data = part->data;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
547
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
548 i_assert(data != NULL);
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
549
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
550 /* see if the content-type is excluded */
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
551 if (set->content_type_filter != NULL &&
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
552 !message_part_has_content_types(part, set->content_type_filter))
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
553 return FALSE;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
554
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
555 /* accept any attachment, or any inlined attachment with filename,
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
556 unless inlined ones are excluded */
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
557 if (null_strcasecmp(data->content_disposition, "attachment") == 0 ||
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
558 (!set->exclude_inlined &&
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
559 null_strcasecmp(data->content_disposition, "inline") == 0 &&
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
560 message_part_has_parameter(part, "filename", FALSE)))
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
561 return TRUE;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
562 return FALSE;
a982d52a740b lib-mail: Add message_part_has_attachment
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22713
diff changeset
563 }