imap-send.c: remove namespace fields from struct imap

They are unused, and their removal means that a bunch of list-related infrastructure can be disposed of. It might be that the "NAMESPACE" response that is now skipped over in get_cmd_result() should never be sent by the server. But somebody would have to check the IMAP protocol and how we interact with the server to be sure. So for now I am leaving that branch of the "if" statement there. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Jan 15, 2013 at 09:06 UTC 3648b4d996be3e89d53a9beefc448c7129e3a49f
1 file changed +9 -66
imap-send.c
+9 -66
@@ -99,15 +99,6 @@ static struct imap_server_conf server = {
99 NULL, /* auth_method */
100 };
101
102 -#define NIL (void *)0x1
103 -#define LIST (void *)0x2
104 -
105 -struct imap_list {
106 - struct imap_list *next, *child;
107 - char *val;
108 - int len;
109 -};
110 -
102 struct imap_socket {
103 int fd[2];
104 SSL *ssl;
@@ -124,7 +115,6 @@ struct imap_cmd;
115
116 struct imap {
117 int uidnext; /* from SELECT responses */
127 - struct imap_list *ns_personal, *ns_other, *ns_shared; /* NAMESPACE info */
118 unsigned caps, rcaps; /* CAPABILITY results */
119 /* command queue */
120 int nexttag, num_in_progress, literal_pending;
@@ -554,34 +544,9 @@ static int imap_exec_m(struct imap_store *ctx, struct imap_cmd_cb *cb,
544 }
545 }
546
557 -static int is_atom(struct imap_list *list)
558 -{
559 - return list && list->val && list->val != NIL && list->val != LIST;
560 -}
561 -
562 -static int is_list(struct imap_list *list)
563 -{
564 - return list && list->val == LIST;
565 -}
566 -
567 -static void free_list(struct imap_list *list)
568 -{
569 - struct imap_list *tmp;
570 -
571 - for (; list; list = tmp) {
572 - tmp = list->next;
573 - if (is_list(list))
574 - free_list(list->child);
575 - else if (is_atom(list))
576 - free(list->val);
577 - free(list);
578 - }
579 -}
580 -
581 -static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)
547 +static int skip_imap_list_l(char **sp, int level)
548 {
583 - struct imap_list *cur;
584 - char *s = *sp, *p;
549 + char *s = *sp;
550
551 for (;;) {
552 while (isspace((unsigned char)*s))
@@ -590,36 +555,23 @@ static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)
555 s++;
556 break;
557 }
593 - *curp = cur = xmalloc(sizeof(*cur));
594 - curp = &cur->next;
595 - cur->val = NULL; /* for clean bail */
558 if (*s == '(') {
559 /* sublist */
560 s++;
599 - cur->val = LIST;
600 - if (parse_imap_list_l(&s, &cur->child, level + 1))
561 + if (skip_imap_list_l(&s, level + 1))
562 goto bail;
563 } else if (*s == '"') {
564 /* quoted string */
565 s++;
605 - p = s;
566 for (; *s != '"'; s++)
567 if (!*s)
568 goto bail;
609 - cur->len = s - p;
569 s++;
611 - cur->val = xmemdupz(p, cur->len);
570 } else {
571 /* atom */
614 - p = s;
572 for (; *s && !isspace((unsigned char)*s); s++)
573 if (level && *s == ')')
574 break;
618 - cur->len = s - p;
619 - if (cur->len == 3 && !memcmp("NIL", p, 3))
620 - cur->val = NIL;
621 - else
622 - cur->val = xmemdupz(p, cur->len);
575 }
576
577 if (!level)
@@ -628,22 +580,15 @@ static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)
580 goto bail;
581 }
582 *sp = s;
631 - *curp = NULL;
583 return 0;
584
585 bail:
635 - *curp = NULL;
586 return -1;
587 }
588
639 -static struct imap_list *parse_list(char **sp)
589 +static void skip_list(char **sp)
590 {
641 - struct imap_list *head;
642 -
643 - if (!parse_imap_list_l(sp, &head, 0))
644 - return head;
645 - free_list(head);
646 - return NULL;
591 + skip_imap_list_l(sp, 0);
592 }
593
594 static void parse_capability(struct imap *imap, char *cmd)
@@ -722,9 +667,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
667 }
668
669 if (!strcmp("NAMESPACE", arg)) {
725 - imap->ns_personal = parse_list(&cmd);
726 - imap->ns_other = parse_list(&cmd);
727 - imap->ns_shared = parse_list(&cmd);
670 + /* rfc2342 NAMESPACE response. */
671 + skip_list(&cmd); /* Personal mailboxes */
672 + skip_list(&cmd); /* Others' mailboxes */
673 + skip_list(&cmd); /* Shared mailboxes */
674 } else if (!strcmp("OK", arg) || !strcmp("BAD", arg) ||
675 !strcmp("NO", arg) || !strcmp("BYE", arg)) {
676 if ((resp = parse_response_code(ctx, NULL, cmd)) != RESP_OK)
@@ -844,9 +790,6 @@ static void imap_close_server(struct imap_store *ictx)
790 imap_exec(ictx, NULL, "LOGOUT");
791 socket_shutdown(&imap->buf.sock);
792 }
847 - free_list(imap->ns_personal);
848 - free_list(imap->ns_other);
849 - free_list(imap->ns_shared);
793 free(imap);
794 }
795