Implement imap mailbox (read-only, so far).
* include/mailutils/sys/imap.h (_mu_imap_mailbox_init): New proto. (_mu_imap_message,_mu_imap_mailbox): New structures. * libproto/imap/mbox.c: New file. * libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Put back mbox.c * libproto/imap/fetch.c: Fix body/bodystructure parsing. * libproto/imap/folder.c (_mu_imap_folder_destroy): Close folder. (_mu_imap_folder_open): Implement STARTTLS. (_imap_record): Accept parameters in URL, use _mu_imap_mailbox_init to initialize mailbox.
Showing
5 changed files
with
91 additions
and
39 deletions
... | @@ -235,9 +235,46 @@ int _mu_imap_url_init (mu_url_t url); | ... | @@ -235,9 +235,46 @@ int _mu_imap_url_init (mu_url_t url); |
235 | int _mu_imaps_url_init (mu_url_t url); | 235 | int _mu_imaps_url_init (mu_url_t url); |
236 | 236 | ||
237 | /* ----------------------------- */ | 237 | /* ----------------------------- */ |
238 | /* Folder interface */ | 238 | /* Mailbox interface */ |
239 | /* ----------------------------- */ | 239 | /* ----------------------------- */ |
240 | 240 | ||
241 | int _mu_imap_mailbox_init (mu_mailbox_t mailbox); | ||
242 | |||
243 | #define _MU_IMAP_MSG_SCANNED 0x01 | ||
244 | #define _MU_IMAP_MSG_CACHED 0x02 | ||
245 | #define _MU_IMAP_MSG_LINES 0x04 | ||
246 | |||
247 | struct _mu_imap_message | ||
248 | { | ||
249 | int flags; | ||
250 | size_t uid; /* Message UID */ | ||
251 | int attr_flags; /* Attributes */ | ||
252 | mu_off_t offset; /* Offset in the message cache stream */ | ||
253 | mu_off_t body_start; /* Start of message, relative to offset */ | ||
254 | mu_off_t body_end; /* End of message, relative to offset */ | ||
255 | size_t header_lines; /* Number of lines in the header */ | ||
256 | size_t body_lines; /* Number of lines in the body */ | ||
257 | size_t message_size; /* Message size */ | ||
258 | size_t message_lines; /* Number of lines in the message */ | ||
259 | struct mu_imapenvelope *env; /* IMAP envelope */ | ||
260 | mu_message_t message; /* Pointer to the message structure */ | ||
261 | struct _mu_imap_mailbox *imbx; /* Back pointer. */ | ||
262 | }; | ||
263 | |||
264 | #define _MU_IMAP_MBX_UPTODATE 0x01 | ||
265 | |||
266 | struct _mu_imap_mailbox | ||
267 | { | ||
268 | int flags; | ||
269 | mu_off_t total_size; /* Total mailbox size. */ | ||
270 | struct mu_imap_stat stats; /* Mailbox statistics */ | ||
271 | struct _mu_imap_message *msgs; /* Array of messages */ | ||
272 | size_t msgs_cnt; /* Number of used slots in msgs */ | ||
273 | size_t msgs_max; /* Number of slots in msgs */ | ||
274 | mu_stream_t cache; /* Message cache stream */ | ||
275 | int last_error; /* Last error code */ | ||
276 | mu_mailbox_t mbox; | ||
277 | }; | ||
241 | 278 | ||
242 | # ifdef __cplusplus | 279 | # ifdef __cplusplus |
243 | } | 280 | } | ... | ... |
... | @@ -23,8 +23,6 @@ libmu_imap_la_LIBADD = ${MU_LIB_AUTH} ${MU_LIB_MAILUTILS} @INTLLIBS@ | ... | @@ -23,8 +23,6 @@ libmu_imap_la_LIBADD = ${MU_LIB_AUTH} ${MU_LIB_MAILUTILS} @INTLLIBS@ |
23 | 23 | ||
24 | SUBDIRS = . tests | 24 | SUBDIRS = . tests |
25 | 25 | ||
26 | # FIXME: Put this back when ready | ||
27 | # mbox.c | ||
28 | libmu_imap_la_SOURCES = \ | 26 | libmu_imap_la_SOURCES = \ |
29 | appmsg.c\ | 27 | appmsg.c\ |
30 | appstr.c\ | 28 | appstr.c\ |
... | @@ -68,4 +66,5 @@ libmu_imap_la_SOURCES = \ | ... | @@ -68,4 +66,5 @@ libmu_imap_la_SOURCES = \ |
68 | unselect.c\ | 66 | unselect.c\ |
69 | unsubscribe.c\ | 67 | unsubscribe.c\ |
70 | folder.c\ | 68 | folder.c\ |
69 | mbox.c\ | ||
71 | url.c | 70 | url.c | ... | ... |
... | @@ -618,7 +618,7 @@ _parse_bodystructure_simple (struct imap_list_element *elt, | ... | @@ -618,7 +618,7 @@ _parse_bodystructure_simple (struct imap_list_element *elt, |
618 | struct body_field_map *map; | 618 | struct body_field_map *map; |
619 | 619 | ||
620 | mu_list_count (elt->v.list, &n); | 620 | mu_list_count (elt->v.list, &n); |
621 | if (n < 8) | 621 | if (n < 7) |
622 | return MU_ERR_PARSE; | 622 | return MU_ERR_PARSE; |
623 | 623 | ||
624 | tok = _mu_imap_list_at (elt->v.list, BSTOK_BODY_TYPE); | 624 | tok = _mu_imap_list_at (elt->v.list, BSTOK_BODY_TYPE); |
... | @@ -976,6 +976,7 @@ _extract_string (void **itmv, size_t itmc, void *call_data) | ... | @@ -976,6 +976,7 @@ _extract_string (void **itmv, size_t itmc, void *call_data) |
976 | static int | 976 | static int |
977 | _fetch_fold (void *item, void *data) | 977 | _fetch_fold (void *item, void *data) |
978 | { | 978 | { |
979 | int rc; | ||
979 | struct imap_list_element *elt = item; | 980 | struct imap_list_element *elt = item; |
980 | struct parse_response_env *env = data; | 981 | struct parse_response_env *env = data; |
981 | 982 | ||
... | @@ -983,7 +984,6 @@ _fetch_fold (void *item, void *data) | ... | @@ -983,7 +984,6 @@ _fetch_fold (void *item, void *data) |
983 | { | 984 | { |
984 | case resp_kw: | 985 | case resp_kw: |
985 | { | 986 | { |
986 | int rc; | ||
987 | char *kw; | 987 | char *kw; |
988 | size_t kwlen; | 988 | size_t kwlen; |
989 | struct mapper_tab *mt; | 989 | struct mapper_tab *mt; |
... | @@ -1020,6 +1020,26 @@ _fetch_fold (void *item, void *data) | ... | @@ -1020,6 +1020,26 @@ _fetch_fold (void *item, void *data) |
1020 | break; | 1020 | break; |
1021 | } | 1021 | } |
1022 | 1022 | ||
1023 | case resp_body: | ||
1024 | if (_mu_imap_list_element_is_string (elt, "[")) | ||
1025 | { | ||
1026 | env->state = resp_body_section; | ||
1027 | break; | ||
1028 | } | ||
1029 | else | ||
1030 | { | ||
1031 | env->mapper = _bodystructure_mapper; | ||
1032 | _free_fetch_response (env->resp); | ||
1033 | rc = alloc_response (&env->resp, MU_IMAP_FETCH_BODYSTRUCTURE); | ||
1034 | if (rc) | ||
1035 | { | ||
1036 | env->status = rc; | ||
1037 | return MU_ERR_FAILURE; | ||
1038 | } | ||
1039 | env->state = resp_val; | ||
1040 | } | ||
1041 | /* fall through */ | ||
1042 | |||
1023 | case resp_val: | 1043 | case resp_val: |
1024 | if (env->mapper) | 1044 | if (env->mapper) |
1025 | { | 1045 | { |
... | @@ -1034,16 +1054,6 @@ _fetch_fold (void *item, void *data) | ... | @@ -1034,16 +1054,6 @@ _fetch_fold (void *item, void *data) |
1034 | env->state = resp_kw; | 1054 | env->state = resp_kw; |
1035 | break; | 1055 | break; |
1036 | 1056 | ||
1037 | case resp_body: | ||
1038 | if (_mu_imap_list_element_is_string (elt, "[")) | ||
1039 | env->state = resp_body_section; | ||
1040 | else | ||
1041 | { | ||
1042 | env->mapper = _bodystructure_mapper; | ||
1043 | env->state = resp_val; | ||
1044 | } | ||
1045 | break; | ||
1046 | |||
1047 | case resp_body_section: | 1057 | case resp_body_section: |
1048 | if (elt->type != imap_eltype_string) | 1058 | if (elt->type != imap_eltype_string) |
1049 | { | 1059 | { | ... | ... |
... | @@ -39,21 +39,13 @@ | ... | @@ -39,21 +39,13 @@ |
39 | #include <mailutils/sys/imap.h> | 39 | #include <mailutils/sys/imap.h> |
40 | #include <mailutils/sys/folder.h> | 40 | #include <mailutils/sys/folder.h> |
41 | 41 | ||
42 | /* Placeholders. */ | ||
43 | #define _mu_imap_mailbox_init NULL | ||
44 | #define _mu_imaps_mailbox_init NULL | ||
45 | |||
46 | |||
47 | static void | 42 | static void |
48 | _mu_imap_folder_destroy (mu_folder_t folder) | 43 | _mu_imap_folder_destroy (mu_folder_t folder) |
49 | { | 44 | { |
50 | mu_imap_t imap = folder->data; | 45 | mu_imap_t imap = folder->data; |
51 | if (imap) | 46 | if (imap) |
52 | { | 47 | { |
53 | /* | 48 | mu_folder_close (folder); |
54 | mu_imap_logout (imap); | ||
55 | mu_imap_disconnect (imap); | ||
56 | */ | ||
57 | mu_imap_destroy (&imap); | 49 | mu_imap_destroy (&imap); |
58 | folder->data = imap; | 50 | folder->data = imap; |
59 | } | 51 | } |
... | @@ -90,13 +82,6 @@ _mu_folder_bad_callback (void *data, int code, size_t sdat, void *pdat) | ... | @@ -90,13 +82,6 @@ _mu_folder_bad_callback (void *data, int code, size_t sdat, void *pdat) |
90 | mu_error (_("This probably indicates a bug in Mailutils client code.")); | 82 | mu_error (_("This probably indicates a bug in Mailutils client code.")); |
91 | mu_error (_("Please, report that to <%s>."), PACKAGE_BUGREPORT); | 83 | mu_error (_("Please, report that to <%s>."), PACKAGE_BUGREPORT); |
92 | } | 84 | } |
93 | #if 0 | ||
94 | static void | ||
95 | _mu_folder_fetch_callback (void *data, int code, size_t sdat, void *pdat) | ||
96 | { | ||
97 | mu_folder_t folder = data; | ||
98 | } | ||
99 | #endif | ||
100 | 85 | ||
101 | /* Set up an IMAP(S) connection for this folder */ | 86 | /* Set up an IMAP(S) connection for this folder */ |
102 | static int | 87 | static int |
... | @@ -187,11 +172,6 @@ _mu_imap_folder_open (mu_folder_t folder, int flags) | ... | @@ -187,11 +172,6 @@ _mu_imap_folder_open (mu_folder_t folder, int flags) |
187 | mu_imap_register_callback_function (imap, MU_IMAP_CB_BAD, | 172 | mu_imap_register_callback_function (imap, MU_IMAP_CB_BAD, |
188 | _mu_folder_bad_callback, | 173 | _mu_folder_bad_callback, |
189 | folder); | 174 | folder); |
190 | #if 0 | ||
191 | mu_imap_register_callback_function (imap, MU_IMAP_CB_FETCH, | ||
192 | _mu_folder_fetch_callback, | ||
193 | folder); | ||
194 | #endif | ||
195 | rc = mu_imap_connect (imap); | 175 | rc = mu_imap_connect (imap); |
196 | if (rc) | 176 | if (rc) |
197 | { | 177 | { |
... | @@ -206,6 +186,32 @@ _mu_imap_folder_open (mu_folder_t folder, int flags) | ... | @@ -206,6 +186,32 @@ _mu_imap_folder_open (mu_folder_t folder, int flags) |
206 | return rc; | 186 | return rc; |
207 | } | 187 | } |
208 | 188 | ||
189 | #ifdef WITH_TLS | ||
190 | if (!tls && mu_imap_capability_test (imap, "STARTTLS", NULL) == 0) | ||
191 | { | ||
192 | size_t parmc = 0; | ||
193 | char **parmv = NULL; | ||
194 | |||
195 | tls = 1; | ||
196 | if (mu_url_sget_fvpairs (folder->url, &parmc, &parmv) == 0) | ||
197 | { | ||
198 | size_t i; | ||
199 | |||
200 | for (i = 0; i < parmc; i++) | ||
201 | { | ||
202 | if (strcmp (parmv[i], "notls") == 0) | ||
203 | tls = 0; | ||
204 | /*FIXME: | ||
205 | else if (strncmp (parmv[i], "auth=", 5) == 0) | ||
206 | */ | ||
207 | /* unrecognized arguments silently ignored */ | ||
208 | } | ||
209 | } | ||
210 | |||
211 | if (tls) | ||
212 | mu_imap_starttls (imap); | ||
213 | } | ||
214 | #endif | ||
209 | if (mu_imap_session_state (imap) == MU_IMAP_SESSION_NONAUTH) | 215 | if (mu_imap_session_state (imap) == MU_IMAP_SESSION_NONAUTH) |
210 | { | 216 | { |
211 | rc = mu_authority_authenticate (folder->authority); | 217 | rc = mu_authority_authenticate (folder->authority); |
... | @@ -217,7 +223,7 @@ _mu_imap_folder_open (mu_folder_t folder, int flags) | ... | @@ -217,7 +223,7 @@ _mu_imap_folder_open (mu_folder_t folder, int flags) |
217 | mu_folder_close (folder); | 223 | mu_folder_close (folder); |
218 | } | 224 | } |
219 | } | 225 | } |
220 | 226 | ||
221 | return rc; | 227 | return rc; |
222 | } | 228 | } |
223 | 229 | ||
... | @@ -551,7 +557,7 @@ static struct _mu_record _imap_record = | ... | @@ -551,7 +557,7 @@ static struct _mu_record _imap_record = |
551 | MU_IMAP_PRIO, | 557 | MU_IMAP_PRIO, |
552 | MU_IMAP_SCHEME, | 558 | MU_IMAP_SCHEME, |
553 | MU_RECORD_DEFAULT, | 559 | MU_RECORD_DEFAULT, |
554 | MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH, | 560 | MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM, |
555 | MU_URL_HOST, | 561 | MU_URL_HOST, |
556 | _mu_imap_url_init, /* url entry. */ | 562 | _mu_imap_url_init, /* url entry. */ |
557 | _mu_imap_mailbox_init, /* Mailbox entry. */ | 563 | _mu_imap_mailbox_init, /* Mailbox entry. */ |
... | @@ -576,7 +582,7 @@ static struct _mu_record _imaps_record = | ... | @@ -576,7 +582,7 @@ static struct _mu_record _imaps_record = |
576 | MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM, | 582 | MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM, |
577 | MU_URL_HOST, | 583 | MU_URL_HOST, |
578 | _mu_imaps_url_init, /* url entry. */ | 584 | _mu_imaps_url_init, /* url entry. */ |
579 | _mu_imaps_mailbox_init, /* Mailbox entry. */ | 585 | _mu_imap_mailbox_init, /* Mailbox entry. */ |
580 | NULL, /* Mailer entry. */ | 586 | NULL, /* Mailer entry. */ |
581 | _mu_imap_folder_init, /* Folder entry. */ | 587 | _mu_imap_folder_init, /* Folder entry. */ |
582 | NULL, /* No need for a back pointer. */ | 588 | NULL, /* No need for a back pointer. */ | ... | ... |
libproto/imap/mbox.c
0 → 100644
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment