Commit 80b012f7 80b012f7f89ca6acbf1191ef1b8073239509b941 by Sergey Poznyakoff

Change callback handling in imap client.

* include/mailutils/imap.h (MU_IMAP_CB_NO)
(MU_IMAP_CB_BAD,MU_IMAP_CB_BYE)
(MU_IMAP_CB_PREAUTH): New callbacks.
(mu_imap_callback_t): Change signature.
(mu_imap_callback): Change signature.
* include/mailutils/sys/imap.h (mu_imap_client_state)
<MU_IMAP_CLOSING>: New state.
* libproto/imap/callback.c (mu_imap_callback): Change signature.
Fix boundary check.
(mu_imap_register_callback_function): Fix boundary check.
* libproto/imap/connect.c (mu_imap_connect): Use mu_imap_foreach_response
to parse response.
* libproto/imap/response.c (_mu_imap_response): Check number of words
before dereferencing them.
* libproto/imap/resproc.c: Handle all server responses.
* mu/imap.c (com_connect): Set POPAUTH callback.
Set verbosity flags after I/O structure has been created.
1 parent bbc46f0c
...@@ -108,19 +108,30 @@ int mu_imap_foreach_response (mu_imap_t imap, mu_imap_response_action_t fun, ...@@ -108,19 +108,30 @@ int mu_imap_foreach_response (mu_imap_t imap, mu_imap_response_action_t fun,
108 void *data); 108 void *data);
109 109
110 110
111 /* The following five callbacks correspond to members of struct
112 mu_imap_stat and take a pointer to struct mu_imap_stat as their
113 only argument. */
111 #define MU_IMAP_CB_PERMANENT_FLAGS 0 114 #define MU_IMAP_CB_PERMANENT_FLAGS 0
112 #define MU_IMAP_CB_MESSAGE_COUNT 1 115 #define MU_IMAP_CB_MESSAGE_COUNT 1
113 #define MU_IMAP_CB_RECENT_COUNT 2 116 #define MU_IMAP_CB_RECENT_COUNT 2
114 #define MU_IMAP_CB_FIRST_UNSEEN 3 117 #define MU_IMAP_CB_FIRST_UNSEEN 3
115 #define MU_IMAP_CB_UIDNEXT 4 118 #define MU_IMAP_CB_UIDNEXT 4
116 #define MU_IMAP_CB_UIDVALIDITY 5 119 #define MU_IMAP_CB_UIDVALIDITY 5
120
121 /* The following callbacks correspond to server responses and take two
122 argument: a response code (see MU_IMAP_RESPONSE, below), and
123 human-readable text string as returned by the server. The latter can
124 be NULL. */
117 #define MU_IMAP_CB_OK 6 125 #define MU_IMAP_CB_OK 6
118 #define _MU_IMAP_CB_MAX 7 126 #define MU_IMAP_CB_NO 7
127 #define MU_IMAP_CB_BAD 8
128 #define MU_IMAP_CB_BYE 9
129 #define MU_IMAP_CB_PREAUTH 10
130 #define _MU_IMAP_CB_MAX 11
119 131
120 typedef void (*mu_imap_callback_t) (void *, int code, mu_list_t resp, 132 typedef void (*mu_imap_callback_t) (void *, int code, va_list ap);
121 va_list ap);
122 133
123 void mu_imap_callback (mu_imap_t imap, int code, mu_list_t resp, ...); 134 void mu_imap_callback (mu_imap_t imap, int code, ...);
124 135
125 void mu_imap_register_callback_function (mu_imap_t imap, int code, 136 void mu_imap_register_callback_function (mu_imap_t imap, int code,
126 mu_imap_callback_t callback, 137 mu_imap_callback_t callback,
......
...@@ -45,7 +45,8 @@ enum mu_imap_client_state ...@@ -45,7 +45,8 @@ enum mu_imap_client_state
45 MU_IMAP_LOGOUT_RX, 45 MU_IMAP_LOGOUT_RX,
46 MU_IMAP_ID_RX, 46 MU_IMAP_ID_RX,
47 MU_IMAP_SELECT_RX, 47 MU_IMAP_SELECT_RX,
48 MU_IMAP_STATUS_RX 48 MU_IMAP_STATUS_RX,
49 MU_IMAP_CLOSING
49 }; 50 };
50 51
51 enum mu_imap_response 52 enum mu_imap_response
......
...@@ -23,15 +23,15 @@ ...@@ -23,15 +23,15 @@
23 #include <mailutils/sys/imap.h> 23 #include <mailutils/sys/imap.h>
24 24
25 void 25 void
26 mu_imap_callback (mu_imap_t imap, int code, mu_list_t resp, ...) 26 mu_imap_callback (mu_imap_t imap, int code, ...)
27 { 27 {
28 va_list ap; 28 va_list ap;
29 29
30 if (code < 0 || code > _MU_IMAP_CB_MAX || !imap->callback[code].action) 30 if (code < 0 || code >= _MU_IMAP_CB_MAX || !imap->callback[code].action)
31 return; 31 return;
32 32
33 va_start (ap, resp); 33 va_start (ap, code);
34 imap->callback[code].action (imap->callback[code].data, code, resp, ap); 34 imap->callback[code].action (imap->callback[code].data, code, ap);
35 va_end (ap); 35 va_end (ap);
36 } 36 }
37 37
...@@ -40,7 +40,7 @@ mu_imap_register_callback_function (mu_imap_t imap, int code, ...@@ -40,7 +40,7 @@ mu_imap_register_callback_function (mu_imap_t imap, int code,
40 mu_imap_callback_t callback, 40 mu_imap_callback_t callback,
41 void *data) 41 void *data)
42 { 42 {
43 if (code < 0 || code > _MU_IMAP_CB_MAX) 43 if (code < 0 || code >= _MU_IMAP_CB_MAX)
44 { 44 {
45 mu_error ("%s:%d: ignoring unsupported callback code %d", 45 mu_error ("%s:%d: ignoring unsupported callback code %d",
46 __FILE__, __LINE__, code); 46 __FILE__, __LINE__, code);
......
...@@ -37,11 +37,17 @@ mu_imap_connect (mu_imap_t imap) ...@@ -37,11 +37,17 @@ mu_imap_connect (mu_imap_t imap)
37 char **wv; 37 char **wv;
38 char *bufptr; 38 char *bufptr;
39 size_t bufsize; 39 size_t bufsize;
40 40
41 if (imap == NULL) 41 if (imap == NULL)
42 return EINVAL; 42 return EINVAL;
43 if (imap->io == NULL) 43 if (imap->io == NULL)
44 return EINVAL; 44 return EINVAL;
45
46 _mu_imap_clrerrstr (imap);
47 status = _mu_imap_untagged_response_clear (imap);
48 if (status)
49 return status;
50
45 switch (imap->state) 51 switch (imap->state)
46 { 52 {
47 default: 53 default:
...@@ -79,29 +85,26 @@ mu_imap_connect (mu_imap_t imap) ...@@ -79,29 +85,26 @@ mu_imap_connect (mu_imap_t imap)
79 imap->state = MU_IMAP_ERROR; 85 imap->state = MU_IMAP_ERROR;
80 return MU_ERR_BADREPLY; 86 return MU_ERR_BADREPLY;
81 } 87 }
82 else if (strcmp (wv[1], "BYE") == 0)
83 {
84 status = EACCES;
85 mu_imapio_getbuf (imap->io, &bufptr, &bufsize);
86 _mu_imap_seterrstr (imap, bufptr + 2, bufsize - 2);
87 }
88 else if (strcmp (wv[1], "PREAUTH") == 0)
89 {
90 status = 0;
91 imap->state = MU_IMAP_CONNECTED;
92 imap->imap_state = MU_IMAP_STATE_AUTH;
93 }
94 else if (strcmp (wv[1], "OK") == 0)
95 {
96 status = 0;
97 imap->state = MU_IMAP_CONNECTED;
98 imap->imap_state = MU_IMAP_STATE_NONAUTH;
99 }
100 else 88 else
101 { 89 {
102 status = MU_ERR_BADREPLY; 90 _mu_imap_untagged_response_add (imap);
103 imap->state = MU_IMAP_ERROR; 91 mu_imap_foreach_response (imap, NULL, NULL);
92 switch (imap->state)
93 {
94 case MU_IMAP_CONNECTED:
95 status = 0;
96 break;
97
98 case MU_IMAP_CLOSING:
99 status = EACCES;
100 break;
101
102 default:
103 imap->state = MU_IMAP_ERROR;
104 status = MU_ERR_BADREPLY;
105 }
104 } 106 }
107 break;
105 } 108 }
106 109
107 return status; 110 return status;
......
...@@ -85,7 +85,6 @@ int ...@@ -85,7 +85,6 @@ int
85 mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc) 85 mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc)
86 { 86 {
87 int status; 87 int status;
88 char *p;
89 88
90 if (imap == NULL) 89 if (imap == NULL)
91 return EINVAL; 90 return EINVAL;
......
...@@ -28,7 +28,6 @@ int ...@@ -28,7 +28,6 @@ int
28 mu_imap_login (mu_imap_t imap, const char *user, const char *pass) 28 mu_imap_login (mu_imap_t imap, const char *user, const char *pass)
29 { 29 {
30 int status; 30 int status;
31 char *p;
32 31
33 if (imap == NULL) 32 if (imap == NULL)
34 return EINVAL; 33 return EINVAL;
......
...@@ -59,6 +59,13 @@ _mu_imap_response (mu_imap_t imap) ...@@ -59,6 +59,13 @@ _mu_imap_response (mu_imap_t imap)
59 size_t wc; 59 size_t wc;
60 60
61 mu_imapio_get_words (imap->io, &wc, &wv); 61 mu_imapio_get_words (imap->io, &wc, &wv);
62 if (wc == 0)
63 {
64 imap->state = MU_IMAP_ERROR;
65 status = MU_ERR_BADREPLY;/* FIXME: ECONNRESET ? */
66 break;
67 }
68
62 if (strcmp (wv[0], "*") == 0) 69 if (strcmp (wv[0], "*") == 0)
63 { 70 {
64 _mu_imap_untagged_response_add (imap);/* FIXME: error checking */ 71 _mu_imap_untagged_response_add (imap);/* FIXME: error checking */
......
...@@ -53,89 +53,157 @@ struct mu_kwd mu_imap_response_codes[] = { ...@@ -53,89 +53,157 @@ struct mu_kwd mu_imap_response_codes[] = {
53 { NULL } 53 { NULL }
54 }; 54 };
55 55
56 static void 56 static int
57 ok_response (mu_imap_t imap, mu_list_t resp, void *data) 57 parse_response_code (mu_imap_t imap, mu_list_t resp)
58 { 58 {
59 struct imap_list_element *arg; 59 struct imap_list_element *arg;
60 int rcode = -1; 60 int rcode = -1;
61 size_t n = 0; 61
62
63 arg = _mu_imap_list_at (resp, 1); 62 arg = _mu_imap_list_at (resp, 1);
64 if (!arg) 63 if (!arg)
65 return; 64 return -1;
65
66 if (_mu_imap_list_element_is_string (arg, "[")) 66 if (_mu_imap_list_element_is_string (arg, "["))
67 { 67 {
68 char *p;
69
70 arg = _mu_imap_list_at (resp, 2); 68 arg = _mu_imap_list_at (resp, 2);
71 if (!arg || arg->type != imap_eltype_string) 69 if (!arg || arg->type != imap_eltype_string)
72 return; 70 return -1;
73 71
74 if (mu_kwd_xlat_name (mu_imap_response_codes, arg->v.string, &rcode)) 72 if (mu_kwd_xlat_name (mu_imap_response_codes, arg->v.string, &rcode))
75 rcode = -1; 73 return -1;
76 74
77 arg = _mu_imap_list_at (resp, 4); 75 arg = _mu_imap_list_at (resp, 4);
78 if (!arg || !_mu_imap_list_element_is_string (arg, "]")) 76 if (!arg || !_mu_imap_list_element_is_string (arg, "]"))
79 return; 77 return -1;
80 78 }
81 switch (rcode) 79 return rcode;
82 { 80 }
83 case MU_IMAP_RESPONSE_PERMANENTFLAGS: 81
84 arg = _mu_imap_list_at (resp, 3); 82 static void
85 if (!arg || 83 ok_response (mu_imap_t imap, mu_list_t resp, void *data)
86 _mu_imap_collect_flags (arg, &imap->mbox_stat.permanent_flags)) 84 {
87 break; 85 struct imap_list_element *arg;
88 imap->mbox_stat.flags |= MU_IMAP_STAT_PERMANENT_FLAGS; 86 int rcode;
89 mu_imap_callback (imap, MU_IMAP_CB_PERMANENT_FLAGS, resp, 87 size_t n = 0;
90 &imap->mbox_stat); 88 char *p;
91 return; 89
90 rcode = parse_response_code (imap, resp);
91 switch (rcode)
92 {
93 case MU_IMAP_RESPONSE_PERMANENTFLAGS:
94 arg = _mu_imap_list_at (resp, 3);
95 if (!arg ||
96 _mu_imap_collect_flags (arg, &imap->mbox_stat.permanent_flags))
97 break;
98 imap->mbox_stat.flags |= MU_IMAP_STAT_PERMANENT_FLAGS;
99 mu_imap_callback (imap, MU_IMAP_CB_PERMANENT_FLAGS, &imap->mbox_stat);
100 return;
92 101
93 case MU_IMAP_RESPONSE_UIDNEXT: 102 case MU_IMAP_RESPONSE_UIDNEXT:
94 arg = _mu_imap_list_at (resp, 3); 103 arg = _mu_imap_list_at (resp, 3);
95 if (!arg || arg->type != imap_eltype_string) 104 if (!arg || arg->type != imap_eltype_string)
96 break; 105 break;
97 n = strtoul (arg->v.string, &p, 10); 106 n = strtoul (arg->v.string, &p, 10);
98 if (*p == 0) 107 if (*p == 0)
99 { 108 {
100 imap->mbox_stat.uidnext = n; 109 imap->mbox_stat.uidnext = n;
101 imap->mbox_stat.flags |= MU_IMAP_STAT_UIDNEXT; 110 imap->mbox_stat.flags |= MU_IMAP_STAT_UIDNEXT;
102 mu_imap_callback (imap, MU_IMAP_CB_UIDNEXT, resp, 111 mu_imap_callback (imap, MU_IMAP_CB_UIDNEXT, &imap->mbox_stat);
103 &imap->mbox_stat); 112 }
104 } 113 return;
105 return;
106
107 case MU_IMAP_RESPONSE_UIDVALIDITY:
108 arg = _mu_imap_list_at (resp, 3);
109 if (!arg || arg->type != imap_eltype_string)
110 break;
111 n = strtoul (arg->v.string, &p, 10);
112 if (*p == 0)
113 {
114 imap->mbox_stat.uidvalidity = n;
115 imap->mbox_stat.flags |= MU_IMAP_STAT_UIDVALIDITY;
116 mu_imap_callback (imap, MU_IMAP_CB_UIDVALIDITY, resp,
117 &imap->mbox_stat);
118 }
119 return;
120 114
121 case MU_IMAP_RESPONSE_UNSEEN: 115 case MU_IMAP_RESPONSE_UIDVALIDITY:
122 arg = _mu_imap_list_at (resp, 3); 116 arg = _mu_imap_list_at (resp, 3);
123 if (!arg || arg->type != imap_eltype_string) 117 if (!arg || arg->type != imap_eltype_string)
124 break; 118 break;
125 n = strtoul (arg->v.string, &p, 10); 119 n = strtoul (arg->v.string, &p, 10);
126 if (*p == 0) 120 if (*p == 0)
127 { 121 {
128 imap->mbox_stat.first_unseen = n; 122 imap->mbox_stat.uidvalidity = n;
129 imap->mbox_stat.flags |= MU_IMAP_STAT_FIRST_UNSEEN; 123 imap->mbox_stat.flags |= MU_IMAP_STAT_UIDVALIDITY;
130 mu_imap_callback (imap, MU_IMAP_CB_FIRST_UNSEEN, resp, 124 mu_imap_callback (imap, MU_IMAP_CB_UIDVALIDITY, &imap->mbox_stat);
131 &imap->mbox_stat); 125 }
132 } 126 return;
133 return; 127
128 case MU_IMAP_RESPONSE_UNSEEN:
129 arg = _mu_imap_list_at (resp, 3);
130 if (!arg || arg->type != imap_eltype_string)
131 break;
132 n = strtoul (arg->v.string, &p, 10);
133 if (*p == 0)
134 {
135 imap->mbox_stat.first_unseen = n;
136 imap->mbox_stat.flags |= MU_IMAP_STAT_FIRST_UNSEEN;
137 mu_imap_callback (imap, MU_IMAP_CB_FIRST_UNSEEN, &imap->mbox_stat);
134 } 138 }
139 return;
140 }
141
142 if (mu_list_tail (resp, (void*) &arg) || arg->type != imap_eltype_string)
143 arg = NULL;
144 mu_imap_callback (imap, MU_IMAP_CB_OK, rcode, arg ? arg->v.string : NULL);
145 if (imap->state == MU_IMAP_GREETINGS)
146 {
147 imap->state = MU_IMAP_CONNECTED;
148 imap->imap_state = MU_IMAP_STATE_NONAUTH;
149 }
150 }
151
152 static void
153 default_response (mu_imap_t imap, int code, mu_list_t resp, void *data)
154 {
155 struct imap_list_element *arg;
156
157 if (mu_list_tail (resp, (void*) &arg) || arg->type != imap_eltype_string)
158 arg = NULL;
159 mu_imap_callback (imap, code, parse_response_code (imap, resp),
160 arg ? arg->v.string : NULL);
161 }
162
163 static void
164 no_response (mu_imap_t imap, mu_list_t resp, void *data)
165 {
166 default_response (imap, MU_IMAP_CB_NO, resp, data);
167 if (imap->state == MU_IMAP_GREETINGS)
168 imap->state = MU_IMAP_ERROR;
169 }
170
171 static void
172 bad_response (mu_imap_t imap, mu_list_t resp, void *data)
173 {
174 default_response (imap, MU_IMAP_CB_BAD, resp, data);
175 if (imap->state == MU_IMAP_GREETINGS)
176 imap->state = MU_IMAP_ERROR;
177 }
178
179 static void
180 bye_response (mu_imap_t imap, mu_list_t resp, void *data)
181 {
182 default_response (imap, MU_IMAP_CB_BYE, resp, data);
183 imap->state = MU_IMAP_CLOSING;
184 }
185
186 static void
187 preauth_response (mu_imap_t imap, mu_list_t resp, void *data)
188 {
189 if (imap->state == MU_IMAP_GREETINGS)
190 {
191 struct imap_list_element *arg;
192
193 if (mu_list_tail (resp, (void*) &arg) || arg->type != imap_eltype_string)
194 arg = NULL;
195 mu_imap_callback (imap, MU_IMAP_CB_PREAUTH,
196 parse_response_code (imap, resp),
197 arg ? arg->v.string : NULL);
198 imap->state = MU_IMAP_CONNECTED;
199 imap->imap_state = MU_IMAP_STATE_AUTH;
135 } 200 }
136 mu_imap_callback (imap, MU_IMAP_CB_OK, resp, rcode); 201 else
202 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
203 ("ignoring unexpected PREAUTH response"));
137 } 204 }
138 205
206
139 207
140 struct response_closure 208 struct response_closure
141 { 209 {
...@@ -152,10 +220,10 @@ struct resptab ...@@ -152,10 +220,10 @@ struct resptab
152 220
153 static struct resptab resptab[] = { 221 static struct resptab resptab[] = {
154 { "OK", ok_response }, 222 { "OK", ok_response },
155 { "NO", }, 223 { "NO", no_response },
156 { "BAD", }, 224 { "BAD", bad_response },
157 { "PREAUTH", }, 225 { "PREAUTH", preauth_response },
158 { "BYE", }, 226 { "BYE", bye_response },
159 { NULL } 227 { NULL }
160 }; 228 };
161 229
...@@ -216,7 +284,8 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp) ...@@ -216,7 +284,8 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp)
216 return 1; 284 return 1;
217 imap->mbox_stat.message_count = n; 285 imap->mbox_stat.message_count = n;
218 imap->mbox_stat.flags |= MU_IMAP_STAT_MESSAGE_COUNT; 286 imap->mbox_stat.flags |= MU_IMAP_STAT_MESSAGE_COUNT;
219 mu_imap_callback (imap, MU_IMAP_CB_MESSAGE_COUNT, resp, n); 287 mu_imap_callback (imap, MU_IMAP_CB_MESSAGE_COUNT, resp,
288 &imap->mbox_stat);
220 return 0; 289 return 0;
221 } 290 }
222 else if (_mu_imap_list_element_is_string (arg, "RECENT")) 291 else if (_mu_imap_list_element_is_string (arg, "RECENT"))
...@@ -229,7 +298,8 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp) ...@@ -229,7 +298,8 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t resp)
229 return 1; 298 return 1;
230 imap->mbox_stat.recent_count = n; 299 imap->mbox_stat.recent_count = n;
231 imap->mbox_stat.flags |= MU_IMAP_STAT_RECENT_COUNT; 300 imap->mbox_stat.flags |= MU_IMAP_STAT_RECENT_COUNT;
232 mu_imap_callback (imap, MU_IMAP_CB_RECENT_COUNT, resp, n); 301 mu_imap_callback (imap, MU_IMAP_CB_RECENT_COUNT, resp,
302 &imap->mbox_stat);
233 return 0; 303 return 0;
234 } 304 }
235 } 305 }
...@@ -248,7 +318,13 @@ _process_response (void *item, void *data) ...@@ -248,7 +318,13 @@ _process_response (void *item, void *data)
248 ("ignoring string response \"%s\"", elt->v.string)); 318 ("ignoring string response \"%s\"", elt->v.string));
249 } 319 }
250 else if (_process_unsolicited_response (clos->imap, elt->v.list)) 320 else if (_process_unsolicited_response (clos->imap, elt->v.list))
251 clos->fun (clos->imap, elt->v.list, clos->data); 321 {
322 if (clos->fun)
323 clos->fun (clos->imap, elt->v.list, clos->data);
324 else
325 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
326 ("ignoring unexpected response"));
327 }
252 return 0; 328 return 0;
253 } 329 }
254 330
......
...@@ -67,7 +67,6 @@ mu_imap_select (mu_imap_t imap, const char *mbox, int writable, ...@@ -67,7 +67,6 @@ mu_imap_select (mu_imap_t imap, const char *mbox, int writable,
67 struct mu_imap_stat *ps) 67 struct mu_imap_stat *ps)
68 { 68 {
69 int status; 69 int status;
70 char *p;
71 70
72 if (imap == NULL) 71 if (imap == NULL)
73 return EINVAL; 72 return EINVAL;
......
...@@ -119,7 +119,6 @@ int ...@@ -119,7 +119,6 @@ int
119 mu_imap_status (mu_imap_t imap, const char *mboxname, struct mu_imap_stat *ps) 119 mu_imap_status (mu_imap_t imap, const char *mboxname, struct mu_imap_stat *ps)
120 { 120 {
121 int status; 121 int status;
122 char *p;
123 int delim = 0; 122 int delim = 0;
124 int i; 123 int i;
125 124
......
...@@ -150,7 +150,18 @@ imap_prompt_env () ...@@ -150,7 +150,18 @@ imap_prompt_env ()
150 150
151 mutool_prompt_env[14] = NULL; 151 mutool_prompt_env[14] = NULL;
152 } 152 }
153 153
154 /* Callbacks */
155 static void
156 imap_popauth_callback (void *data, int code, va_list ap)
157 {
158 int rcode = va_arg (ap, int);
159 const char *text = va_arg (ap, const char *);
160 if (text)
161 mu_diag_output (MU_DIAG_INFO, _("session authenticated: %s"), text);
162 else
163 mu_diag_output (MU_DIAG_INFO, _("session authenticated"));
164 }
154 165
155 static int 166 static int
156 com_disconnect (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) 167 com_disconnect (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
...@@ -206,12 +217,6 @@ com_connect (int argc, char **argv) ...@@ -206,12 +217,6 @@ com_connect (int argc, char **argv)
206 struct mu_sockaddr *sa; 217 struct mu_sockaddr *sa;
207 struct mu_sockaddr_hints hints; 218 struct mu_sockaddr_hints hints;
208 219
209 if (QRY_VERBOSE ())
210 {
211 imap_set_verbose ();
212 imap_set_verbose_mask ();
213 }
214
215 memset (&hints, 0, sizeof (hints)); 220 memset (&hints, 0, sizeof (hints));
216 hints.flags = MU_AH_DETECT_FAMILY; 221 hints.flags = MU_AH_DETECT_FAMILY;
217 hints.port = tls ? MU_IMAP_DEFAULT_SSL_PORT : MU_IMAP_DEFAULT_PORT; 222 hints.port = tls ? MU_IMAP_DEFAULT_SSL_PORT : MU_IMAP_DEFAULT_PORT;
...@@ -243,6 +248,19 @@ com_connect (int argc, char **argv) ...@@ -243,6 +248,19 @@ com_connect (int argc, char **argv)
243 } 248 }
244 #endif 249 #endif
245 mu_imap_set_carrier (imap, tcp); 250 mu_imap_set_carrier (imap, tcp);
251
252 if (QRY_VERBOSE ())
253 {
254 imap_set_verbose ();
255 imap_set_verbose_mask ();
256 }
257
258 /* Set callbacks */
259 mu_imap_register_callback_function (imap, MU_IMAP_CB_PREAUTH,
260 imap_popauth_callback,
261 NULL);
262
263
246 status = mu_imap_connect (imap); 264 status = mu_imap_connect (imap);
247 if (status) 265 if (status)
248 { 266 {
...@@ -554,7 +572,6 @@ com_status (int argc, char **argv) ...@@ -554,7 +572,6 @@ com_status (int argc, char **argv)
554 } 572 }
555 return 0; 573 return 0;
556 } 574 }
557
558 575
559 struct mutool_command imap_comtab[] = { 576 struct mutool_command imap_comtab[] = {
560 { "capability", 1, -1, com_capability, 577 { "capability", 1, -1, com_capability,
......