annotate src/lib-imap/imap-envelope.c @ 21627:6ced094b1759

lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data. Contained unparsed IMAP string data before.
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Sun, 23 Oct 2016 16:50:25 +0200
parents 591338b088aa
children e630e1ba2e17
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21390
2e2563132d5f Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 19552
diff changeset
1 /* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 591
diff changeset
4 #include "istream.h"
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
5 #include "str.h"
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
6 #include "message-address.h"
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
7 #include "message-parser.h"
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 339
diff changeset
8 #include "imap-parser.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "imap-envelope.h"
339
6f4eeb6a0a0d Several fields in BODY were unquoted.
Timo Sirainen <tss@iki.fi>
parents: 264
diff changeset
10 #include "imap-quote.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
12 struct message_part_envelope_data {
4818
24f60fa451f2 const fixes
Timo Sirainen <tss@iki.fi>
parents: 4635
diff changeset
13 const char *date, *subject;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
14 struct message_address *from, *sender, *reply_to;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
15 struct message_address *to, *cc, *bcc;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
4818
24f60fa451f2 const fixes
Timo Sirainen <tss@iki.fi>
parents: 4635
diff changeset
17 const char *in_reply_to, *message_id;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 };
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1663
diff changeset
20 const char *imap_envelope_headers[] = {
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1663
diff changeset
21 "Date", "Subject", "From", "Sender", "Reply-To",
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1663
diff changeset
22 "To", "Cc", "Bcc", "In-Reply-To", "Message-ID",
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1663
diff changeset
23 NULL
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1663
diff changeset
24 };
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1663
diff changeset
25
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3039
diff changeset
26 bool imap_envelope_get_field(const char *name, enum imap_envelope_field *ret)
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
27 {
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
28 *ret = (enum imap_envelope_field)-1;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
29
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
30 switch (*name) {
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
31 case 'B':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
32 case 'b':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
33 if (strcasecmp(name, "Bcc") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
34 *ret = IMAP_ENVELOPE_BCC;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
35 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
36 case 'C':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
37 case 'c':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
38 if (strcasecmp(name, "Cc") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
39 *ret = IMAP_ENVELOPE_CC;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
40 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
41 case 'D':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
42 case 'd':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
43 if (strcasecmp(name, "Date") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
44 *ret = IMAP_ENVELOPE_DATE;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
45 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
46 case 'F':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
47 case 'f':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
48 if (strcasecmp(name, "From") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
49 *ret = IMAP_ENVELOPE_FROM;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
50 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
51 case 'I':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
52 case 'i':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
53 if (strcasecmp(name, "In-reply-to") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
54 *ret = IMAP_ENVELOPE_IN_REPLY_TO;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
55 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
56 case 'M':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
57 case 'm':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
58 if (strcasecmp(name, "Message-id") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
59 *ret = IMAP_ENVELOPE_MESSAGE_ID;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
60 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
61 case 'R':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
62 case 'r':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
63 if (strcasecmp(name, "Reply-to") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
64 *ret = IMAP_ENVELOPE_REPLY_TO;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
65 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
66 case 'S':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
67 case 's':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
68 if (strcasecmp(name, "Subject") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
69 *ret = IMAP_ENVELOPE_SUBJECT;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
70 if (strcasecmp(name, "Sender") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
71 *ret = IMAP_ENVELOPE_SENDER;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
72 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
73 case 'T':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
74 case 't':
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
75 if (strcasecmp(name, "To") == 0)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
76 *ret = IMAP_ENVELOPE_TO;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
77 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
78 }
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
79
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
80 return *ret != (enum imap_envelope_field)-1;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
81 }
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
82
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
83 void imap_envelope_parse_header(pool_t pool,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
84 struct message_part_envelope_data **data,
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
85 struct message_header_line *hdr)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
87 struct message_part_envelope_data *d;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
88 enum imap_envelope_field field;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
89 struct message_address **addr_p;
4818
24f60fa451f2 const fixes
Timo Sirainen <tss@iki.fi>
parents: 4635
diff changeset
90 const char **str_p;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
91
1342
f1dc24e5bc0f Don't crash if mail doesn't have any headers.
Timo Sirainen <tss@iki.fi>
parents: 1322
diff changeset
92 if (*data == NULL) {
f1dc24e5bc0f Don't crash if mail doesn't have any headers.
Timo Sirainen <tss@iki.fi>
parents: 1322
diff changeset
93 *data = p_new(pool, struct message_part_envelope_data, 1);
f1dc24e5bc0f Don't crash if mail doesn't have any headers.
Timo Sirainen <tss@iki.fi>
parents: 1322
diff changeset
94 }
f1dc24e5bc0f Don't crash if mail doesn't have any headers.
Timo Sirainen <tss@iki.fi>
parents: 1322
diff changeset
95
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
96 if (hdr == NULL || !imap_envelope_get_field(hdr->name, &field))
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
97 return;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
98
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
99 if (hdr->continues) {
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
100 /* wait for full value */
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
101 hdr->use_full_value = TRUE;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
102 return;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
103 }
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
104
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
105 d = *data;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
106 addr_p = NULL; str_p = NULL;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
107 switch (field) {
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
108 case IMAP_ENVELOPE_DATE:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
109 str_p = &d->date;
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
110 break;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
111 case IMAP_ENVELOPE_SUBJECT:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
112 str_p = &d->subject;
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
113 break;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
114 case IMAP_ENVELOPE_MESSAGE_ID:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
115 str_p = &d->message_id;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
116 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
117 case IMAP_ENVELOPE_IN_REPLY_TO:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
118 str_p = &d->in_reply_to;
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
119 break;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
120
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
121 case IMAP_ENVELOPE_CC:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
122 addr_p = &d->cc;
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
123 break;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
124 case IMAP_ENVELOPE_BCC:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
125 addr_p = &d->bcc;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
126 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
127 case IMAP_ENVELOPE_FROM:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
128 addr_p = &d->from;
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
129 break;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
130 case IMAP_ENVELOPE_SENDER:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
131 addr_p = &d->sender;
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
132 break;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
133 case IMAP_ENVELOPE_TO:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
134 addr_p = &d->to;
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
135 break;
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
136 case IMAP_ENVELOPE_REPLY_TO:
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
137 addr_p = &d->reply_to;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
138 break;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
139 case IMAP_ENVELOPE_FIELDS:
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
140 break;
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
141 }
805
5ac361acb316 Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
142
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
143 if (addr_p != NULL) {
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1321
diff changeset
144 *addr_p = message_address_parse(pool, hdr->full_value,
3039
d6910d273852 Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
145 hdr->full_value_len,
15904
d3cf06639864 Replaced all -1U and (unsigned int)-1 with UINT_MAX.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
146 UINT_MAX, TRUE);
21627
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
147 } else if (str_p != NULL) {
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
148 *str_p = p_strndup(pool,
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
149 hdr->full_value, hdr->full_value_len);
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
150 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
153 static void imap_write_address(string_t *str, struct message_address *addr)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 if (addr == NULL) {
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
156 str_append(str, "NIL");
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
160 str_append_c(str, '(');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 while (addr != NULL) {
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
162 str_append_c(str, '(');
15250
b89dae6aead4 lib-imap: Replaced last traces of imap_quote*() with imap_append_string_for_humans()
Timo Sirainen <tss@iki.fi>
parents: 15249
diff changeset
163 if (addr->name == NULL)
b89dae6aead4 lib-imap: Replaced last traces of imap_quote*() with imap_append_string_for_humans()
Timo Sirainen <tss@iki.fi>
parents: 15249
diff changeset
164 str_append(str, "NIL");
b89dae6aead4 lib-imap: Replaced last traces of imap_quote*() with imap_append_string_for_humans()
Timo Sirainen <tss@iki.fi>
parents: 15249
diff changeset
165 else {
b89dae6aead4 lib-imap: Replaced last traces of imap_quote*() with imap_append_string_for_humans()
Timo Sirainen <tss@iki.fi>
parents: 15249
diff changeset
166 imap_append_string_for_humans(str,
b89dae6aead4 lib-imap: Replaced last traces of imap_quote*() with imap_append_string_for_humans()
Timo Sirainen <tss@iki.fi>
parents: 15249
diff changeset
167 (const void *)addr->name, strlen(addr->name));
b89dae6aead4 lib-imap: Replaced last traces of imap_quote*() with imap_append_string_for_humans()
Timo Sirainen <tss@iki.fi>
parents: 15249
diff changeset
168 }
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
169 str_append_c(str, ' ');
15249
c849ae6603f2 lib-imap: ENVELOPE parsing/writing no longer strips whitespace from machine readable fields.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
170 imap_append_nstring(str, addr->route);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
171 str_append_c(str, ' ');
15249
c849ae6603f2 lib-imap: ENVELOPE parsing/writing no longer strips whitespace from machine readable fields.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
172 imap_append_nstring(str, addr->mailbox);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
173 str_append_c(str, ' ');
15249
c849ae6603f2 lib-imap: ENVELOPE parsing/writing no longer strips whitespace from machine readable fields.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
174 imap_append_nstring(str, addr->domain);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
175 str_append_c(str, ')');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 addr = addr->next;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 }
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
179 str_append_c(str, ')');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
182 void imap_envelope_write_part_data(struct message_part_envelope_data *data,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
183 string_t *str)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 {
12523
25958384d938 Moved a global NVL() macro to the few places in lib-imap where it was actually used.
Timo Sirainen <tss@iki.fi>
parents: 11063
diff changeset
185 #define NVL(str, nullstr) ((str) != NULL ? (str) : (nullstr))
1663
4aca99baa9a4 Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
186 static const char *empty_envelope =
4aca99baa9a4 Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
187 "NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL";
4aca99baa9a4 Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
188
4aca99baa9a4 Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
189 if (data == NULL) {
4aca99baa9a4 Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
190 str_append(str, empty_envelope);
4aca99baa9a4 Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
191 return;
4aca99baa9a4 Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
192 }
4aca99baa9a4 Don't write envelope as NIL into bodystructure even if it's broken.
Timo Sirainen <tss@iki.fi>
parents: 1591
diff changeset
193
21627
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
194 imap_append_nstring(str, data->date);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
195 str_append_c(str, ' ');
21627
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
196 if (data->subject == NULL)
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
197 str_append(str, "NIL");
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
198 else {
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
199 imap_append_string_for_humans(str,
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
200 (const unsigned char *)data->subject,
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
201 strlen(data->subject));
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
202 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
204 str_append_c(str, ' ');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 imap_write_address(str, data->from);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
206 str_append_c(str, ' ');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 imap_write_address(str, NVL(data->sender, data->from));
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
208 str_append_c(str, ' ');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209 imap_write_address(str, NVL(data->reply_to, data->from));
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
210 str_append_c(str, ' ');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
211 imap_write_address(str, data->to);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
212 str_append_c(str, ' ');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 imap_write_address(str, data->cc);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
214 str_append_c(str, ' ');
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 imap_write_address(str, data->bcc);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
217 str_append_c(str, ' ');
21627
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
218 imap_append_nstring(str, data->in_reply_to);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents: 805
diff changeset
219 str_append_c(str, ' ');
21627
6ced094b1759 lib-imap: imap-bodystructure: Changed struct message_part_body to contain fully decoded data.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21626
diff changeset
220 imap_append_nstring(str, data->message_id);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221 }
21626
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
222
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
223 static bool
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
224 imap_envelope_parse_address(const struct imap_arg *arg,
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
225 pool_t pool, struct message_address **addr_r)
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
226 {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
227 struct message_address *addr;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
228 const struct imap_arg *list_args;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
229 const char *name, *route, *mailbox, *domain;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
230 unsigned int list_count;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
231
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
232 if (!imap_arg_get_list_full(arg, &list_args, &list_count))
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
233 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
234
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
235 /* we require 4 arguments, strings or NILs */
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
236 if (list_count < 4)
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
237 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
238
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
239 if (!imap_arg_get_nstring(&list_args[0], &name))
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
240 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
241 if (!imap_arg_get_nstring(&list_args[1], &route))
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
242 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
243 if (!imap_arg_get_nstring(&list_args[2], &mailbox))
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
244 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
245 if (!imap_arg_get_nstring(&list_args[3], &domain))
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
246 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
247
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
248 addr = p_new(pool, struct message_address, 1);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
249 addr->name = p_strdup(pool, name);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
250 addr->route = p_strdup(pool, route);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
251 addr->mailbox = p_strdup(pool, mailbox);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
252 addr->domain = p_strdup(pool, domain);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
253
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
254 *addr_r = addr;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
255 return TRUE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
256 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
257
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
258 static bool
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
259 imap_envelope_parse_addresses(const struct imap_arg *arg,
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
260 pool_t pool, struct message_address **addrs_r)
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
261 {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
262 struct message_address *first, *addr, *prev;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
263 const struct imap_arg *list_args;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
264
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
265 if (arg->type == IMAP_ARG_NIL) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
266 *addrs_r = NULL;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
267 return TRUE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
268 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
269
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
270 if (!imap_arg_get_list(arg, &list_args))
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
271 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
272
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
273 first = addr = prev = NULL;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
274 for (; !IMAP_ARG_IS_EOL(list_args); list_args++) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
275 if (!imap_envelope_parse_address
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
276 (list_args, pool, &addr))
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
277 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
278 if (first == NULL)
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
279 first = addr;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
280 if (prev != NULL)
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
281 prev->next = addr;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
282 prev = addr;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
283 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
284
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
285 *addrs_r = first;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
286 return TRUE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
287 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
288
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
289 bool imap_envelope_parse_args(const struct imap_arg *args,
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
290 pool_t pool, struct message_part_envelope_data **envlp_r,
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
291 const char **error_r)
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
292 {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
293 struct message_part_envelope_data *envlp;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
294
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
295 envlp = p_new(pool, struct message_part_envelope_data, 1);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
296
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
297 if (!imap_arg_get_nstring(args++, &envlp->date)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
298 *error_r = "Invalid date field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
299 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
300 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
301 envlp->date = p_strdup(pool, envlp->date);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
302
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
303 if (!imap_arg_get_nstring(args++, &envlp->subject)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
304 *error_r = "Invalid subject field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
305 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
306 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
307 envlp->subject = p_strdup(pool, envlp->subject);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
308
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
309 if (!imap_envelope_parse_addresses(args++, pool, &envlp->from)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
310 *error_r = "Invalid from field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
311 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
312 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
313 if (!imap_envelope_parse_addresses(args++, pool, &envlp->sender)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
314 *error_r = "Invalid sender field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
315 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
316 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
317 if (!imap_envelope_parse_addresses(args++, pool, &envlp->reply_to)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
318 *error_r = "Invalid reply_to field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
319 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
320 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
321 if (!imap_envelope_parse_addresses(args++, pool, &envlp->to)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
322 *error_r = "Invalid to field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
323 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
324 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
325 if (!imap_envelope_parse_addresses(args++, pool, &envlp->cc)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
326 *error_r = "Invalid cc field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
327 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
328 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
329 if (!imap_envelope_parse_addresses(args++, pool, &envlp->bcc)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
330 *error_r = "Invalid bcc field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
331 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
332 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
333
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
334 if (!imap_arg_get_nstring(args++, &envlp->in_reply_to)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
335 *error_r = "Invalid in_reply_to field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
336 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
337 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
338 envlp->in_reply_to = p_strdup(pool, envlp->in_reply_to);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
339
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
340 if (!imap_arg_get_nstring(args++, &envlp->message_id)) {
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
341 *error_r = "Invalid message_id field";
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
342 return FALSE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
343 }
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
344 envlp->message_id = p_strdup(pool, envlp->message_id);
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
345
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
346 *envlp_r = envlp;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
347 return TRUE;
591338b088aa lib-imap: imap-envelope: Added function to parse struct message_part_envelope_data from parsed imap args.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21624
diff changeset
348 }