Commit acaaf3cd acaaf3cdb700f79351819a7ff8db20f405ece9a7 by Alain Magloire

header.c: bug corrected

address.c mime.c misc.c: Always cast to (unsigned char) when using the ctype
functions like isspace();
mbx_default.c: If _PATH_SENDMAIL not set via paths.h use "/usr/spool/mail"
message.c: uidl is now <md5 . time . sequene>
tcp.c: INADDR_NONE is not define on solaris define it to -1.
1 parent 1d370559
......@@ -44,7 +44,7 @@ struct token
char word[1];
};
#define SKIPSPACE(p) do { while(*p && isspace(*p)) p++; } while(0)
#define SKIPSPACE(p) do { while(*p && isspace((unsigned char)*p)) p++; } while(0)
/* Skip everything between quotes. */
static void
......
......@@ -112,6 +112,7 @@ body_get_stream (body_t body, stream_t *pstream)
if (fd == -1)
return errno;
status = stream_open (stream, body->filename, 0, MU_STREAM_RDWR);
close (fd);
if (status != 0)
return status;
body->stream = stream;
......
......@@ -140,7 +140,7 @@ _file_write (stream_t stream, const char *iptr, size_t isize,
err = errno;
}
else
fs->offset += *nbytes;
fs->offset += n;
if (nbytes)
*nbytes = n;
......
......@@ -523,18 +523,13 @@ header_set_fill (header_t header, int
static int
fill_blurb (header_t header)
{
stream_t is = NULL;
int status;
char buf[1024];
char *tbuf;
size_t nread = 0;
if (header->_fill == NULL)
{
status = header_get_stream (header, &is);
if (status != 0)
return status;
}
if (header->_fill == NULL && header->stream == NULL)
return 0;
do
{
......@@ -542,7 +537,7 @@ fill_blurb (header_t header)
status = header->_fill (header, buf, sizeof (buf),
header->temp_blurb_len, &nread) ;
else
status = stream_read (is, buf, sizeof (buf),
status = stream_read (header->stream, buf, sizeof (buf),
header->temp_blurb_len, &nread);
if (status != 0)
{
......@@ -610,7 +605,7 @@ header_read (stream_t is, char *buf, size_t buflen, off_t off, size_t *pnread)
return EINVAL;
/* Try to fill out the buffer, if we know how. */
if (header->blurb == NULL)
if (header->blurb == NULL && header->_fill)
{
int err = fill_blurb (header);
if (err != 0)
......@@ -651,7 +646,7 @@ header_readline (stream_t is, char *buf, size_t buflen, off_t off, size_t *pn)
}
/* Try to fill out the buffer, if we know how. */
if (header->blurb == NULL)
if (header->blurb == NULL && header->_fill)
{
int err = fill_blurb (header);
if (err != 0)
......
......@@ -142,7 +142,7 @@ locker_lock (locker_t lock, int flags)
O_WRONLY | O_CREAT | O_EXCL, LOCKFILE_ATTR)) == -1)
return errno;
/* Success. */
sprintf(buf, "%d", getpid());
sprintf(buf, "%ld", (long)getpid());
write(fd, buf, strlen(buf));
/* Try to get a file lock. */
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
......@@ -31,7 +31,7 @@
#include <mailutils/mailbox.h>
#ifndef _PATH_MAILDIR
# define _PATH_MAILDIR "/var/spool/mail"
# define _PATH_MAILDIR "/usr/spool/mail"
#endif
int
......
......@@ -437,14 +437,18 @@ message_get_uid (message_t msg, char *buffer, size_t buflen, size_t *pwriten)
status = header_get_value (header, "X-UIDL", buffer, buflen, &n);
if (status == 0 && n > 0)
{
/* FIXME: Is header_get_value suppose to do this ? */
/* FIXME: Is this necessary ? I did not see so far a x-uidl message
that broken i.e.
X-UIDL: <abaceekeke\n
jakdkjaja>
*/
/* We need to collapse the header if it was mutiline. e points to the
last char meaning in a C string that's '\0', s to the start. We also
remove the spesky '<' '>' if they are around. */
char *s, *e;
for (s = buffer, e = buffer + n; s <= e; s++)
{
if (isspace (*s) || *s == '<' || *s == '>')
if (isspace ((unsigned char)*s) || *s == '<' || *s == '>')
{
memmove (s, s + 1, e - (s + 1));
e -= 1;
......@@ -454,6 +458,7 @@ message_get_uid (message_t msg, char *buffer, size_t buflen, size_t *pwriten)
}
else
{
static unsigned long seq;
struct md5_ctx md5context;
stream_t stream = NULL;
char buf[1024];
......@@ -474,6 +479,11 @@ message_get_uid (message_t msg, char *buffer, size_t buflen, size_t *pwriten)
for (n = 0; n < 16; n++, tmp += 2)
sprintf (tmp, "%02x", md5digest[n]);
*tmp = '\0';
/* Access to sequence is not thread-safe, but that is not a problem. */
seq++;
/* POP3 rfc says that an UID should not be longer than 70. */
snprintf (buf + 32, 70, ".%lu.%lu", (unsigned long)time (NULL), seq);
header_set_value (header, "X-UIDL", buf, 1);
buflen--; /* leave space for the NULL. */
strncpy (buffer, buf, buflen)[buflen] = '\0';
......
......@@ -106,7 +106,7 @@ _strltrim(char *str)
{
char *p;
for (p = str; isspace(*p) && *p != '\0'; ++p)
for (p = str; isspace((unsigned char)*p) && *p != '\0'; ++p)
;
return((p != str) ? memmove(str, p, strlen(p)+1) : str);
}
......@@ -116,7 +116,7 @@ _strttrim(char *str)
{
char *p;
for (p = str + strlen(str) - 1; isspace(*p) && p >= str; --p)
for (p = str + strlen(str) - 1; isspace((unsigned char)*p) && p >= str; --p)
;
*++p = '\0';
return(str);
......@@ -144,7 +144,7 @@ _mime_munge_content_header(char *field_body )
while( *e == ';' ) {
p = e;
e++;
while ( *e && isspace(*e) ) /* remove space upto param */
while ( *e && isspace((unsigned char)*e) ) /* remove space upto param */
e++;
memmove(p+1, e, strlen(e)+1);
e = p+1;
......@@ -152,7 +152,7 @@ _mime_munge_content_header(char *field_body )
while ( *e && *e != '=' ) /* find end of value */
e++;
e = p = e+1;
while ( *e && (quoted || ( !_ISSPECIAL(*e) && !isspace(*e) ) ) ) {
while ( *e && (quoted || ( !_ISSPECIAL(*e) && !isspace((unsigned char)*e) ) ) ) {
if ( *e == '\\' ) { /* escaped */
memmove(e, e+1, strlen(e)+2);
} else if ( *e == '\"' )
......@@ -178,7 +178,7 @@ _mime_get_param(char *field_body, const char *param, int *len)
break;
*len = 0;
v = e = v + 1;
while ( *e && (quoted || ( !_ISSPECIAL(*e) && !isspace(*e) ) ) ) { /* skip pass value and calc len */
while ( *e && (quoted || ( !_ISSPECIAL(*e) && !isspace((unsigned char)*e) ) ) ) { /* skip pass value and calc len */
if ( *e == '\"' )
quoted = ~quoted, was_quoted = 1;
else
......
......@@ -55,7 +55,7 @@ struct token
char word[1];
};
#define SKIPSPACE(p) do { while(*p && isspace(*p)) p++; } while(0)
#define SKIPSPACE(p) do { while(*p && isspace((unsigned char)*p)) p++; } while(0)
/* Skip everything between quotes. */
static void
......
......@@ -34,6 +34,11 @@
#include <mailutils/stream.h>
#include <tcp0.h>
/* On solaris inet_addr() return -1. */
#ifndef INADDR_NONE
# define INADDR_NONE (unsigned long)-1
#endif
static int _tcp_close(stream_t stream)
{
struct _tcp_instance *tcp = stream_get_owner(stream);
......