Commit 58d01e1e 58d01e1e081f2767ac07e9735c20d7f74c1bc637 by Sergey Poznyakoff

Imap client: fix status implementation.

1 parent 35718326
...@@ -87,41 +87,32 @@ _status_mapper (void **itmv, size_t itmc, void *call_data) ...@@ -87,41 +87,32 @@ _status_mapper (void **itmv, size_t itmc, void *call_data)
87 return 0; 87 return 0;
88 } 88 }
89 89
90 static int 90 struct status_data
91 _parse_status_response (mu_imap_t imap, const char *mboxname,
92 struct mu_imap_stat *ps)
93 { 91 {
94 struct imap_list_element *response, *elt; 92 const char *mboxname;
95 size_t count; 93 struct mu_imap_stat *ps;
96 int rc; 94 };
97
98 rc = mu_list_get (imap->untagged_resp, 0, (void*) &response);
99 if (rc)
100 return rc;
101 95
102 mu_list_count (response->v.list, &count); 96 static void
103 if (count != 3) 97 _status_response_action (mu_imap_t imap, mu_list_t response, void *data)
104 return MU_ERR_PARSE; 98 {
105 rc = mu_list_get (response->v.list, 0, (void*) &elt); 99 struct status_data *sd = data;
106 if (rc) 100 struct imap_list_element *elt;
107 return rc;
108 if (!_mu_imap_list_element_is_string (elt, "STATUS"))
109 return MU_ERR_NOENT;
110
111 rc = mu_list_get (response->v.list, 1, (void*) &elt);
112 if (rc)
113 return rc;
114 if (!_mu_imap_list_element_is_string (elt, mboxname))
115 return MU_ERR_NOENT;
116
117 rc = mu_list_get (response->v.list, 2, (void*) &elt);
118 if (rc)
119 return rc;
120 if (elt->type != imap_eltype_list)
121 return MU_ERR_PARSE;
122 101
123 ps->flags = 0; 102 elt = _mu_imap_list_at (response, 0);
124 return mu_list_gmap (elt->v.list, _status_mapper, 2, ps); 103 if (elt && _mu_imap_list_element_is_string (elt, "STATUS"))
104 {
105 elt = _mu_imap_list_at (response, 1);
106 if (elt && _mu_imap_list_element_is_string (elt, sd->mboxname))
107 {
108 elt = _mu_imap_list_at (response, 2);
109 if (elt && elt->type == imap_eltype_list)
110 {
111 sd->ps->flags = 0;
112 mu_list_gmap (elt->v.list, _status_mapper, 2, sd->ps);
113 }
114 }
115 }
125 } 116 }
126 117
127 int 118 int
...@@ -197,8 +188,11 @@ mu_imap_status (mu_imap_t imap, const char *mboxname, struct mu_imap_stat *ps) ...@@ -197,8 +188,11 @@ mu_imap_status (mu_imap_t imap, const char *mboxname, struct mu_imap_stat *ps)
197 switch (imap->resp_code) 188 switch (imap->resp_code)
198 { 189 {
199 case MU_IMAP_OK: 190 case MU_IMAP_OK:
200 memset (&imap->mbox_stat, 0, sizeof (imap->mbox_stat)); 191 {
201 status = _parse_status_response (imap, mboxname, ps); 192 struct status_data sd = { mboxname, ps };
193 status = mu_imap_foreach_response (imap, _status_response_action,
194 &sd);
195 }
202 break; 196 break;
203 197
204 case MU_IMAP_NO: 198 case MU_IMAP_NO:
......