General bug fixes to get Imap working. It is getting good but still more
general cleanup need to be done.
Showing
5 changed files
with
83 additions
and
10 deletions
1 | 2001-02-20 Alain Magloire | ||
2 | |||
3 | * mailbox/mailbox.c (mailbox_set_ticket mailbox_set_authority | ||
4 | mailbox_set_stream) : Those objects are now part of th folder | ||
5 | if a folder is attached to the mailbox. | ||
6 | * mailbox/mbx_imap.c (imap_message_read imap_body_read) : | ||
7 | If offset == 0, reset the lines to 0. | ||
8 | |||
9 | 2001-02-19 Alain Magloire | ||
10 | |||
11 | * mailbox/mbx_pop.c (pop_body_read) : Move the CHECK_BUSY higher | ||
12 | it should be the first thing done. If the state is POP_NO_STATE | ||
13 | reset the offset and the size to 0 i.e we are starting fresh. | ||
14 | (pop_header_read) : Likewise. | ||
15 | (pop_message_read) : Likewise. | ||
16 | * mailbox/stream.c (stream_write) : Don't call stream_flush(). | ||
17 | |||
1 | 2001-02-04 Alain Magloire | 18 | 2001-02-04 Alain Magloire |
2 | 19 | ||
3 | * mailbox/message.c (message_get_uid) : Add message_get_uid() for | 20 | * mailbox/message.c (message_get_uid) : Add message_get_uid() for | ... | ... |
... | @@ -1150,6 +1150,13 @@ imap_flags (f_imap_t f_imap, char **ptr) | ... | @@ -1150,6 +1150,13 @@ imap_flags (f_imap_t f_imap, char **ptr) |
1150 | else | 1150 | else |
1151 | f_imap->flags |= MU_ATTRIBUTE_DRAFT; | 1151 | f_imap->flags |= MU_ATTRIBUTE_DRAFT; |
1152 | } | 1152 | } |
1153 | else if (strcasecmp (flag, "\\Read") == 0) | ||
1154 | { | ||
1155 | if (msg_imap) | ||
1156 | msg_imap->flags |= MU_ATTRIBUTE_READ; | ||
1157 | else | ||
1158 | f_imap->flags |= MU_ATTRIBUTE_READ; | ||
1159 | } | ||
1153 | } | 1160 | } |
1154 | return 0; | 1161 | return 0; |
1155 | } | 1162 | } |
... | @@ -1260,12 +1267,20 @@ imap_fetch (f_imap_t f_imap) | ... | @@ -1260,12 +1267,20 @@ imap_fetch (f_imap_t f_imap) |
1260 | { | 1267 | { |
1261 | status = imap_internaldate (f_imap, &sp); | 1268 | status = imap_internaldate (f_imap, &sp); |
1262 | } | 1269 | } |
1263 | else if (strncmp (command, "RFC822.SIZE", 10) == 0) | 1270 | else if (strncmp (command, "RFC822", 10) == 0) |
1264 | { | 1271 | { |
1265 | imap_token (command, &sp); | 1272 | if (*sp == '.') |
1266 | if (f_imap->callback.msg_imap) | 1273 | { |
1267 | f_imap->callback.msg_imap->message_size = strtoul (command, | 1274 | sp++; |
1268 | NULL, 10); | 1275 | imap_token (command, &sp); |
1276 | if (strcasecmp (command, "SIZE") == 0) | ||
1277 | { | ||
1278 | imap_token (command, &sp); | ||
1279 | if (f_imap->callback.msg_imap) | ||
1280 | f_imap->callback.msg_imap->message_size = | ||
1281 | strtoul (command, NULL, 10); | ||
1282 | } | ||
1283 | } | ||
1269 | } | 1284 | } |
1270 | else if (strncmp (command, "UID", 3) == 0) | 1285 | else if (strncmp (command, "UID", 3) == 0) |
1271 | { | 1286 | { |
... | @@ -1281,6 +1296,7 @@ static int | ... | @@ -1281,6 +1296,7 @@ static int |
1281 | imap_token (char *buf, char **ptr) | 1296 | imap_token (char *buf, char **ptr) |
1282 | { | 1297 | { |
1283 | char *start = *ptr; | 1298 | char *start = *ptr; |
1299 | /* Skip leading space. */ | ||
1284 | while (**ptr && **ptr == ' ') | 1300 | while (**ptr && **ptr == ' ') |
1285 | (*ptr)++; | 1301 | (*ptr)++; |
1286 | for (; **ptr; (*ptr)++, buf++) | 1302 | for (; **ptr; (*ptr)++, buf++) |
... | @@ -1297,6 +1313,9 @@ imap_token (char *buf, char **ptr) | ... | @@ -1297,6 +1313,9 @@ imap_token (char *buf, char **ptr) |
1297 | *buf = **ptr; | 1313 | *buf = **ptr; |
1298 | } | 1314 | } |
1299 | *buf = '\0'; | 1315 | *buf = '\0'; |
1316 | /* Skip tail space. */ | ||
1317 | while (**ptr && **ptr == ' ') | ||
1318 | (*ptr)++; | ||
1300 | return *ptr - start;; | 1319 | return *ptr - start;; |
1301 | } | 1320 | } |
1302 | 1321 | ... | ... |
... | @@ -424,9 +424,11 @@ header_get_value (header_t header, const char *name, char *buffer, | ... | @@ -424,9 +424,11 @@ header_get_value (header_t header, const char *name, char *buffer, |
424 | buflen = (len < buflen) ? len : buflen; | 424 | buflen = (len < buflen) ? len : buflen; |
425 | memcpy (buffer, buf, buflen); | 425 | memcpy (buffer, buf, buflen); |
426 | buffer[buflen] = '\0'; | 426 | buffer[buflen] = '\0'; |
427 | if (pn) | ||
428 | *pn = buflen; | ||
429 | } | 427 | } |
428 | else | ||
429 | buflen = len; | ||
430 | if (pn) | ||
431 | *pn = buflen; | ||
430 | } | 432 | } |
431 | return err; | 433 | return err; |
432 | } | 434 | } | ... | ... |
... | @@ -308,6 +308,8 @@ mailbox_set_authority (mailbox_t mbox, authority_t authority) | ... | @@ -308,6 +308,8 @@ mailbox_set_authority (mailbox_t mbox, authority_t authority) |
308 | { | 308 | { |
309 | if (mbox == NULL) | 309 | if (mbox == NULL) |
310 | return EINVAL; | 310 | return EINVAL; |
311 | if (mbox->folder) | ||
312 | return folder_set_authority (mbox->folder, authority); | ||
311 | if (mbox->authority) | 313 | if (mbox->authority) |
312 | authority_destroy (&(mbox->authority), mbox); | 314 | authority_destroy (&(mbox->authority), mbox); |
313 | mbox->authority = authority; | 315 | mbox->authority = authority; |
... | @@ -319,6 +321,8 @@ mailbox_get_authority (mailbox_t mbox, authority_t *pauthority) | ... | @@ -319,6 +321,8 @@ mailbox_get_authority (mailbox_t mbox, authority_t *pauthority) |
319 | { | 321 | { |
320 | if (mbox == NULL || pauthority == NULL) | 322 | if (mbox == NULL || pauthority == NULL) |
321 | return EINVAL; | 323 | return EINVAL; |
324 | if (mbox->folder) | ||
325 | return folder_get_authority (mbox->folder, pauthority); | ||
322 | *pauthority = mbox->authority; | 326 | *pauthority = mbox->authority; |
323 | return 0; | 327 | return 0; |
324 | } | 328 | } |
... | @@ -328,6 +332,8 @@ mailbox_set_ticket (mailbox_t mbox, ticket_t ticket) | ... | @@ -328,6 +332,8 @@ mailbox_set_ticket (mailbox_t mbox, ticket_t ticket) |
328 | { | 332 | { |
329 | if (mbox == NULL) | 333 | if (mbox == NULL) |
330 | return EINVAL; | 334 | return EINVAL; |
335 | if (mbox->folder) | ||
336 | return folder_set_ticket (mbox->folder, ticket); | ||
331 | if (mbox->ticket) | 337 | if (mbox->ticket) |
332 | ticket_destroy (&(mbox->ticket), mbox); | 338 | ticket_destroy (&(mbox->ticket), mbox); |
333 | mbox->ticket = ticket; | 339 | mbox->ticket = ticket; |
... | @@ -339,6 +345,8 @@ mailbox_get_ticket (mailbox_t mbox, ticket_t *pticket) | ... | @@ -339,6 +345,8 @@ mailbox_get_ticket (mailbox_t mbox, ticket_t *pticket) |
339 | { | 345 | { |
340 | if (mbox == NULL || pticket == NULL) | 346 | if (mbox == NULL || pticket == NULL) |
341 | return EINVAL; | 347 | return EINVAL; |
348 | if (mbox->folder) | ||
349 | return folder_get_ticket (mbox->folder, pticket); | ||
342 | *pticket = mbox->ticket; | 350 | *pticket = mbox->ticket; |
343 | return 0; | 351 | return 0; |
344 | } | 352 | } |
... | @@ -348,6 +356,8 @@ mailbox_set_stream (mailbox_t mbox, stream_t stream) | ... | @@ -348,6 +356,8 @@ mailbox_set_stream (mailbox_t mbox, stream_t stream) |
348 | { | 356 | { |
349 | if (mbox == NULL) | 357 | if (mbox == NULL) |
350 | return EINVAL; | 358 | return EINVAL; |
359 | if (mbox->folder) | ||
360 | return folder_set_stream (mbox->folder, stream); | ||
351 | if (mbox->stream) | 361 | if (mbox->stream) |
352 | stream_destroy (&(mbox->stream), mbox); | 362 | stream_destroy (&(mbox->stream), mbox); |
353 | mbox->stream = stream; | 363 | mbox->stream = stream; |
... | @@ -359,6 +369,8 @@ mailbox_get_stream (mailbox_t mbox, stream_t *pstream) | ... | @@ -359,6 +369,8 @@ mailbox_get_stream (mailbox_t mbox, stream_t *pstream) |
359 | { | 369 | { |
360 | if (mbox == NULL || pstream) | 370 | if (mbox == NULL || pstream) |
361 | return EINVAL; | 371 | return EINVAL; |
372 | if (mbox->folder) | ||
373 | return folder_get_stream (mbox->folder, pstream); | ||
362 | *pstream = mbox->stream; | 374 | *pstream = mbox->stream; |
363 | return 0; | 375 | return 0; |
364 | } | 376 | } | ... | ... |
... | @@ -649,6 +649,10 @@ imap_message_read (stream_t stream, char *buffer, size_t buflen, | ... | @@ -649,6 +649,10 @@ imap_message_read (stream_t stream, char *buffer, size_t buflen, |
649 | m_imap_t m_imap = msg_imap->m_imap; | 649 | m_imap_t m_imap = msg_imap->m_imap; |
650 | f_imap_t f_imap = m_imap->f_imap; | 650 | f_imap_t f_imap = m_imap->f_imap; |
651 | 651 | ||
652 | /* Start over. */ | ||
653 | if (offset == 0) | ||
654 | msg_imap->message_lines = 0; | ||
655 | |||
652 | /* Select first. */ | 656 | /* Select first. */ |
653 | if (f_imap->state == IMAP_NO_STATE) | 657 | if (f_imap->state == IMAP_NO_STATE) |
654 | { | 658 | { |
... | @@ -1007,8 +1011,10 @@ imap_attr_set_flags (attribute_t attribute, int flags) | ... | @@ -1007,8 +1011,10 @@ imap_attr_set_flags (attribute_t attribute, int flags) |
1007 | { | 1011 | { |
1008 | status = imap_writeline (f_imap, "g%d STORE %d +FLAGS.SILENT (%s %s %s %s)\r\n", | 1012 | status = imap_writeline (f_imap, "g%d STORE %d +FLAGS.SILENT (%s %s %s %s)\r\n", |
1009 | f_imap->seq++, msg_imap->num, | 1013 | f_imap->seq++, msg_imap->num, |
1010 | (flags & MU_ATTRIBUTE_SEEN) ? "\\Seen" : "", | ||
1011 | (flags & MU_ATTRIBUTE_ANSWERED) ? "\\Answered" : "", | 1014 | (flags & MU_ATTRIBUTE_ANSWERED) ? "\\Answered" : "", |
1015 | (flags & MU_ATTRIBUTE_RECENT) ? "\\Recent" : "", | ||
1016 | (flags & MU_ATTRIBUTE_READ) ? "\\Read" : "", | ||
1017 | (flags & MU_ATTRIBUTE_SEEN) ? "\\Seen" : "", | ||
1012 | (flags & MU_ATTRIBUTE_DRAFT) ? "\\Draft" : "", | 1018 | (flags & MU_ATTRIBUTE_DRAFT) ? "\\Draft" : "", |
1013 | (flags & MU_ATTRIBUTE_FLAGGED) ? "\\Flagged" : ""); | 1019 | (flags & MU_ATTRIBUTE_FLAGGED) ? "\\Flagged" : ""); |
1014 | CHECK_ERROR (f_imap, status); | 1020 | CHECK_ERROR (f_imap, status); |
... | @@ -1128,6 +1134,10 @@ imap_header_read (header_t header, char *buffer, size_t buflen, off_t offset, | ... | @@ -1128,6 +1134,10 @@ imap_header_read (header_t header, char *buffer, size_t buflen, off_t offset, |
1128 | m_imap_t m_imap = msg_imap->m_imap; | 1134 | m_imap_t m_imap = msg_imap->m_imap; |
1129 | f_imap_t f_imap = m_imap->f_imap; | 1135 | f_imap_t f_imap = m_imap->f_imap; |
1130 | 1136 | ||
1137 | /* Start over. */ | ||
1138 | if (offset == 0) | ||
1139 | msg_imap->header_lines = 0; | ||
1140 | |||
1131 | /* Select first. */ | 1141 | /* Select first. */ |
1132 | if (f_imap->state == IMAP_NO_STATE) | 1142 | if (f_imap->state == IMAP_NO_STATE) |
1133 | { | 1143 | { |
... | @@ -1168,7 +1178,15 @@ imap_body_size (body_t body, size_t *psize) | ... | @@ -1168,7 +1178,15 @@ imap_body_size (body_t body, size_t *psize) |
1168 | message_t msg = body_get_owner (body); | 1178 | message_t msg = body_get_owner (body); |
1169 | msg_imap_t msg_imap = message_get_owner (msg); | 1179 | msg_imap_t msg_imap = message_get_owner (msg); |
1170 | if (psize && msg_imap) | 1180 | if (psize && msg_imap) |
1171 | *psize = msg_imap->body_size; | 1181 | { |
1182 | if (msg_imap->body_size) | ||
1183 | *psize = msg_imap->body_size; | ||
1184 | else if (msg_imap->message_size) | ||
1185 | *psize = msg_imap->message_size | ||
1186 | - (msg_imap->header_size + msg_imap->header_lines); | ||
1187 | else | ||
1188 | *psize = 0; | ||
1189 | } | ||
1172 | return 0; | 1190 | return 0; |
1173 | } | 1191 | } |
1174 | 1192 | ||
... | @@ -1200,7 +1218,7 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset, | ... | @@ -1200,7 +1218,7 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset, |
1200 | example "\n" to retrieve from the server, IMAP will transform this to | 1218 | example "\n" to retrieve from the server, IMAP will transform this to |
1201 | "\r\n" and since you ask for only 1, the server will send '\r' only. | 1219 | "\r\n" and since you ask for only 1, the server will send '\r' only. |
1202 | And ... '\r' will be stripped by (imap_readline()) the number of char | 1220 | And ... '\r' will be stripped by (imap_readline()) the number of char |
1203 | read will be 0 which means we're done .... sigh ... So we guard to at | 1221 | read will be 0 which means we're done .... sigh ... So we guard by at |
1204 | least ask for 2 chars. */ | 1222 | least ask for 2 chars. */ |
1205 | if (buflen == 1) | 1223 | if (buflen == 1) |
1206 | { | 1224 | { |
... | @@ -1208,6 +1226,11 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset, | ... | @@ -1208,6 +1226,11 @@ imap_body_read (stream_t stream, char *buffer, size_t buflen, off_t offset, |
1208 | buffer = newbuf; | 1226 | buffer = newbuf; |
1209 | buflen = 2; | 1227 | buflen = 2; |
1210 | } | 1228 | } |
1229 | |||
1230 | /* Start over. */ | ||
1231 | if (offset == 0) | ||
1232 | msg_imap->body_lines = 0; | ||
1233 | |||
1211 | /* Select first. */ | 1234 | /* Select first. */ |
1212 | if (f_imap->state == IMAP_NO_STATE) | 1235 | if (f_imap->state == IMAP_NO_STATE) |
1213 | { | 1236 | { | ... | ... |
-
Please register or sign in to post a comment