attachment.c mbx_unix.c mime.c include/private/mime0.h
include/public/mime.h incorporate some changes by D.I.
Showing
5 changed files
with
60 additions
and
58 deletions
... | @@ -223,6 +223,8 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data) | ... | @@ -223,6 +223,8 @@ int message_unencapsulate(message_t msg, message_t *newmsg, void **data) |
223 | } | 223 | } |
224 | info->line_ndx = 0; | 224 | info->line_ndx = 0; |
225 | } | 225 | } |
226 | if ( info->line_ndx == MAX_HDR_LEN ) /* prevent overflow */ | ||
227 | info->line_ndx--; | ||
226 | info->ioffset++; | 228 | info->ioffset++; |
227 | info->nbytes--; | 229 | info->nbytes--; |
228 | cp++; | 230 | cp++; | ... | ... |
... | @@ -60,10 +60,6 @@ struct _mime | ... | @@ -60,10 +60,6 @@ struct _mime |
60 | int nmtp_parts; | 60 | int nmtp_parts; |
61 | struct _mime_part **mtp_parts; /* list of parts in the msg */ | 61 | struct _mime_part **mtp_parts; /* list of parts in the msg */ |
62 | 62 | ||
63 | int tmsgs; | ||
64 | int ncap_msgs; | ||
65 | struct _mime_part **cap_msgs; /* list of encapsulated msgs */ | ||
66 | |||
67 | /* parser state */ | 63 | /* parser state */ |
68 | char *boundary; | 64 | char *boundary; |
69 | char *cur_line; | 65 | char *cur_line; | ... | ... |
... | @@ -43,12 +43,14 @@ typedef struct _mime *mime_t; | ... | @@ -43,12 +43,14 @@ typedef struct _mime *mime_t; |
43 | 43 | ||
44 | int mime_create __P ((mime_t *pmime, message_t msg, int flags)); | 44 | int mime_create __P ((mime_t *pmime, message_t msg, int flags)); |
45 | void mime_destroy __P ((mime_t *pmime)); | 45 | void mime_destroy __P ((mime_t *pmime)); |
46 | int mime_is_multi_part __P ((mime_t mime)); | 46 | int mime_is_multipart __P ((mime_t mime)); |
47 | int mime_get_num_parts __P ((mime_t mime, int *nparts)); | ||
48 | |||
47 | int mime_get_part __P ((mime_t mime, int part, message_t *msg)); | 49 | int mime_get_part __P ((mime_t mime, int part, message_t *msg)); |
50 | |||
48 | int mime_add_part __P ((mime_t mime, message_t msg)); | 51 | int mime_add_part __P ((mime_t mime, message_t msg)); |
49 | int mime_get_num_parts __P ((mime_t mime, int *nparts)); | 52 | |
50 | int mime_get_message __P ((mime_t mime, message_t *msg)); | 53 | int mime_get_message __P ((mime_t mime, message_t *msg)); |
51 | int mime_unencapsulate __P ((mime_t mime, message_t msg, message_t *newmsg)); | ||
52 | 54 | ||
53 | #ifdef _cplusplus | 55 | #ifdef _cplusplus |
54 | } | 56 | } | ... | ... |
... | @@ -327,6 +327,10 @@ mailbox_unix_destroy (mailbox_t *pmbox) | ... | @@ -327,6 +327,10 @@ mailbox_unix_destroy (mailbox_t *pmbox) |
327 | /* destroy the url */ | 327 | /* destroy the url */ |
328 | if (mbox->url) | 328 | if (mbox->url) |
329 | url_destroy (&(mbox->url)); | 329 | url_destroy (&(mbox->url)); |
330 | if (mbox->locker) | ||
331 | locker_destroy (&(mbox->locker)); | ||
332 | if (mbox->auth) | ||
333 | auth_destroy (&(mbox->auth), (*pmbox)); | ||
330 | free (*pmbox); | 334 | free (*pmbox); |
331 | *pmbox = NULL; | 335 | *pmbox = NULL; |
332 | } | 336 | } | ... | ... |
... | @@ -38,43 +38,46 @@ | ... | @@ -38,43 +38,46 @@ |
38 | * Define mbx i/f for protocols that support mime parsing (IMAP). | 38 | * Define mbx i/f for protocols that support mime parsing (IMAP). |
39 | */ | 39 | */ |
40 | 40 | ||
41 | static int _mime_append_part(mime_t mime, message_t msg, int body_offset, int body_len, int encap_msg) | 41 | #define DIGEST_TYPE "Content-Type: message/rfc822" |
42 | |||
43 | static int _mime_is_multipart_digest(mime_t mime) | ||
44 | { | ||
45 | if ( mime->content_type ) | ||
46 | return(strncasecmp("multipart/digest", mime->content_type, strlen("multipart/digest")) ? 0: 1); | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static int _mime_append_part(mime_t mime, message_t msg, int body_offset, int body_len) | ||
42 | { | 51 | { |
43 | struct _mime_part *mime_part, **part_arr; | 52 | struct _mime_part *mime_part, **part_arr; |
44 | int ret; | 53 | int ret; |
54 | size_t size; | ||
45 | 55 | ||
46 | if ( ( mime_part = calloc(1, sizeof(*mime_part)) ) == NULL ) | 56 | if ( ( mime_part = calloc(1, sizeof(*mime_part)) ) == NULL ) |
47 | return ENOMEM; | 57 | return ENOMEM; |
48 | 58 | ||
49 | memcpy(mime_part->sig,"MIME", 4); | 59 | memcpy(mime_part->sig,"MIME", 4); |
50 | if ( encap_msg ) { | 60 | if ( mime->nmtp_parts >= mime->tparts ) { |
51 | if ( mime->ncap_msgs >= mime->tmsgs ) { | 61 | if ( ( part_arr = realloc(mime->mtp_parts, ( mime->tparts + 5 ) * sizeof(mime_part)) ) == NULL ) { |
52 | if ( ( part_arr = realloc(mime->cap_msgs, ( mime->tmsgs + 2 ) * sizeof(mime_part)) ) == NULL ) { | 62 | free(mime_part); |
53 | free(mime_part); | 63 | return ENOMEM; |
54 | return ENOMEM; | ||
55 | } | ||
56 | mime->cap_msgs = part_arr; | ||
57 | mime->tmsgs += 2; | ||
58 | } | ||
59 | mime->cap_msgs[mime->ncap_msgs++] = mime_part; | ||
60 | } | ||
61 | else { | ||
62 | if ( mime->nmtp_parts >= mime->tparts ) { | ||
63 | if ( ( part_arr = realloc(mime->mtp_parts, ( mime->tparts + 5 ) * sizeof(mime_part)) ) == NULL ) { | ||
64 | free(mime_part); | ||
65 | return ENOMEM; | ||
66 | } | ||
67 | mime->mtp_parts = part_arr; | ||
68 | mime->tparts += 5; | ||
69 | } | 64 | } |
70 | mime->mtp_parts[mime->nmtp_parts++] = mime_part; | 65 | mime->mtp_parts = part_arr; |
66 | mime->tparts += 5; | ||
71 | } | 67 | } |
68 | mime->mtp_parts[mime->nmtp_parts++] = mime_part; | ||
72 | if ( msg == NULL ) { | 69 | if ( msg == NULL ) { |
73 | if ( ( ret = header_create(&mime_part->hdr, mime->header_buf, mime->header_length, mime_part) ) != 0 ) { | 70 | if ( ( ret = header_create(&mime_part->hdr, mime->header_buf, mime->header_length, mime_part) ) != 0 ) { |
74 | free(mime_part); | 71 | free(mime_part); |
75 | return ret; | 72 | return ret; |
76 | } | 73 | } |
77 | mime->header_length = 0; | 74 | mime->header_length = 0; |
75 | if ( ( ret = header_get_value(mime_part->hdr, "Content-Type", NULL, 0, &size) ) != 0 || size == 0 ) { | ||
76 | if ( _mime_is_multipart_digest(mime) ) | ||
77 | header_set_value(mime_part->hdr, "Content-Type", "message/rfc822", 0, 0); | ||
78 | else | ||
79 | header_set_value(mime_part->hdr, "Content-Type", "text/plain", 0, 0); | ||
80 | } | ||
78 | } | 81 | } |
79 | mime_part->body_len = body_len; | 82 | mime_part->body_len = body_len; |
80 | mime_part->body_offset = body_offset; | 83 | mime_part->body_offset = body_offset; |
... | @@ -245,7 +248,7 @@ static int _mime_parse_mpart_message(mime_t mime) | ... | @@ -245,7 +248,7 @@ static int _mime_parse_mpart_message(mime_t mime) |
245 | mime->flags &= ~MIME_PARSER_HAVE_CR; | 248 | mime->flags &= ~MIME_PARSER_HAVE_CR; |
246 | body_length = mime->cur_offset - body_offset - mime->line_ndx + 1; | 249 | body_length = mime->cur_offset - body_offset - mime->line_ndx + 1; |
247 | if ( mime->header_length ) /* this skips the preamble */ | 250 | if ( mime->header_length ) /* this skips the preamble */ |
248 | _mime_append_part(mime, NULL, body_offset, body_length, FALSE ); | 251 | _mime_append_part(mime, NULL, body_offset, body_length); |
249 | if ( ( cp2 + blength + 2 < cp && !strncasecmp(cp2+2+blength, "--",2) ) || | 252 | if ( ( cp2 + blength + 2 < cp && !strncasecmp(cp2+2+blength, "--",2) ) || |
250 | !strncasecmp(cp2+blength, "--",2) ) { /* very last boundary */ | 253 | !strncasecmp(cp2+blength, "--",2) ) { /* very last boundary */ |
251 | mime->parser_state = MIME_STATE_BEGIN_LINE; | 254 | mime->parser_state = MIME_STATE_BEGIN_LINE; |
... | @@ -279,29 +282,28 @@ static int _mime_parse_mpart_message(mime_t mime) | ... | @@ -279,29 +282,28 @@ static int _mime_parse_mpart_message(mime_t mime) |
279 | nbytes--; | 282 | nbytes--; |
280 | cp++; | 283 | cp++; |
281 | } | 284 | } |
282 | if ( mime->flags & MIME_INCREAMENTAL_PARSER ) { | 285 | if ( mime->flags & MIME_INCREAMENTAL_PARSER ) { |
286 | /* | ||
287 | * can't really do this since returning EAGAIN will make the MUA think | ||
288 | * it should select on the messages stream fd. re-think this whole | ||
289 | * non-blocking thing..... | ||
290 | |||
283 | ret = EAGAIN; | 291 | ret = EAGAIN; |
284 | break; | 292 | break; |
293 | */ | ||
285 | } | 294 | } |
286 | } | 295 | } |
287 | mime->body_length = body_length; | 296 | mime->body_length = body_length; |
288 | mime->body_offset = body_offset; | 297 | mime->body_offset = body_offset; |
289 | if ( ret != EAGAIN ) { /* finished cleanup */ | 298 | if ( ret != EAGAIN ) { /* finished cleanup */ |
290 | if ( mime->header_length ) /* this skips the preamble */ | 299 | if ( mime->header_length ) /* this skips the preamble */ |
291 | _mime_append_part(mime, NULL, body_offset, body_length, FALSE ); | 300 | _mime_append_part(mime, NULL, body_offset, body_length); |
292 | mime->flags &= ~MIME_PARSER_ACTIVE; | 301 | mime->flags &= ~MIME_PARSER_ACTIVE; |
293 | mime->body_offset = mime->body_length = mime->header_length = 0; | 302 | mime->body_offset = mime->body_length = mime->header_length = 0; |
294 | } | 303 | } |
295 | return ret; | 304 | return ret; |
296 | } | 305 | } |
297 | 306 | ||
298 | static int _mime_message_fd(stream_t stream, int *fd) | ||
299 | { | ||
300 | struct _mime_part *mime_part = stream->owner; | ||
301 | |||
302 | return stream_get_fd(mime_part->mime->stream, fd); | ||
303 | } | ||
304 | |||
305 | static int _mime_message_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t *nbytes) | 307 | static int _mime_message_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t *nbytes) |
306 | { | 308 | { |
307 | struct _mime_part *mime_part = stream->owner; | 309 | struct _mime_part *mime_part = stream->owner; |
... | @@ -319,6 +321,13 @@ static int _mime_message_read(stream_t stream, char *buf, size_t buflen, off_t o | ... | @@ -319,6 +321,13 @@ static int _mime_message_read(stream_t stream, char *buf, size_t buflen, off_t o |
319 | return stream_read(mime_part->mime->stream, buf, read_len, mime_part->body_offset + off, nbytes ); | 321 | return stream_read(mime_part->mime->stream, buf, read_len, mime_part->body_offset + off, nbytes ); |
320 | } | 322 | } |
321 | 323 | ||
324 | static int _mime_message_fd(stream_t stream, int *fd) | ||
325 | { | ||
326 | struct _mime_part *mime_part = stream->owner; | ||
327 | |||
328 | return stream_get_fd(mime_part->mime->stream, fd); | ||
329 | } | ||
330 | |||
322 | static int _mime_new_message_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t *nbytes) | 331 | static int _mime_new_message_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t *nbytes) |
323 | { | 332 | { |
324 | (void)stream; (void)buf; (void)buflen; (void)off; | 333 | (void)stream; (void)buf; (void)buflen; (void)off; |
... | @@ -397,16 +406,7 @@ void mime_destroy(mime_t *pmime) | ... | @@ -397,16 +406,7 @@ void mime_destroy(mime_t *pmime) |
397 | mime_part = mime->mtp_parts[i]; | 406 | mime_part = mime->mtp_parts[i]; |
398 | if ( mime_part->msg ) | 407 | if ( mime_part->msg ) |
399 | message_destroy(&mime_part->msg, mime_part); | 408 | message_destroy(&mime_part->msg, mime_part); |
400 | else | 409 | else if ( mime_part->hdr ) |
401 | header_destroy(&mime_part->hdr, mime_part); | ||
402 | } | ||
403 | } | ||
404 | if ( mime->cap_msgs != NULL ) { | ||
405 | for ( i = 0; i < mime->ncap_msgs; i++ ) { | ||
406 | mime_part = mime->cap_msgs[i]; | ||
407 | if ( mime_part->msg ) | ||
408 | message_destroy(&mime_part->msg, mime_part); | ||
409 | else | ||
410 | header_destroy(&mime_part->hdr, mime_part); | 410 | header_destroy(&mime_part->hdr, mime_part); |
411 | } | 411 | } |
412 | } | 412 | } |
... | @@ -425,14 +425,6 @@ void mime_destroy(mime_t *pmime) | ... | @@ -425,14 +425,6 @@ void mime_destroy(mime_t *pmime) |
425 | } | 425 | } |
426 | } | 426 | } |
427 | 427 | ||
428 | int mime_is_multi_part(mime_t mime) | ||
429 | { | ||
430 | if ( mime->content_type ) | ||
431 | return(strncasecmp("multipart", mime->content_type, strlen("multipart")) ? 0: 1); | ||
432 | return 0; | ||
433 | } | ||
434 | |||
435 | |||
436 | int mime_get_part(mime_t mime, int part, message_t *msg) | 428 | int mime_get_part(mime_t mime, int part, message_t *msg) |
437 | { | 429 | { |
438 | int nmtp_parts, ret = 0; | 430 | int nmtp_parts, ret = 0; |
... | @@ -474,7 +466,7 @@ int mime_get_num_parts(mime_t mime, int *nmtp_parts) | ... | @@ -474,7 +466,7 @@ int mime_get_num_parts(mime_t mime, int *nmtp_parts) |
474 | int ret = 0; | 466 | int ret = 0; |
475 | 467 | ||
476 | if ( mime->nmtp_parts == 0 || mime->flags & MIME_PARSER_ACTIVE ) { | 468 | if ( mime->nmtp_parts == 0 || mime->flags & MIME_PARSER_ACTIVE ) { |
477 | if ( mime_is_multi_part(mime) ) { | 469 | if ( mime_is_multipart(mime) ) { |
478 | if ( ( ret = _mime_parse_mpart_message(mime) ) != 0 ) | 470 | if ( ( ret = _mime_parse_mpart_message(mime) ) != 0 ) |
479 | return(ret); | 471 | return(ret); |
480 | } else | 472 | } else |
... | @@ -489,7 +481,7 @@ int mime_add_part(mime_t mime, message_t msg) | ... | @@ -489,7 +481,7 @@ int mime_add_part(mime_t mime, message_t msg) |
489 | { | 481 | { |
490 | if ( mime == NULL || msg == NULL || ( mime->flags & MIME_NEW_MESSAGE ) == 0 ) | 482 | if ( mime == NULL || msg == NULL || ( mime->flags & MIME_NEW_MESSAGE ) == 0 ) |
491 | return EINVAL; | 483 | return EINVAL; |
492 | return _mime_append_part(mime, msg, 0, 0, FALSE); | 484 | return _mime_append_part(mime, msg, 0, 0); |
493 | } | 485 | } |
494 | 486 | ||
495 | int mime_get_message(mime_t mime, message_t *msg) | 487 | int mime_get_message(mime_t mime, message_t *msg) |
... | @@ -500,3 +492,9 @@ int mime_get_message(mime_t mime, message_t *msg) | ... | @@ -500,3 +492,9 @@ int mime_get_message(mime_t mime, message_t *msg) |
500 | return 0; | 492 | return 0; |
501 | } | 493 | } |
502 | 494 | ||
495 | int mime_is_multipart(mime_t mime) | ||
496 | { | ||
497 | if ( mime->content_type ) | ||
498 | return(strncasecmp("multipart", mime->content_type, strlen("multipart")) ? 0: 1); | ||
499 | return 0; | ||
500 | } | ... | ... |
-
Please register or sign in to post a comment