@@ -99,15 +99,6 @@ static struct imap_server_conf server = {
9999 NULL , /* auth_method */
100100};
101101
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-
111102struct imap_socket {
112103 int fd [2 ];
113104 SSL * ssl ;
@@ -124,7 +115,6 @@ struct imap_cmd;
124115
125116struct imap {
126117 int uidnext ; /* from SELECT responses */
127- struct imap_list * ns_personal , * ns_other , * ns_shared ; /* NAMESPACE info */
128118 unsigned caps , rcaps ; /* CAPABILITY results */
129119 /* command queue */
130120 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,
554544 }
555545}
556546
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 )
582548{
583- struct imap_list * cur ;
584- char * s = * sp , * p ;
549+ char * s = * sp ;
585550
586551 for (;;) {
587552 while (isspace ((unsigned char )* s ))
@@ -590,36 +555,23 @@ static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)
590555 s ++ ;
591556 break ;
592557 }
593- * curp = cur = xmalloc (sizeof (* cur ));
594- curp = & cur -> next ;
595- cur -> val = NULL ; /* for clean bail */
596558 if (* s == '(' ) {
597559 /* sublist */
598560 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 ))
601562 goto bail ;
602563 } else if (* s == '"' ) {
603564 /* quoted string */
604565 s ++ ;
605- p = s ;
606566 for (; * s != '"' ; s ++ )
607567 if (!* s )
608568 goto bail ;
609- cur -> len = s - p ;
610569 s ++ ;
611- cur -> val = xmemdupz (p , cur -> len );
612570 } else {
613571 /* atom */
614- p = s ;
615572 for (; * s && !isspace ((unsigned char )* s ); s ++ )
616573 if (level && * s == ')' )
617574 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 );
623575 }
624576
625577 if (!level )
@@ -628,22 +580,15 @@ static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)
628580 goto bail ;
629581 }
630582 * sp = s ;
631- * curp = NULL ;
632583 return 0 ;
633584
634585bail :
635- * curp = NULL ;
636586 return -1 ;
637587}
638588
639- static struct imap_list * parse_list (char * * sp )
589+ static void skip_list (char * * sp )
640590{
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 );
647592}
648593
649594static 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)
722667 }
723668
724669 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 */
728674 } else if (!strcmp ("OK" , arg ) || !strcmp ("BAD" , arg ) ||
729675 !strcmp ("NO" , arg ) || !strcmp ("BYE" , arg )) {
730676 if ((resp = parse_response_code (ctx , NULL , cmd )) != RESP_OK )
@@ -844,9 +790,6 @@ static void imap_close_server(struct imap_store *ictx)
844790 imap_exec (ictx , NULL , "LOGOUT" );
845791 socket_shutdown (& imap -> buf .sock );
846792 }
847- free_list (imap -> ns_personal );
848- free_list (imap -> ns_other );
849- free_list (imap -> ns_shared );
850793 free (imap );
851794}
852795
0 commit comments