Commit 7e34b968 7e34b96853495be724e1cd0379620ed87f6fef75 by Alain Magloire

Bug fixes in mime.c

1 parent 76ec9ddd
2001-05-23 Alain Magloire
* mailbox/mbx_default.c (mailbox_create_default): Check
for URL in the mailbox name.
* mailbox/mime.c (_mimepart_body_read): Use stream_is_seekable()
to detect if the stream is POP for example and read 'til the end.
(mime_get_part): Reuse the stream the original stream flags on the
newly created message.
Fix and patches provided by Dave Inglis.
2001-05-23 Sergey Poznyakoff
* pop3d/user.c: check for NULL return from getpwnam()
......
......@@ -273,6 +273,8 @@ mailbox_create_default (mailbox_t *pmbox, const char *mail)
mbox = get_full_path (mail2);
free (mail2);
}
else if (mail)
mbox = strdup (mail);
/* Search the spooldir. */
if (mbox == NULL)
......
......@@ -339,14 +339,21 @@ _mimepart_body_read(stream_t stream, char *buf, size_t buflen, off_t off, size_t
message_t msg = body_get_owner(body);
struct _mime_part *mime_part = message_get_owner(msg);
size_t read_len;
int ret = 0;
if ( nbytes == NULL )
return(EINVAL);
*nbytes = 0;
read_len = (int)mime_part->len - (int)off;
if ( read_len <= 0 )
return 0;
if ( read_len <= 0 ) {
if ( !stream_is_seekable (mime_part->mime->stream) ) {
while( ( ret = stream_read(mime_part->mime->stream, buf, buflen, mime_part->offset + off, nbytes) ) == 0 && *nbytes > 0 )
off += *nbytes;
*nbytes = 0;
}
return ret;
}
read_len = (buflen <= read_len)? buflen : read_len;
return stream_read(mime_part->mime->stream, buf, read_len, mime_part->offset + off, nbytes );
......@@ -665,7 +672,7 @@ int
mime_get_part(mime_t mime, size_t part, message_t *msg)
{
size_t nmtp_parts;
int ret = 0;
int ret = 0, flags = 0;
stream_t stream;
body_t body;
struct _mime_part *mime_part;
......@@ -680,7 +687,8 @@ mime_get_part(mime_t mime, size_t part, message_t *msg)
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 ) {
stream_get_flags(mime->stream, &flags);
if ( ( ret = stream_create(&stream, MU_STREAM_READ | (flags & (MU_STREAM_SEEKABLE|MU_STREAM_NONBLOCK)), body) ) == 0 ) {
stream_set_read(stream, _mimepart_body_read, body);
stream_set_fd(stream, _mimepart_body_fd, body);
body_set_stream(body, stream, mime_part->msg);
......