| 681 | } |
| 682 | |
| 683 | static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb, |
| 684 | char *s) |
| 685 | { |
| 686 | struct imap *imap = ctx->imap; |
| 687 | char *arg, *p; |
| 688 | |
| 689 | if (!s || *s != '[') |
| 690 | return RESP_OK; /* no response code */ |
| 691 | s++; |
| 692 | if (!(p = strchr(s, ']'))) { |
| 693 | fprintf(stderr, "IMAP error: malformed response code\n"); |
| 694 | return RESP_BAD; |
| 695 | } |
| 696 | *p++ = 0; |
| 697 | arg = next_arg(&s); |
| 698 | if (!arg) { |
| 699 | fprintf(stderr, "IMAP error: empty response code\n"); |
| 700 | return RESP_BAD; |
| 701 | } |
| 702 | if (!strcmp("UIDVALIDITY", arg)) { |
| 703 | if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity) { |
| 704 | fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n"); |
| 705 | return RESP_BAD; |
| 706 | } |
| 707 | } else if (!strcmp("UIDNEXT", arg)) { |
| 708 | if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &imap->uidnext) || !imap->uidnext) { |
| 709 | fprintf(stderr, "IMAP error: malformed NEXTUID status\n"); |
| 710 | return RESP_BAD; |
| 711 | } |
| 712 | } else if (!strcmp("CAPABILITY", arg)) { |
| 713 | parse_capability(imap, s); |
| 714 | } else if (!strcmp("ALERT", arg)) { |
| 715 | /* RFC2060 says that these messages MUST be displayed |
| 716 | * to the user |
| 717 | */ |
| 718 | for (; isspace((unsigned char)*p); p++); |
| 719 | fprintf(stderr, "*** IMAP ALERT *** %s\n", p); |
| 720 | } else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) { |
| 721 | if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity || |
| 722 | !(arg = next_arg(&s)) || strtol_i(arg, 10, (int *)cb->ctx) || !cb->ctx) { |
| 723 | fprintf(stderr, "IMAP error: malformed APPENDUID status\n"); |
| 724 | return RESP_BAD; |
| 725 | } |
| 726 | } |
| 727 | return RESP_OK; |
| 728 | } |
| 729 | |
| 730 | static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd) |
| 731 | { |
no test coverage detected