Commit 8e227e9b 8e227e9b65a9e74450a81d200a99d5539f0ab93f by Sergey Poznyakoff

imap4d: fetch body with a nonempty section spec returns section body without headers.

* imap4d/fetch.c (fetch_function_closure) <section_tag>: New member.
(_frt_body_text): Output ffc->section_tag after the secion part by
default.
(_frt_header, _frt_mime): Remove.
(_frt_header0): Rewrite as a general-purpose _frt_header function.
(parse_section_text): Set _frt_header as a driver function and
set section_tag accordingly, instead of selecting _frt_header/_frt_mime.
Set section_tag when selecting _frt_body_text.
(parse_section): Default to _frt_body_text and fall back to _frt_body
only when an empty section specifier is given.
* imap4d/testsuite/imap4d/fetch.exp: Update accordingly.
1 parent 1cb4b8d7
...@@ -49,6 +49,7 @@ struct fetch_function_closure ...@@ -49,6 +49,7 @@ struct fetch_function_closure
49 { 49 {
50 fetch_function_t fun; /* Handler function */ 50 fetch_function_t fun; /* Handler function */
51 const char *name; /* Response tag */ 51 const char *name; /* Response tag */
52 const char *section_tag;
52 size_t *section_part; /* Section-part */ 53 size_t *section_part; /* Section-part */
53 size_t nset; /* Number of elements in section_part */ 54 size_t nset; /* Number of elements in section_part */
54 int peek; 55 int peek;
...@@ -906,7 +907,7 @@ _frt_body_text (struct fetch_function_closure *ffc, ...@@ -906,7 +907,7 @@ _frt_body_text (struct fetch_function_closure *ffc,
906 if (ffc->name) 907 if (ffc->name)
907 util_send ("%s", ffc->name); 908 util_send ("%s", ffc->name);
908 else 909 else
909 fetch_send_section_part (ffc, "TEXT", 1); 910 fetch_send_section_part (ffc, ffc->section_tag, 1);
910 msg = fetch_get_part (ffc, frt); 911 msg = fetch_get_part (ffc, frt);
911 if (!msg) 912 if (!msg)
912 { 913 {
...@@ -935,9 +936,8 @@ _frt_size (struct fetch_function_closure *ffc, ...@@ -935,9 +936,8 @@ _frt_size (struct fetch_function_closure *ffc,
935 } 936 }
936 937
937 static int 938 static int
938 _frt_header0 (struct fetch_function_closure *ffc, 939 _frt_header (struct fetch_function_closure *ffc,
939 struct fetch_runtime_closure *frt, 940 struct fetch_runtime_closure *frt)
940 const char *suffix)
941 { 941 {
942 mu_message_t msg; 942 mu_message_t msg;
943 mu_header_t header = NULL; 943 mu_header_t header = NULL;
...@@ -948,7 +948,7 @@ _frt_header0 (struct fetch_function_closure *ffc, ...@@ -948,7 +948,7 @@ _frt_header0 (struct fetch_function_closure *ffc,
948 if (ffc->name) 948 if (ffc->name)
949 util_send ("%s", ffc->name); 949 util_send ("%s", ffc->name);
950 else 950 else
951 fetch_send_section_part (ffc, suffix, 1); 951 fetch_send_section_part (ffc, ffc->section_tag, 1);
952 952
953 msg = fetch_get_part (ffc, frt); 953 msg = fetch_get_part (ffc, frt);
954 if (!msg) 954 if (!msg)
...@@ -964,20 +964,6 @@ _frt_header0 (struct fetch_function_closure *ffc, ...@@ -964,20 +964,6 @@ _frt_header0 (struct fetch_function_closure *ffc,
964 } 964 }
965 965
966 static int 966 static int
967 _frt_header (struct fetch_function_closure *ffc,
968 struct fetch_runtime_closure *frt)
969 {
970 return _frt_header0 (ffc, frt, "HEADER");
971 }
972
973 static int
974 _frt_mime (struct fetch_function_closure *ffc,
975 struct fetch_runtime_closure *frt)
976 {
977 return _frt_header0 (ffc, frt, "MIME");
978 }
979
980 static int
981 _send_header_name (void *item, void *data) 967 _send_header_name (void *item, void *data)
982 { 968 {
983 int *pf = data; 969 int *pf = data;
...@@ -1291,17 +1277,22 @@ parse_section_text (imap4d_parsebuf_t p, struct fetch_function_closure *ffc, ...@@ -1291,17 +1277,22 @@ parse_section_text (imap4d_parsebuf_t p, struct fetch_function_closure *ffc,
1291 parse_header_list (p, ffc); 1277 parse_header_list (p, ffc);
1292 } 1278 }
1293 else 1279 else
1280 {
1294 ffc->fun = _frt_header; 1281 ffc->fun = _frt_header;
1282 ffc->section_tag = "HEADER";
1283 }
1295 } 1284 }
1296 else if (mu_c_strcasecmp (p->token, "TEXT") == 0) 1285 else if (mu_c_strcasecmp (p->token, "TEXT") == 0)
1297 { 1286 {
1298 imap4d_parsebuf_next (p, 1); 1287 imap4d_parsebuf_next (p, 1);
1299 ffc->fun = _frt_body_text; 1288 ffc->fun = _frt_body_text;
1289 ffc->section_tag = "TEXT";
1300 } 1290 }
1301 else if (allow_mime && mu_c_strcasecmp (p->token, "MIME") == 0) 1291 else if (allow_mime && mu_c_strcasecmp (p->token, "MIME") == 0)
1302 { 1292 {
1303 imap4d_parsebuf_next (p, 1); 1293 imap4d_parsebuf_next (p, 1);
1304 ffc->fun = _frt_mime; 1294 ffc->fun = _frt_header;
1295 ffc->section_tag = "MIME";
1305 } 1296 }
1306 else 1297 else
1307 return 1; 1298 return 1;
...@@ -1375,12 +1366,12 @@ parse_section (imap4d_parsebuf_t p, struct fetch_function_closure *ffc) ...@@ -1375,12 +1366,12 @@ parse_section (imap4d_parsebuf_t p, struct fetch_function_closure *ffc)
1375 return 1; 1366 return 1;
1376 ffc_init (ffc); 1367 ffc_init (ffc);
1377 ffc->name = NULL; 1368 ffc->name = NULL;
1378 ffc->fun = _frt_body; 1369 ffc->fun = _frt_body_text;
1379 imap4d_parsebuf_next (p, 1); 1370 imap4d_parsebuf_next (p, 1);
1380 if (parse_section_text (p, ffc, 0)) 1371 if (parse_section_text (p, ffc, 0))
1381 { 1372 {
1382 if (p->token[0] == ']') 1373 if (p->token[0] == ']')
1383 /* OK */; 1374 ffc->fun = _frt_body;
1384 else if (mu_isdigit (p->token[0])) 1375 else if (mu_isdigit (p->token[0]))
1385 { 1376 {
1386 parse_section_part (p, ffc); 1377 parse_section_part (p, ffc);
......
...@@ -330,13 +330,8 @@ imap4d_test "FETCH 3 BODY\[1.MIME\]"\ ...@@ -330,13 +330,8 @@ imap4d_test "FETCH 3 BODY\[1.MIME\]"\
330 "OK" 330 "OK"
331 331
332 imap4d_test "FETCH 4 BODY\[2.2.1\]"\ 332 imap4d_test "FETCH 4 BODY\[2.2.1\]"\
333 "4 FETCH (FLAGS (\\Seen) BODY\[2.2.1\] {680}"\ 333 "4 FETCH (FLAGS (\\Seen) BODY\[2.2.1\] {490}"\
334 -literal\ 334 -literal\
335 "Content-Type: application/octet-stream; name=\"msg.23\""\
336 "Content-ID: <5122.1026510654.6@Mirddin.farlep.net>"\
337 "Content-Description: Father William Part III"\
338 "Content-Transfer-Encoding: base64"\
339 ""\
340 "YFlvdSBhcmUgb2xkLCcgc2FpZCB0aGUgeW91dGgsIGBhbmQgeW91ciBqYXdzIGFyZSB0b28gd2Vh"\ 335 "YFlvdSBhcmUgb2xkLCcgc2FpZCB0aGUgeW91dGgsIGBhbmQgeW91ciBqYXdzIGFyZSB0b28gd2Vh"\
341 "awpGb3IgYW55dGhpbmcgdG91Z2hlciB0aGFuIHN1ZXQ7CllldCB5b3UgZmluaXNoZWQgdGhlIGdv"\ 336 "awpGb3IgYW55dGhpbmcgdG91Z2hlciB0aGFuIHN1ZXQ7CllldCB5b3UgZmluaXNoZWQgdGhlIGdv"\
342 "b3NlLCB3aXRoIHRoZSBib25lcyBhbmQgdGhlIGJlYWstLQpQcmF5IGhvdyBkaWQgeW91IG1hbmFn"\ 337 "b3NlLCB3aXRoIHRoZSBib25lcyBhbmQgdGhlIGJlYWstLQpQcmF5IGhvdyBkaWQgeW91IG1hbmFn"\
......