2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-27 12:33:43 +00:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 12:33:43 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
2001-03-25 04:57:05 +00:00
|
|
|
#if 0
|
1994-05-27 12:33:43 +00:00
|
|
|
static char sccsid[] = "@(#)send.c 8.1 (Berkeley) 6/6/93";
|
2001-03-25 04:57:05 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include "rcv.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mail -- a mail program
|
|
|
|
*
|
|
|
|
* Mail to others.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send message described by the passed pointer to the
|
|
|
|
* passed output buffer. Return -1 on error.
|
|
|
|
* Adjust the status: field if need be.
|
|
|
|
* If doign is given, suppress ignored header fields.
|
|
|
|
* prefix is a string to prepend to each output line.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
sendmessage(struct message *mp, FILE *obuf, struct ignoretab *doign,
|
|
|
|
char *prefix)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
long count;
|
2001-05-27 20:26:22 +00:00
|
|
|
FILE *ibuf;
|
|
|
|
char *cp, *cp2, line[LINESIZE];
|
1994-05-27 12:33:43 +00:00
|
|
|
int ishead, infld, ignoring, dostat, firstline;
|
2017-01-23 07:32:47 +00:00
|
|
|
int c = 0, length, prefixlen;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the prefix string, without trailing whitespace
|
|
|
|
*/
|
2001-05-27 20:26:22 +00:00
|
|
|
if (prefix != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp2 = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
for (cp = prefix; *cp != '\0'; cp++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (*cp != ' ' && *cp != '\t')
|
|
|
|
cp2 = cp;
|
2001-05-27 20:26:22 +00:00
|
|
|
prefixlen = cp2 == NULL ? 0 : cp2 - prefix + 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
ibuf = setinput(mp);
|
|
|
|
count = mp->m_size;
|
|
|
|
ishead = 1;
|
|
|
|
dostat = doign == 0 || !isign("status", doign);
|
|
|
|
infld = 0;
|
|
|
|
firstline = 1;
|
|
|
|
/*
|
|
|
|
* Process headers first
|
|
|
|
*/
|
|
|
|
while (count > 0 && ishead) {
|
2001-03-25 04:57:05 +00:00
|
|
|
if (fgets(line, sizeof(line), ibuf) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
count -= length = strlen(line);
|
|
|
|
if (firstline) {
|
1995-05-30 06:41:30 +00:00
|
|
|
/*
|
1994-05-27 12:33:43 +00:00
|
|
|
* First line is the From line, so no headers
|
|
|
|
* there to worry about
|
|
|
|
*/
|
|
|
|
firstline = 0;
|
|
|
|
ignoring = doign == ignoreall;
|
|
|
|
} else if (line[0] == '\n') {
|
|
|
|
/*
|
|
|
|
* If line is blank, we've reached end of
|
|
|
|
* headers, so force out status: field
|
|
|
|
* and note that we are no longer in header
|
|
|
|
* fields
|
|
|
|
*/
|
|
|
|
if (dostat) {
|
|
|
|
statusput(mp, obuf, prefix);
|
|
|
|
dostat = 0;
|
|
|
|
}
|
|
|
|
ishead = 0;
|
|
|
|
ignoring = doign == ignoreall;
|
|
|
|
} else if (infld && (line[0] == ' ' || line[0] == '\t')) {
|
|
|
|
/*
|
|
|
|
* If this line is a continuation (via space or tab)
|
|
|
|
* of a previous header field, just echo it
|
|
|
|
* (unless the field should be ignored).
|
|
|
|
* In other words, nothing to do.
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Pick up the header field if we have one.
|
|
|
|
*/
|
2001-05-27 20:26:22 +00:00
|
|
|
for (cp = line; (c = *cp++) != '\0' && c != ':' &&
|
2001-12-19 21:50:22 +00:00
|
|
|
!isspace((unsigned char)c);)
|
1994-05-27 12:33:43 +00:00
|
|
|
;
|
|
|
|
cp2 = --cp;
|
2001-12-19 21:50:22 +00:00
|
|
|
while (isspace((unsigned char)*cp++))
|
1994-05-27 12:33:43 +00:00
|
|
|
;
|
|
|
|
if (cp[-1] != ':') {
|
|
|
|
/*
|
|
|
|
* Not a header line, force out status:
|
|
|
|
* This happens in uucp style mail where
|
|
|
|
* there are no headers at all.
|
|
|
|
*/
|
|
|
|
if (dostat) {
|
|
|
|
statusput(mp, obuf, prefix);
|
|
|
|
dostat = 0;
|
|
|
|
}
|
|
|
|
if (doign != ignoreall)
|
|
|
|
/* add blank line */
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc('\n', obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
ishead = 0;
|
|
|
|
ignoring = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If it is an ignored field and
|
|
|
|
* we care about such things, skip it.
|
|
|
|
*/
|
2001-05-27 20:26:22 +00:00
|
|
|
*cp2 = '\0'; /* temporarily null terminate */
|
1994-05-27 12:33:43 +00:00
|
|
|
if (doign && isign(line, doign))
|
|
|
|
ignoring = 1;
|
|
|
|
else if ((line[0] == 's' || line[0] == 'S') &&
|
|
|
|
strcasecmp(line, "status") == 0) {
|
|
|
|
/*
|
|
|
|
* If the field is "status," go compute
|
|
|
|
* and print the real Status: field
|
|
|
|
*/
|
|
|
|
if (dostat) {
|
|
|
|
statusput(mp, obuf, prefix);
|
|
|
|
dostat = 0;
|
|
|
|
}
|
|
|
|
ignoring = 1;
|
|
|
|
} else {
|
|
|
|
ignoring = 0;
|
|
|
|
*cp2 = c; /* restore */
|
|
|
|
}
|
|
|
|
infld = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ignoring) {
|
|
|
|
/*
|
|
|
|
* Strip trailing whitespace from prefix
|
|
|
|
* if line is blank.
|
|
|
|
*/
|
2001-05-27 20:26:22 +00:00
|
|
|
if (prefix != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (length > 1)
|
|
|
|
fputs(prefix, obuf);
|
|
|
|
else
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fwrite(prefix, sizeof(*prefix),
|
|
|
|
prefixlen, obuf);
|
2001-03-25 04:57:05 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fwrite(line, sizeof(*line), length, obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ferror(obuf))
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Copy out message body
|
|
|
|
*/
|
|
|
|
if (doign == ignoreall)
|
|
|
|
count--; /* skip final blank line */
|
2001-05-27 20:26:22 +00:00
|
|
|
if (prefix != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
while (count > 0) {
|
2001-03-25 04:57:05 +00:00
|
|
|
if (fgets(line, sizeof(line), ibuf) == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
c = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count -= c = strlen(line);
|
|
|
|
/*
|
|
|
|
* Strip trailing whitespace from prefix
|
|
|
|
* if line is blank.
|
|
|
|
*/
|
|
|
|
if (c > 1)
|
|
|
|
fputs(prefix, obuf);
|
|
|
|
else
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fwrite(prefix, sizeof(*prefix),
|
|
|
|
prefixlen, obuf);
|
|
|
|
(void)fwrite(line, sizeof(*line), c, obuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ferror(obuf))
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
while (count > 0) {
|
|
|
|
c = count < LINESIZE ? count : LINESIZE;
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((c = fread(line, sizeof(*line), c, ibuf)) <= 0)
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
count -= c;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (fwrite(line, sizeof(*line), c, obuf) != c)
|
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (doign == ignoreall && c > 0 && line[c - 1] != '\n')
|
|
|
|
/* no final blank line */
|
|
|
|
if ((c = getc(ibuf)) != EOF && putc(c, obuf) == EOF)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output a reasonable looking status field.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-19 16:25:23 +00:00
|
|
|
statusput(struct message *mp, FILE *obuf, char *prefix)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char statout[3];
|
2001-05-27 20:26:22 +00:00
|
|
|
char *cp = statout;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (mp->m_flag & MREAD)
|
|
|
|
*cp++ = 'R';
|
|
|
|
if ((mp->m_flag & MNEW) == 0)
|
|
|
|
*cp++ = 'O';
|
2001-05-27 20:26:22 +00:00
|
|
|
*cp = '\0';
|
|
|
|
if (statout[0] != '\0')
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(obuf, "%sStatus: %s\n",
|
2001-05-27 20:26:22 +00:00
|
|
|
prefix == NULL ? "" : prefix, statout);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface between the argument list and the mail1 routine
|
|
|
|
* which does all the dirty work.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
mail(struct name *to, struct name *cc, struct name *bcc, struct name *smopts,
|
|
|
|
char *subject, char *replyto)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct header head;
|
|
|
|
|
|
|
|
head.h_to = to;
|
|
|
|
head.h_subject = subject;
|
|
|
|
head.h_cc = cc;
|
|
|
|
head.h_bcc = bcc;
|
|
|
|
head.h_smopts = smopts;
|
1998-01-02 16:44:13 +00:00
|
|
|
head.h_replyto = replyto;
|
2001-05-27 20:26:22 +00:00
|
|
|
head.h_inreplyto = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
mail1(&head, 0);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send mail to a bunch of user names. The interface is through
|
|
|
|
* the mail routine below.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
sendmail(char *str)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct header head;
|
|
|
|
|
|
|
|
head.h_to = extract(str, GTO);
|
2001-05-27 20:26:22 +00:00
|
|
|
head.h_subject = NULL;
|
|
|
|
head.h_cc = NULL;
|
|
|
|
head.h_bcc = NULL;
|
|
|
|
head.h_smopts = NULL;
|
2001-06-14 01:08:30 +00:00
|
|
|
head.h_replyto = value("REPLYTO");
|
2001-05-27 20:26:22 +00:00
|
|
|
head.h_inreplyto = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
mail1(&head, 0);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mail a message on standard input to the people indicated
|
|
|
|
* in the passed header. (Internal interface).
|
|
|
|
*/
|
|
|
|
void
|
2010-12-19 16:25:23 +00:00
|
|
|
mail1(struct header *hp, int printheaders)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char *cp;
|
2004-02-29 20:44:44 +00:00
|
|
|
char *nbuf;
|
1994-05-27 12:33:43 +00:00
|
|
|
int pid;
|
|
|
|
char **namelist;
|
2004-02-29 20:44:44 +00:00
|
|
|
struct name *to, *nsto;
|
1994-05-27 12:33:43 +00:00
|
|
|
FILE *mtf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect user's mail from standard input.
|
|
|
|
* Get the result as mtf.
|
|
|
|
*/
|
|
|
|
if ((mtf = collect(hp, printheaders)) == NULL)
|
|
|
|
return;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (value("interactive") != NULL) {
|
2001-12-18 20:52:09 +00:00
|
|
|
if (value("askcc") != NULL || value("askbcc") != NULL) {
|
|
|
|
if (value("askcc") != NULL)
|
|
|
|
grabh(hp, GCC);
|
|
|
|
if (value("askbcc") != NULL)
|
|
|
|
grabh(hp, GBCC);
|
|
|
|
} else {
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("EOT\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(stdout);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-03-25 04:57:05 +00:00
|
|
|
}
|
|
|
|
if (fsize(mtf) == 0) {
|
2001-06-28 02:40:07 +00:00
|
|
|
if (value("dontsendempty") != NULL)
|
|
|
|
goto out;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (hp->h_subject == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("No message, no subject; hope that's ok\n");
|
|
|
|
else
|
|
|
|
printf("Null message body; hope that's ok\n");
|
2001-03-25 04:57:05 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Now, take the user names from the combined
|
|
|
|
* to and cc lists and do all the alias
|
|
|
|
* processing.
|
|
|
|
*/
|
|
|
|
senderr = 0;
|
|
|
|
to = usermap(cat(hp->h_bcc, cat(hp->h_to, hp->h_cc)));
|
2001-05-27 20:26:22 +00:00
|
|
|
if (to == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("No recipients specified\n");
|
|
|
|
senderr++;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Look through the recipient list for names with /'s
|
|
|
|
* in them which we write to as files directly.
|
|
|
|
*/
|
|
|
|
to = outof(to, mtf, hp);
|
|
|
|
if (senderr)
|
|
|
|
savedeadletter(mtf);
|
|
|
|
to = elide(to);
|
|
|
|
if (count(to) == 0)
|
|
|
|
goto out;
|
2004-02-29 20:44:44 +00:00
|
|
|
if (value("recordrecip") != NULL) {
|
|
|
|
/*
|
|
|
|
* Before fixing the header, save old To:.
|
|
|
|
* We do this because elide above has sorted To: list, and
|
|
|
|
* we would like to save message in a file named by the first
|
|
|
|
* recipient the user has entered, not the one being the first
|
|
|
|
* after sorting happened.
|
|
|
|
*/
|
|
|
|
if ((nsto = malloc(sizeof(struct name))) == NULL)
|
|
|
|
err(1, "Out of memory");
|
|
|
|
bcopy(hp->h_to, nsto, sizeof(struct name));
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
fixhead(hp, to);
|
|
|
|
if ((mtf = infix(hp, mtf)) == NULL) {
|
|
|
|
fprintf(stderr, ". . . message lost, sorry.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
namelist = unpack(cat(hp->h_smopts, to));
|
|
|
|
if (debug) {
|
|
|
|
char **t;
|
|
|
|
|
|
|
|
printf("Sendmail arguments:");
|
2001-05-27 20:26:22 +00:00
|
|
|
for (t = namelist; *t != NULL; t++)
|
1994-05-27 12:33:43 +00:00
|
|
|
printf(" \"%s\"", *t);
|
|
|
|
printf("\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2004-02-29 20:44:44 +00:00
|
|
|
if (value("recordrecip") != NULL) {
|
|
|
|
/*
|
|
|
|
* Extract first recipient username from saved To: and use it
|
|
|
|
* as a filename.
|
|
|
|
*/
|
|
|
|
if ((nbuf = malloc(strlen(detract(nsto, 0)) + 1)) == NULL)
|
|
|
|
err(1, "Out of memory");
|
|
|
|
if ((cp = yanklogin(detract(nsto, 0), nbuf)) != NULL)
|
|
|
|
(void)savemail(expand(nbuf), mtf);
|
|
|
|
free(nbuf);
|
|
|
|
free(nsto);
|
|
|
|
} else if ((cp = value("record")) != NULL)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)savemail(expand(cp), mtf);
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Fork, set up the temporary mail file as standard
|
|
|
|
* input for "mail", and exec with the user list we generated
|
|
|
|
* far above.
|
|
|
|
*/
|
|
|
|
pid = fork();
|
|
|
|
if (pid == -1) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("fork");
|
1994-05-27 12:33:43 +00:00
|
|
|
savedeadletter(mtf);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (pid == 0) {
|
2001-12-18 20:52:09 +00:00
|
|
|
sigset_t nset;
|
|
|
|
(void)sigemptyset(&nset);
|
|
|
|
(void)sigaddset(&nset, SIGHUP);
|
|
|
|
(void)sigaddset(&nset, SIGINT);
|
|
|
|
(void)sigaddset(&nset, SIGQUIT);
|
|
|
|
(void)sigaddset(&nset, SIGTSTP);
|
|
|
|
(void)sigaddset(&nset, SIGTTIN);
|
|
|
|
(void)sigaddset(&nset, SIGTTOU);
|
|
|
|
prepare_child(&nset, fileno(mtf), -1);
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((cp = value("sendmail")) != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
cp = expand(cp);
|
|
|
|
else
|
|
|
|
cp = _PATH_SENDMAIL;
|
|
|
|
execv(cp, namelist);
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", cp);
|
1994-05-27 12:33:43 +00:00
|
|
|
_exit(1);
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
if (value("verbose") != NULL)
|
|
|
|
(void)wait_child(pid);
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
|
|
|
free_child(pid);
|
|
|
|
out:
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(mtf);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fix the header by glopping all of the expanded names from
|
|
|
|
* the distribution list into the appropriate fields.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-19 16:25:23 +00:00
|
|
|
fixhead(struct header *hp, struct name *tolist)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct name *np;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
hp->h_to = NULL;
|
|
|
|
hp->h_cc = NULL;
|
|
|
|
hp->h_bcc = NULL;
|
2001-12-19 22:25:11 +00:00
|
|
|
for (np = tolist; np != NULL; np = np->n_flink) {
|
2001-12-18 20:52:09 +00:00
|
|
|
/* Don't copy deleted addresses to the header */
|
|
|
|
if (np->n_type & GDEL)
|
|
|
|
continue;
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((np->n_type & GMASK) == GTO)
|
|
|
|
hp->h_to =
|
2001-05-27 20:26:22 +00:00
|
|
|
cat(hp->h_to, nalloc(np->n_name, np->n_type));
|
1994-05-27 12:33:43 +00:00
|
|
|
else if ((np->n_type & GMASK) == GCC)
|
|
|
|
hp->h_cc =
|
2001-05-27 20:26:22 +00:00
|
|
|
cat(hp->h_cc, nalloc(np->n_name, np->n_type));
|
1994-05-27 12:33:43 +00:00
|
|
|
else if ((np->n_type & GMASK) == GBCC)
|
|
|
|
hp->h_bcc =
|
2001-05-27 20:26:22 +00:00
|
|
|
cat(hp->h_bcc, nalloc(np->n_name, np->n_type));
|
2001-12-19 22:25:11 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepend a header in front of the collected stuff
|
|
|
|
* and return the new file.
|
|
|
|
*/
|
|
|
|
FILE *
|
2010-12-19 16:25:23 +00:00
|
|
|
infix(struct header *hp, FILE *fi)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
FILE *nfo, *nfi;
|
|
|
|
int c, fd;
|
2001-03-25 04:57:05 +00:00
|
|
|
char tempname[PATHSIZE];
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)snprintf(tempname, sizeof(tempname),
|
|
|
|
"%s/mail.RsXXXXXXXXXX", tmpdir);
|
2001-03-25 04:57:05 +00:00
|
|
|
if ((fd = mkstemp(tempname)) == -1 ||
|
|
|
|
(nfo = Fdopen(fd, "w")) == NULL) {
|
|
|
|
warn("%s", tempname);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (fi);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-03-25 04:57:05 +00:00
|
|
|
if ((nfi = Fopen(tempname, "r")) == NULL) {
|
|
|
|
warn("%s", tempname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(nfo);
|
|
|
|
(void)rm(tempname);
|
|
|
|
return (fi);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)rm(tempname);
|
|
|
|
(void)puthead(hp, nfo,
|
|
|
|
GTO|GSUBJECT|GCC|GBCC|GREPLYTO|GINREPLYTO|GNL|GCOMMA);
|
1994-05-27 12:33:43 +00:00
|
|
|
c = getc(fi);
|
|
|
|
while (c != EOF) {
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc(c, nfo);
|
1994-05-27 12:33:43 +00:00
|
|
|
c = getc(fi);
|
|
|
|
}
|
|
|
|
if (ferror(fi)) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warnx("read");
|
1994-05-27 12:33:43 +00:00
|
|
|
rewind(fi);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (fi);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(nfo);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ferror(nfo)) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", tempname);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(nfo);
|
|
|
|
(void)Fclose(nfi);
|
1994-05-27 12:33:43 +00:00
|
|
|
rewind(fi);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (fi);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(nfo);
|
|
|
|
(void)Fclose(fi);
|
1994-05-27 12:33:43 +00:00
|
|
|
rewind(nfi);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (nfi);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump the to, subject, cc header on the
|
|
|
|
* passed file buffer.
|
|
|
|
*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
puthead(struct header *hp, FILE *fo, int w)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int gotcha;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
gotcha = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (hp->h_to != NULL && w & GTO)
|
1994-05-27 12:33:43 +00:00
|
|
|
fmt("To:", hp->h_to, fo, w&GCOMMA), gotcha++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (hp->h_subject != NULL && w & GSUBJECT)
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(fo, "Subject: %s\n", hp->h_subject), gotcha++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (hp->h_cc != NULL && w & GCC)
|
1994-05-27 12:33:43 +00:00
|
|
|
fmt("Cc:", hp->h_cc, fo, w&GCOMMA), gotcha++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (hp->h_bcc != NULL && w & GBCC)
|
1994-05-27 12:33:43 +00:00
|
|
|
fmt("Bcc:", hp->h_bcc, fo, w&GCOMMA), gotcha++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (hp->h_replyto != NULL && w & GREPLYTO)
|
1998-01-02 16:44:13 +00:00
|
|
|
fprintf(fo, "Reply-To: %s\n", hp->h_replyto), gotcha++;
|
2001-05-27 20:26:22 +00:00
|
|
|
if (hp->h_inreplyto != NULL && w & GINREPLYTO)
|
1998-01-02 16:44:13 +00:00
|
|
|
fprintf(fo, "In-Reply-To: <%s>\n", hp->h_inreplyto), gotcha++;
|
1994-05-27 12:33:43 +00:00
|
|
|
if (gotcha && w & GNL)
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)putc('\n', fo);
|
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format the given header line to not exceed 72 characters.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-19 16:25:23 +00:00
|
|
|
fmt(const char *str, struct name *np, FILE *fo, int comma)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int col, len;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
comma = comma ? 1 : 0;
|
|
|
|
col = strlen(str);
|
|
|
|
if (col)
|
|
|
|
fputs(str, fo);
|
2001-05-27 20:26:22 +00:00
|
|
|
for (; np != NULL; np = np->n_flink) {
|
|
|
|
if (np->n_flink == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
comma = 0;
|
|
|
|
len = strlen(np->n_name);
|
|
|
|
col++; /* for the space */
|
|
|
|
if (col + len + comma > 72 && col > 4) {
|
2001-05-27 20:26:22 +00:00
|
|
|
fprintf(fo, "\n ");
|
1994-05-27 12:33:43 +00:00
|
|
|
col = 4;
|
|
|
|
} else
|
2001-05-27 20:26:22 +00:00
|
|
|
fprintf(fo, " ");
|
1994-05-27 12:33:43 +00:00
|
|
|
fputs(np->n_name, fo);
|
|
|
|
if (comma)
|
2001-05-27 20:26:22 +00:00
|
|
|
fprintf(fo, ",");
|
1994-05-27 12:33:43 +00:00
|
|
|
col += len + comma;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
fprintf(fo, "\n");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the outgoing mail on the passed file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2010-12-19 16:25:23 +00:00
|
|
|
savemail(char name[], FILE *fi)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
FILE *fo;
|
1994-05-27 12:33:43 +00:00
|
|
|
char buf[BUFSIZ];
|
2001-05-27 20:26:22 +00:00
|
|
|
int i;
|
|
|
|
time_t now;
|
2017-01-23 06:04:43 +00:00
|
|
|
mode_t saved_umask;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2017-01-23 06:04:43 +00:00
|
|
|
saved_umask = umask(077);
|
|
|
|
fo = Fopen(name, "a");
|
|
|
|
umask(saved_umask);
|
|
|
|
|
|
|
|
if (fo == NULL) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", name);
|
1994-05-27 12:33:43 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)time(&now);
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(fo, "From %s %s", myname, ctime(&now));
|
2001-05-27 20:26:22 +00:00
|
|
|
while ((i = fread(buf, 1, sizeof(buf), fi)) > 0)
|
|
|
|
(void)fwrite(buf, 1, i, fo);
|
|
|
|
fprintf(fo, "\n");
|
|
|
|
(void)fflush(fo);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ferror(fo))
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("%s", name);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(fo);
|
1994-05-27 12:33:43 +00:00
|
|
|
rewind(fi);
|
|
|
|
return (0);
|
|
|
|
}
|