Commit 3e158c93 3e158c932500f9ddb94a5e0fddfb6bc8e1615cbe by Alain Magloire

Dave latest patch

1 parent dff80b59
1 2001-05-16 Dave Inglis
2
3 * mailbox/mime.c (_mime_parse_mpart): Better check for the
4 boundary.
5
1 2001-05-14 Sergey Poznyakoff 6 2001-05-14 Sergey Poznyakoff
2 7
3 * pop3d/user.c: After unsuccessful authorization frees cmd twice, 8 * pop3d/user.c: After unsuccessful authorization frees cmd twice,
...@@ -116,7 +121,7 @@ ...@@ -116,7 +121,7 @@
116 * pop3d/user.c: Cast the return of crypt(), since in may not be 121 * pop3d/user.c: Cast the return of crypt(), since in may not be
117 declare in <unistd.h>. 122 declare in <unistd.h>.
118 123
119 * lib/snprintf.c: Use only __STDC__ to detect <stdar.h> 124 * lib/snprintf.c: Use only __STDC__ to detect <stdarg.h>
120 * lib/snprintf.h: Use only __STDC__. 125 * lib/snprintf.h: Use only __STDC__.
121 126
122 * mail/mail.h: The global variable should be declare extern. 127 * mail/mail.h: The global variable should be declare extern.
......
1 There are many ways to authenticate to a server, to be flexible the
2 authentication process is provided by two objects @code{auth_t} and
3 @{ticket_t}. The @{auth_t} can implement different protocol like
4 APOP, MD5-AUTH, One Time Passwd etc .. By default if a mailbox
5 does not understand or know how to authenticate it falls back to
6 user/passwd authentication. The @{ticket_t} is away to
1 Mailboxes and Mailers provide a way to authenticate when the URL does not 7 Mailboxes and Mailers provide a way to authenticate when the URL does not
2 contain enough information. The default action is to call function 8 contain enough information. The default action is to call function
3 @code{auth_authenticate} who will get the @emph{user} and @emph{passwd} 9 @code{auth_authenticate} who will get the @emph{user} and @emph{passwd}
......
...@@ -489,7 +489,7 @@ imap4d_readline (FILE *fp) ...@@ -489,7 +489,7 @@ imap4d_readline (FILE *fp)
489 } 489 }
490 } 490 }
491 while (number > 0); 491 while (number > 0);
492 /* syslog (LOG_INFO, "readline: %s", line); */ 492 /* syslog (LOG_INFO, "readline: %s", line); */
493 return line; 493 return line;
494 } 494 }
495 495
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -60,12 +60,12 @@ struct _mime ...@@ -60,12 +60,12 @@ struct _mime
60 { 60 {
61 message_t msg; 61 message_t msg;
62 header_t hdrs; 62 header_t hdrs;
63 /*stream_t stream; */ 63 stream_t stream;
64 int flags; 64 int flags;
65 char *content_type; 65 char *content_type;
66 66
67 int tparts; 67 int tparts;
68 int nmtp_parts; 68 int nmtp_parts;
69 struct _mime_part **mtp_parts; /* list of parts in the msg */ 69 struct _mime_part **mtp_parts; /* list of parts in the msg */
70 char *boundary; 70 char *boundary;
71 int cur_offset; 71 int cur_offset;
...@@ -73,8 +73,8 @@ struct _mime ...@@ -73,8 +73,8 @@ struct _mime
73 int part_offset; 73 int part_offset;
74 int boundary_len; 74 int boundary_len;
75 int preamble; 75 int preamble;
76 int postamble; 76 int postamble;
77 /* parser state */ 77 /* parser state */
78 char *cur_line; 78 char *cur_line;
79 int line_ndx; 79 int line_ndx;
80 char *cur_buf; 80 char *cur_buf;
...@@ -92,6 +92,7 @@ struct _mime_part ...@@ -92,6 +92,7 @@ struct _mime_part
92 { 92 {
93 mime_t mime; 93 mime_t mime;
94 message_t msg; 94 message_t msg;
95 int body_created;
95 int offset; 96 int offset;
96 size_t len; 97 size_t len;
97 size_t lines; 98 size_t lines;
......
...@@ -408,6 +408,7 @@ mbox_close (mailbox_t mailbox) ...@@ -408,6 +408,7 @@ mbox_close (mailbox_t mailbox)
408 /* Make sure that we do not hold any file locking. */ 408 /* Make sure that we do not hold any file locking. */
409 locker_unlock (mailbox->locker); 409 locker_unlock (mailbox->locker);
410 410
411 #if 0
411 monitor_wrlock (mailbox->monitor); 412 monitor_wrlock (mailbox->monitor);
412 /* Before closing we need to remove all the messages 413 /* Before closing we need to remove all the messages
413 - to reclaim the memory 414 - to reclaim the memory
...@@ -434,6 +435,7 @@ mbox_close (mailbox_t mailbox) ...@@ -434,6 +435,7 @@ mbox_close (mailbox_t mailbox)
434 mud->uidvalidity = 0; 435 mud->uidvalidity = 0;
435 mud->uidnext = 0; 436 mud->uidnext = 0;
436 monitor_unlock (mailbox->monitor); 437 monitor_unlock (mailbox->monitor);
438 #endif
437 return stream_close (mailbox->stream); 439 return stream_close (mailbox->stream);
438 } 440 }
439 441
......
...@@ -208,7 +208,7 @@ _mime_setup_buffers(mime_t mime) ...@@ -208,7 +208,7 @@ _mime_setup_buffers(mime_t mime)
208 if ( mime->cur_buf == NULL && ( mime->cur_buf = malloc( mime->buf_size ) ) == NULL ) { 208 if ( mime->cur_buf == NULL && ( mime->cur_buf = malloc( mime->buf_size ) ) == NULL ) {
209 return ENOMEM; 209 return ENOMEM;
210 } 210 }
211 if ( mime->cur_line == NULL && ( mime->cur_line = malloc( MIME_MAX_HDR_LEN ) ) == NULL ) { 211 if ( mime->cur_line == NULL && ( mime->cur_line = calloc( MIME_MAX_HDR_LEN, 1 ) ) == NULL ) {
212 free(mime->cur_buf); 212 free(mime->cur_buf);
213 return ENOMEM; 213 return ENOMEM;
214 } 214 }
...@@ -235,8 +235,6 @@ _mime_parse_mpart_message(mime_t mime) ...@@ -235,8 +235,6 @@ _mime_parse_mpart_message(mime_t mime)
235 char *cp, *cp2; 235 char *cp, *cp2;
236 int blength, mb_length, mb_offset, mb_lines, ret; 236 int blength, mb_length, mb_offset, mb_lines, ret;
237 size_t nbytes; 237 size_t nbytes;
238 body_t body;
239 stream_t stream;
240 238
241 if ( !(mime->flags & MIME_PARSER_ACTIVE) ) { 239 if ( !(mime->flags & MIME_PARSER_ACTIVE) ) {
242 char *boundary; 240 char *boundary;
...@@ -258,12 +256,9 @@ _mime_parse_mpart_message(mime_t mime) ...@@ -258,12 +256,9 @@ _mime_parse_mpart_message(mime_t mime)
258 mb_length = mime->body_length; 256 mb_length = mime->body_length;
259 mb_offset = mime->body_offset; 257 mb_offset = mime->body_offset;
260 mb_lines = mime->body_lines; 258 mb_lines = mime->body_lines;
259 blength = strlen(mime->boundary);
261 260
262 body = NULL; 261 while ( ( ret = stream_read(mime->stream, mime->cur_buf, mime->buf_size, mime->cur_offset, &nbytes) ) == 0 && nbytes ) {
263 stream = NULL;
264 message_get_body (mime->msg, &body);
265 body_get_stream (body, &stream);
266 while ( ( ret = stream_read(stream, mime->cur_buf, mime->buf_size, mime->cur_offset, &nbytes) ) == 0 && nbytes ) {
267 cp = mime->cur_buf; 262 cp = mime->cur_buf;
268 while ( nbytes ) { 263 while ( nbytes ) {
269 mime->cur_line[mime->line_ndx] = *cp; 264 mime->cur_line[mime->line_ndx] = *cp;
...@@ -276,7 +271,6 @@ _mime_parse_mpart_message(mime_t mime) ...@@ -276,7 +271,6 @@ _mime_parse_mpart_message(mime_t mime)
276 break; 271 break;
277 case MIME_STATE_SCAN_BOUNDARY: 272 case MIME_STATE_SCAN_BOUNDARY:
278 cp2 = mime->cur_line[0] == '\n' ? mime->cur_line + 1 : mime->cur_line; 273 cp2 = mime->cur_line[0] == '\n' ? mime->cur_line + 1 : mime->cur_line;
279 blength = strlen(mime->boundary);
280 if ( mime->header_length ) 274 if ( mime->header_length )
281 mb_lines++; 275 mb_lines++;
282 if ( mime->line_ndx >= blength ) { 276 if ( mime->line_ndx >= blength ) {
...@@ -287,8 +281,10 @@ _mime_parse_mpart_message(mime_t mime) ...@@ -287,8 +281,10 @@ _mime_parse_mpart_message(mime_t mime)
287 mb_length = mime->cur_offset - mb_offset - mime->line_ndx + 1; 281 mb_length = mime->cur_offset - mb_offset - mime->line_ndx + 1;
288 if ( mime->header_length ) /* this skips the preamble */ 282 if ( mime->header_length ) /* this skips the preamble */
289 _mime_append_part(mime, NULL, mb_offset, mb_length, mb_lines); 283 _mime_append_part(mime, NULL, mb_offset, mb_length, mb_lines);
290 if ( ( cp2 + blength + 2 < cp && !strncasecmp(cp2+blength, "--",2) ) || 284 if ( ( &mime->cur_line[mime->line_ndx] - cp2 - 1 > blength
291 !strncasecmp(cp2+blength+2, "--",2) ) { /* very last boundary */ 285 && !strncasecmp(cp2+blength+2, "--",2) )
286 || ( &mime->cur_line[mime->line_ndx] - cp2 - 1 == blength
287 && !strncasecmp(cp2+blength, "--",2) ) ) { /* last boundary */
292 mime->parser_state = MIME_STATE_BEGIN_LINE; 288 mime->parser_state = MIME_STATE_BEGIN_LINE;
293 mime->header_length = 0; 289 mime->header_length = 0;
294 break; 290 break;
...@@ -353,11 +349,7 @@ _mimepart_body_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t ...@@ -353,11 +349,7 @@ _mimepart_body_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t
353 return 0; 349 return 0;
354 read_len = (buflen <= read_len)? buflen : read_len; 350 read_len = (buflen <= read_len)? buflen : read_len;
355 351
356 body = NULL; 352 return stream_read(mime_part->mime->stream, buf, read_len, mime_part->offset + off, nbytes );
357 stream = NULL;
358 message_get_body (mime_part->mime->msg, &body);
359 body_get_stream (body, &stream);
360 return stream_read(stream, buf, read_len, mime_part->offset + off, nbytes );
361 } 353 }
362 354
363 static int 355 static int
...@@ -367,11 +359,7 @@ _mimepart_body_fd(stream_t stream, int *fd) ...@@ -367,11 +359,7 @@ _mimepart_body_fd(stream_t stream, int *fd)
367 message_t msg = body_get_owner(body); 359 message_t msg = body_get_owner(body);
368 struct _mime_part *mime_part = message_get_owner(msg); 360 struct _mime_part *mime_part = message_get_owner(msg);
369 361
370 body = NULL; 362 return stream_get_fd(mime_part->mime->stream, fd);
371 stream = NULL;
372 message_get_body (mime_part->mime->msg, &body);
373 body_get_stream (body, &stream);
374 return stream_get_fd(stream, fd);
375 } 363 }
376 364
377 static int 365 static int
...@@ -412,7 +400,7 @@ _mime_set_content_type(mime_t mime) ...@@ -412,7 +400,7 @@ _mime_set_content_type(mime_t mime)
412 /* Delayed the creation of the header 'til they create the final message via 400 /* Delayed the creation of the header 'til they create the final message via
413 mime_get_message() */ 401 mime_get_message() */
414 if (mime->hdrs == NULL) 402 if (mime->hdrs == NULL)
415 return 0; 403 return 0;
416 if ( mime->nmtp_parts > 1 ) { 404 if ( mime->nmtp_parts > 1 ) {
417 if ( mime->flags & MIME_ADDED_MULTIPART_CT ) 405 if ( mime->flags & MIME_ADDED_MULTIPART_CT )
418 return 0; 406 return 0;
...@@ -594,6 +582,7 @@ mime_create(mime_t *pmime, message_t msg, int flags) ...@@ -594,6 +582,7 @@ mime_create(mime_t *pmime, message_t msg, int flags)
594 mime_t mime = NULL; 582 mime_t mime = NULL;
595 int ret = 0; 583 int ret = 0;
596 size_t size; 584 size_t size;
585 body_t body;
597 586
598 if (pmime == NULL) 587 if (pmime == NULL)
599 return EINVAL; 588 return EINVAL;
...@@ -615,6 +604,8 @@ mime_create(mime_t *pmime, message_t msg, int flags) ...@@ -615,6 +604,8 @@ mime_create(mime_t *pmime, message_t msg, int flags)
615 if (ret == 0 ) { 604 if (ret == 0 ) {
616 mime->msg = msg; 605 mime->msg = msg;
617 mime->buf_size = MIME_DFLT_BUF_SIZE; 606 mime->buf_size = MIME_DFLT_BUF_SIZE;
607 message_get_body(msg, &body);
608 body_get_stream(body, &(mime->stream));
618 } 609 }
619 } 610 }
620 } 611 }
...@@ -686,7 +677,7 @@ mime_get_part(mime_t mime, size_t part, message_t *msg) ...@@ -686,7 +677,7 @@ mime_get_part(mime_t mime, size_t part, message_t *msg)
686 *msg = mime->msg; 677 *msg = mime->msg;
687 else { 678 else {
688 mime_part = mime->mtp_parts[part-1]; 679 mime_part = mime->mtp_parts[part-1];
689 if ( ( ret = body_create(&body, mime_part->msg) ) == 0 ) { 680 if ( !mime_part->body_created && ( ret = body_create(&body, mime_part->msg) ) == 0 ) {
690 body_set_size (body, _mimepart_body_size, mime_part->msg); 681 body_set_size (body, _mimepart_body_size, mime_part->msg);
691 body_set_lines (body, _mimepart_body_lines, mime_part->msg); 682 body_set_lines (body, _mimepart_body_lines, mime_part->msg);
692 if ( ( ret = stream_create(&stream, MU_STREAM_READ, body) ) == 0 ) { 683 if ( ( ret = stream_create(&stream, MU_STREAM_READ, body) ) == 0 ) {
...@@ -694,10 +685,10 @@ mime_get_part(mime_t mime, size_t part, message_t *msg) ...@@ -694,10 +685,10 @@ mime_get_part(mime_t mime, size_t part, message_t *msg)
694 stream_set_fd(stream, _mimepart_body_fd, body); 685 stream_set_fd(stream, _mimepart_body_fd, body);
695 body_set_stream(body, stream, mime_part->msg); 686 body_set_stream(body, stream, mime_part->msg);
696 message_set_body(mime_part->msg, body, mime_part); 687 message_set_body(mime_part->msg, body, mime_part);
697 *msg = mime_part->msg; 688 mime_part->body_created = 1;
698 return 0;
699 } 689 }
700 } 690 }
691 *msg = mime_part->msg;
701 } 692 }
702 } 693 }
703 return ret; 694 return ret;
...@@ -764,6 +755,7 @@ mime_get_message(mime_t mime, message_t *msg) ...@@ -764,6 +755,7 @@ mime_get_message(mime_t mime, message_t *msg)
764 } 755 }
765 } 756 }
766 message_destroy(&(mime->msg), mime); 757 message_destroy(&(mime->msg), mime);
758 mime->msg = NULL;
767 } 759 }
768 } 760 }
769 if ( ret == 0 ) 761 if ( ret == 0 )
......