imap4d/fetch.c : implement fetch [HEADER.FIELD]
Showing
1 changed file
with
62 additions
and
4 deletions
... | @@ -470,7 +470,9 @@ static int | ... | @@ -470,7 +470,9 @@ static int |
470 | fetch_body (struct imap4d_command *command, char *arg) | 470 | fetch_body (struct imap4d_command *command, char *arg) |
471 | { | 471 | { |
472 | struct imap4d_command c_body_p = fetch_command_table[F_BODY_PEEK]; | 472 | struct imap4d_command c_body_p = fetch_command_table[F_BODY_PEEK]; |
473 | |||
473 | util_send ("%s ", command->name); | 474 | util_send ("%s ", command->name); |
475 | |||
474 | if (strncasecmp (arg, ".PEEK", 5) == 0) | 476 | if (strncasecmp (arg, ".PEEK", 5) == 0) |
475 | { | 477 | { |
476 | arg += strlen (".PEEK"); | 478 | arg += strlen (".PEEK"); |
... | @@ -493,6 +495,7 @@ fetch_body (struct imap4d_command *command, char *arg) | ... | @@ -493,6 +495,7 @@ fetch_body (struct imap4d_command *command, char *arg) |
493 | return 0; | 495 | return 0; |
494 | } | 496 | } |
495 | 497 | ||
498 | util_send ("%s", arg); | ||
496 | fetch_operation (command->states, arg); | 499 | fetch_operation (command->states, arg); |
497 | return 0; | 500 | return 0; |
498 | } | 501 | } |
... | @@ -500,8 +503,25 @@ fetch_body (struct imap4d_command *command, char *arg) | ... | @@ -500,8 +503,25 @@ fetch_body (struct imap4d_command *command, char *arg) |
500 | static int | 503 | static int |
501 | fetch_operation (size_t msgno, char *arg) | 504 | fetch_operation (size_t msgno, char *arg) |
502 | { | 505 | { |
503 | //char *partial = strchr (arg, '<'); | 506 | off_t offset = 0; |
507 | size_t limit = -1; /* No limit. */ | ||
504 | message_t msg = NULL; | 508 | message_t msg = NULL; |
509 | char *partial = strchr (arg, '<'); | ||
510 | |||
511 | /* Check for section specific offset. */ | ||
512 | if (partial) | ||
513 | { | ||
514 | /* FIXME: This shoud be move in imap4d_fetch() and have more | ||
515 | draconian check. */ | ||
516 | partial++; | ||
517 | offset = strtoul (partial, &partial, 10); | ||
518 | if (*partial == '.') | ||
519 | { | ||
520 | partial++; | ||
521 | limit = strtoul (partial, NULL, 10); | ||
522 | } | ||
523 | } | ||
524 | |||
505 | mailbox_get_message (mbox, msgno, &msg); | 525 | mailbox_get_message (mbox, msgno, &msg); |
506 | 526 | ||
507 | if (strncasecmp (arg, "[]", 2) == 0) | 527 | if (strncasecmp (arg, "[]", 2) == 0) |
... | @@ -524,7 +544,8 @@ fetch_operation (size_t msgno, char *arg) | ... | @@ -524,7 +544,8 @@ fetch_operation (size_t msgno, char *arg) |
524 | off += n; | 544 | off += n; |
525 | } | 545 | } |
526 | } | 546 | } |
527 | else if (strncasecmp (arg, "[HEADER]", 8) == 0) | 547 | else if (strncasecmp (arg, "[HEADER]", 8) == 0 |
548 | || strncasecmp (arg, "[MIME]", 6) == 0) | ||
528 | { | 549 | { |
529 | header_t header = NULL; | 550 | header_t header = NULL; |
530 | stream_t stream = NULL; | 551 | stream_t stream = NULL; |
... | @@ -550,9 +571,46 @@ fetch_operation (size_t msgno, char *arg) | ... | @@ -550,9 +571,46 @@ fetch_operation (size_t msgno, char *arg) |
550 | { | 571 | { |
551 | /* Not implemented. */ | 572 | /* Not implemented. */ |
552 | } | 573 | } |
553 | else if (strncasecmp (arg, "[HEADER.FIELDS", 15) == 0) | 574 | else if (strncasecmp (arg, "[HEADER.FIELDS", 14) == 0) |
554 | { | 575 | { |
555 | /* Not implemented. */ | 576 | char *field; |
577 | char *sp = NULL; | ||
578 | header_t header = NULL; | ||
579 | size_t val_len = 0; | ||
580 | size_t total = 0; | ||
581 | char *buffer = NULL; | ||
582 | |||
583 | arg += 14; | ||
584 | message_get_header (msg, &header); | ||
585 | |||
586 | for (; field = strtok_r (arg, " ()]\r\n", &sp); arg = NULL, val_len = 0) | ||
587 | { | ||
588 | size_t ototal; | ||
589 | char *value = NULL; | ||
590 | |||
591 | header_get_value (header, field, NULL, 0, &val_len); | ||
592 | if (val_len == 0) | ||
593 | continue; | ||
594 | value = malloc (val_len + 1); | ||
595 | if (!value) | ||
596 | util_quit (1); /* FIXME: ENOMEM, send a "* BYE" to the client. */ | ||
597 | header_get_value (header, field, value, val_len + 1, NULL); | ||
598 | |||
599 | ototal = strlen (field) + val_len + 4; /* 4 for ": \r\n" */ | ||
600 | buffer = realloc (buffer, ototal + total + 1); | ||
601 | if (!buffer) | ||
602 | util_quit (1); /* FIXME: ENOMEM, send a "* BYE" to the client. */ | ||
603 | snprintf (buffer + total, ototal + 1, "%s: %s\r\n", field, value); | ||
604 | free (value); | ||
605 | total += ototal; | ||
606 | } | ||
607 | |||
608 | util_send ("{%u}\r\n", total + 2); | ||
609 | if (total) | ||
610 | util_send ("%s", buffer); | ||
611 | util_send ("\r\n"); | ||
612 | if (buffer) | ||
613 | free (buffer); | ||
556 | } | 614 | } |
557 | else if (strncasecmp (arg, "[TEXT]", 6) == 0) | 615 | else if (strncasecmp (arg, "[TEXT]", 6) == 0) |
558 | { | 616 | { | ... | ... |
-
Please register or sign in to post a comment