Commit 3e158c93 3e158c932500f9ddb94a5e0fddfb6bc8e1615cbe by Alain Magloire

Dave latest patch

1 parent dff80b59
2001-05-16 Dave Inglis
* mailbox/mime.c (_mime_parse_mpart): Better check for the
boundary.
2001-05-14 Sergey Poznyakoff
* pop3d/user.c: After unsuccessful authorization frees cmd twice,
......@@ -116,7 +121,7 @@
* pop3d/user.c: Cast the return of crypt(), since in may not be
declare in <unistd.h>.
* lib/snprintf.c: Use only __STDC__ to detect <stdar.h>
* lib/snprintf.c: Use only __STDC__ to detect <stdarg.h>
* lib/snprintf.h: Use only __STDC__.
* mail/mail.h: The global variable should be declare extern.
......
There are many ways to authenticate to a server, to be flexible the
authentication process is provided by two objects @code{auth_t} and
@{ticket_t}. The @{auth_t} can implement different protocol like
APOP, MD5-AUTH, One Time Passwd etc .. By default if a mailbox
does not understand or know how to authenticate it falls back to
user/passwd authentication. The @{ticket_t} is away to
Mailboxes and Mailers provide a way to authenticate when the URL does not
contain enough information. The default action is to call function
@code{auth_authenticate} who will get the @emph{user} and @emph{passwd}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
......@@ -60,7 +60,7 @@ struct _mime
{
message_t msg;
header_t hdrs;
/*stream_t stream; */
stream_t stream;
int flags;
char *content_type;
......@@ -92,6 +92,7 @@ struct _mime_part
{
mime_t mime;
message_t msg;
int body_created;
int offset;
size_t len;
size_t lines;
......
......@@ -408,6 +408,7 @@ mbox_close (mailbox_t mailbox)
/* Make sure that we do not hold any file locking. */
locker_unlock (mailbox->locker);
#if 0
monitor_wrlock (mailbox->monitor);
/* Before closing we need to remove all the messages
- to reclaim the memory
......@@ -434,6 +435,7 @@ mbox_close (mailbox_t mailbox)
mud->uidvalidity = 0;
mud->uidnext = 0;
monitor_unlock (mailbox->monitor);
#endif
return stream_close (mailbox->stream);
}
......
......@@ -208,7 +208,7 @@ _mime_setup_buffers(mime_t mime)
if ( mime->cur_buf == NULL && ( mime->cur_buf = malloc( mime->buf_size ) ) == NULL ) {
return ENOMEM;
}
if ( mime->cur_line == NULL && ( mime->cur_line = malloc( MIME_MAX_HDR_LEN ) ) == NULL ) {
if ( mime->cur_line == NULL && ( mime->cur_line = calloc( MIME_MAX_HDR_LEN, 1 ) ) == NULL ) {
free(mime->cur_buf);
return ENOMEM;
}
......@@ -235,8 +235,6 @@ _mime_parse_mpart_message(mime_t mime)
char *cp, *cp2;
int blength, mb_length, mb_offset, mb_lines, ret;
size_t nbytes;
body_t body;
stream_t stream;
if ( !(mime->flags & MIME_PARSER_ACTIVE) ) {
char *boundary;
......@@ -258,12 +256,9 @@ _mime_parse_mpart_message(mime_t mime)
mb_length = mime->body_length;
mb_offset = mime->body_offset;
mb_lines = mime->body_lines;
blength = strlen(mime->boundary);
body = NULL;
stream = NULL;
message_get_body (mime->msg, &body);
body_get_stream (body, &stream);
while ( ( ret = stream_read(stream, mime->cur_buf, mime->buf_size, mime->cur_offset, &nbytes) ) == 0 && nbytes ) {
while ( ( ret = stream_read(mime->stream, mime->cur_buf, mime->buf_size, mime->cur_offset, &nbytes) ) == 0 && nbytes ) {
cp = mime->cur_buf;
while ( nbytes ) {
mime->cur_line[mime->line_ndx] = *cp;
......@@ -276,7 +271,6 @@ _mime_parse_mpart_message(mime_t mime)
break;
case MIME_STATE_SCAN_BOUNDARY:
cp2 = mime->cur_line[0] == '\n' ? mime->cur_line + 1 : mime->cur_line;
blength = strlen(mime->boundary);
if ( mime->header_length )
mb_lines++;
if ( mime->line_ndx >= blength ) {
......@@ -287,8 +281,10 @@ _mime_parse_mpart_message(mime_t mime)
mb_length = mime->cur_offset - mb_offset - mime->line_ndx + 1;
if ( mime->header_length ) /* this skips the preamble */
_mime_append_part(mime, NULL, mb_offset, mb_length, mb_lines);
if ( ( cp2 + blength + 2 < cp && !strncasecmp(cp2+blength, "--",2) ) ||
!strncasecmp(cp2+blength+2, "--",2) ) { /* very last boundary */
if ( ( &mime->cur_line[mime->line_ndx] - cp2 - 1 > blength
&& !strncasecmp(cp2+blength+2, "--",2) )
|| ( &mime->cur_line[mime->line_ndx] - cp2 - 1 == blength
&& !strncasecmp(cp2+blength, "--",2) ) ) { /* last boundary */
mime->parser_state = MIME_STATE_BEGIN_LINE;
mime->header_length = 0;
break;
......@@ -353,11 +349,7 @@ _mimepart_body_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t
return 0;
read_len = (buflen <= read_len)? buflen : read_len;
body = NULL;
stream = NULL;
message_get_body (mime_part->mime->msg, &body);
body_get_stream (body, &stream);
return stream_read(stream, buf, read_len, mime_part->offset + off, nbytes );
return stream_read(mime_part->mime->stream, buf, read_len, mime_part->offset + off, nbytes );
}
static int
......@@ -367,11 +359,7 @@ _mimepart_body_fd(stream_t stream, int *fd)
message_t msg = body_get_owner(body);
struct _mime_part *mime_part = message_get_owner(msg);
body = NULL;
stream = NULL;
message_get_body (mime_part->mime->msg, &body);
body_get_stream (body, &stream);
return stream_get_fd(stream, fd);
return stream_get_fd(mime_part->mime->stream, fd);
}
static int
......@@ -594,6 +582,7 @@ mime_create(mime_t *pmime, message_t msg, int flags)
mime_t mime = NULL;
int ret = 0;
size_t size;
body_t body;
if (pmime == NULL)
return EINVAL;
......@@ -615,6 +604,8 @@ mime_create(mime_t *pmime, message_t msg, int flags)
if (ret == 0 ) {
mime->msg = msg;
mime->buf_size = MIME_DFLT_BUF_SIZE;
message_get_body(msg, &body);
body_get_stream(body, &(mime->stream));
}
}
}
......@@ -686,7 +677,7 @@ mime_get_part(mime_t mime, size_t part, message_t *msg)
*msg = mime->msg;
else {
mime_part = mime->mtp_parts[part-1];
if ( ( ret = body_create(&body, mime_part->msg) ) == 0 ) {
if ( !mime_part->body_created && ( ret = body_create(&body, mime_part->msg) ) == 0 ) {
body_set_size (body, _mimepart_body_size, mime_part->msg);
body_set_lines (body, _mimepart_body_lines, mime_part->msg);
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)
stream_set_fd(stream, _mimepart_body_fd, body);
body_set_stream(body, stream, mime_part->msg);
message_set_body(mime_part->msg, body, mime_part);
*msg = mime_part->msg;
return 0;
mime_part->body_created = 1;
}
}
*msg = mime_part->msg;
}
}
return ret;
......@@ -764,6 +755,7 @@ mime_get_message(mime_t mime, message_t *msg)
}
}
message_destroy(&(mime->msg), mime);
mime->msg = NULL;
}
}
if ( ret == 0 )
......