sync code with last fixes and improvements from OpenBSD

This commit is contained in:
purplerain 2023-06-07 21:20:56 +00:00
parent 4b78db449c
commit bf0676207f
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
2406 changed files with 6353 additions and 434004 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: mail.local.c,v 1.41 2023/05/15 12:02:40 op Exp $ */
/* $OpenBSD: mail.local.c,v 1.42 2023/06/05 08:07:18 op Exp $ */
/*-
* Copyright (c) 1996-1998 Theo de Raadt <deraadt@theos.com>
@ -111,9 +111,10 @@ storemail(char *from)
{
FILE *fp = NULL;
time_t tval;
int fd, eline;
size_t len;
char *line, *tbuf;
int fd, eline = 1;
char *tbuf, *line = NULL;
size_t linesize = 0;
ssize_t linelen;
if ((tbuf = strdup(_PATH_LOCTMP)) == NULL)
merr(EX_OSERR, "unable to allocate memory");
@ -125,23 +126,13 @@ storemail(char *from)
(void)time(&tval);
(void)fprintf(fp, "From %s %s", from, ctime(&tval));
for (eline = 1, tbuf = NULL; (line = fgetln(stdin, &len));) {
/* We have to NUL-terminate the line since fgetln does not */
if (line[len - 1] == '\n')
line[len - 1] = '\0';
else {
/* No trailing newline, so alloc space and copy */
if ((tbuf = malloc(len + 1)) == NULL)
merr(EX_OSERR, "unable to allocate memory");
memcpy(tbuf, line, len);
tbuf[len] = '\0';
line = tbuf;
}
while ((linelen = getline(&line, &linesize, stdin)) != -1) {
if (line[linelen - 1] == '\n')
line[linelen - 1] = '\0';
if (line[0] == '\0')
eline = 1;
else {
if (eline && line[0] == 'F' && len > 5 &&
!memcmp(line, "From ", 5))
if (eline && !strncmp(line, "From ", 5))
(void)putc('>', fp);
eline = 0;
}
@ -149,7 +140,7 @@ storemail(char *from)
if (ferror(fp))
break;
}
free(tbuf);
free(line);
/* Output a newline; note, empty messages are allowed. */
(void)putc('\n', fp);