summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mailx/send.c
blob: e4a0b6c6b2a53c572f138b0fa44f790894c94f3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 1985, 2010, Oracle and/or its affiliates. All rights reserved.
 * Copyright (c) 2016 by Delphix. All rights reserved.
 */

/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
/*	  All Rights Reserved  	*/

/*
 * University Copyright- Copyright (c) 1982, 1986, 1988
 * The Regents of the University of California
 * All Rights Reserved
 *
 * University Acknowledgment- Portions of this document are derived from
 * software developed by the University of California, Berkeley, and its
 * contributors.
 */

#include "rcv.h"
#include <locale.h>

/*
 * mailx -- a modified version of a University of California at Berkeley
 *	mail program
 *
 * Mail to others.
 */

static void		fmt(register char *str, register FILE *fo);
static FILE		*infix(struct header *hp, FILE *fi);
static void		statusput(register struct message *mp, register FILE *obuf, int doign, int (*fp)(const char *, FILE *));
static int		savemail(char name[], struct header *hp, FILE *fi);
static int		sendmail(char *str);
static int		Sendmail(char *str);

static off_t textpos;

/*
 * Send message described by the passed pointer to the
 * passed output buffer.  Return -1 on error, but normally
 * the number of lines written.  Adjust the status: field
 * if need be.  If doign is set, suppress ignored header fields.
 * Call (*fp)(line, obuf) to print the line.
 */
long
msend(
	struct message *mailp,
	FILE *obuf,
	int flag,
	int (*fp)(const char *, FILE *))
{
	register struct message *mp;
	long clen, n, c;
	FILE *ibuf;
	char line[LINESIZE], field[BUFSIZ];
	int ishead, infld, fline, dostat, doclen, nread, unused;
	char *cp, *cp2;
	int doign = flag & M_IGNORE;
	int oldign = 0;	/* previous line was ignored */
	long lc;

	mp = mailp;
	if (mp->m_clen == 0)
		setclen(mp);
	ibuf = setinput(mp);
	c = mp->m_size;
	ishead = 1;
	dostat = 1;
	doclen = 1;
	infld = 0;
	fline = 1;
	lc = 0;
	clearerr(obuf);
	while (c > 0L) {
		nread = getaline(line, LINESIZE, ibuf, &unused);
		c -= nread;
		lc++;
		if (ishead) {
			/*
			 * First line is the From line, so no headers
			 * there to worry about
			 */
			if (fline) {
				fline = 0;
				goto writeit;
			}
			/*
			 * 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.  Also force out Content-Length: field.
			 */
			if (line[0] == '\n') {
				if (dostat) {
					statusput(mailp, obuf, doign, fp);
					dostat = 0;
				}
				if (doclen &&
				    !isign("content-length", flag&M_SAVING)) {
					snprintf(field, sizeof (field),
						"Content-Length: %ld\n",
						mp->m_clen - 1);
					(*fp)(field, obuf);
					if (ferror(obuf))
						return(-1);
					doclen = 0;
				}
				ishead = 0;
				goto writeit;
			}
			/*
			 * If this line is a continuation
			 * of a previous header field, just echo it.
			 */
			if (isspace(line[0]) && infld)
				if (oldign)
					continue;
				else
					goto writeit;
			infld = 0;
			/*
			 * If we are no longer looking at real
			 * header lines, force out status:
			 * This happens in uucp style mail where
			 * there are no headers at all.
			 */
			if (!headerp(line)) {
				if (dostat) {
					statusput(mailp, obuf, doign, fp);
					dostat = 0;
				}
				(*fp)("\n", obuf);
				ishead = 0;
				goto writeit;
			}
			infld++;
			/*
			 * Pick up the header field.
			 * If it is an ignored field and
			 * we care about such things, skip it.
			 */
			cp = line;
			cp2 = field;
			while (*cp && *cp != ':' && !isspace(*cp))
				*cp2++ = *cp++;
			*cp2 = 0;
			oldign = doign && isign(field, flag&M_SAVING);
			if (oldign)
				continue;
			/*
			 * If the field is "status," go compute and print the
			 * real Status: field
			 */
			if (icequal(field, "status")) {
				if (dostat) {
					statusput(mailp, obuf, doign, fp);
					dostat = 0;
				}
				continue;
			}
			if (icequal(field, "content-length")) {
				if (doclen) {
					snprintf(line, sizeof (line),
						"Content-Length: %ld\n",
						mp->m_clen - 1);
					(*fp)(line, obuf);
					if (ferror(obuf))
						return(-1);
					doclen = 0;
				}
				continue;
			}
		}
writeit:
		if (!ishead && !mp->m_text && mp->m_clen != 0) {
			if (line[0] == '\n')
				putc('\n', obuf);
			clen = mp->m_clen-1;
			for (;;) {
				n = clen < sizeof line ? clen : sizeof line;
				if ((n = fread(line, 1, (int)n, ibuf)) <= 0) {
					fprintf(stderr, gettext(
					    "\t(Unexpected end-of-file).\n"));
					clen = 0;
				} else {
					if (fwrite(line, 1, (int)n, obuf) != n) {
						fprintf(stderr, gettext(
					"\tError writing to the new file.\n"));
						fflush(obuf);
						if (fferror(obuf))
							return (-1);
					}
				}
				clen -= n;
				if (clen <= 0) {
					break;
				}
			}
			c = 0L;
		} else {
			(*fp)(line, obuf);
			if (ferror(obuf))
				return(-1);
		}
	}
	fflush(obuf);
	if (ferror(obuf))
		return(-1);
	if (ishead && (mailp->m_flag & MSTATUS))
		printf(gettext("failed to fix up status field\n"));
	return(lc);
}

/*
 * Test if the passed line is a header line, RFC 822 style.
 */
int
headerp(register char *line)
{
	register char *cp = line;

	while (*cp && *cp != ' ' && *cp != '\t' && *cp != ':')
		cp++;
	return(*cp == ':');
}

/*
 * Output a reasonable looking status field.
 * But if "status" is ignored and doign, forget it.
 */
static void
statusput(
	register struct message *mp,
	register FILE *obuf,
	int doign,
	int (*fp)(const char *, FILE *))
{
	char statout[12];

	if (doign && isign("status", 0))
		return;
	if ((mp->m_flag & (MNEW|MREAD)) == MNEW)
		return;
	strcpy(statout, "Status: ");
	if (mp->m_flag & MREAD)
		strcat(statout, "R");
	if ((mp->m_flag & MNEW) == 0)
		strcat(statout, "O");
	strcat(statout, "\n");
	(*fp)(statout, obuf);
}

/*
 * Interface between the argument list and the mail1 routine
 * which does all the dirty work.
 */

int
mail(char **people)
{
	register char *cp2, *cp3;
	register int s;
	char *buf, **ap;
	struct header head;

	for (s = 0, ap = people; *ap; ap++)
		s += strlen(*ap) + 2;
	buf = (char *)salloc((unsigned)(s+1));
	cp2 = buf;
	for (ap = people; *ap; ap++) {
		for (cp3 = *ap; *cp3; ) {
			if (*cp3 == ' ' || *cp3 == '\t') {
				*cp3++ = ',';
				while (*cp3 == ' ' || *cp3 == '\t')
					cp3++;
			} else
				cp3++;
		}
		cp2 = copy(*ap, cp2);
		*cp2++ = ',';
		*cp2++ = ' ';
	}
	*cp2 = '\0';
	head.h_to = buf;
	head.h_subject = head.h_cc = head.h_bcc = head.h_defopt = NOSTR;
	head.h_others = NOSTRPTR;
	head.h_seq = 0;
	mail1(&head, Fflag, NOSTR);
	return(0);
}

int
sendm(char *str)
{
	if (value("flipm") != NOSTR)
		return(Sendmail(str));
	else return(sendmail(str));
}

int
Sendm(char *str)
{
	if (value("flipm") != NOSTR)
		return(sendmail(str));
	else return(Sendmail(str));
}

/*
 * Interface to the mail1 routine for the -t flag
 * (read headers from text).
 */
int
tmail(void)
{
	struct header head;

	head.h_to = NOSTR;
	head.h_subject = head.h_cc = head.h_bcc = head.h_defopt = NOSTR;
	head.h_others = NOSTRPTR;
	head.h_seq = 0;
	mail1(&head, Fflag, NOSTR);
	return(0);
}

/*
 * Send mail to a bunch of user names.  The interface is through
 * the mail routine below.
 */
static int
sendmail(char *str)
{
	struct header head;

	if (blankline(str))
		head.h_to = NOSTR;
	else
		head.h_to = addto(NOSTR, str);
	head.h_subject = head.h_cc = head.h_bcc = head.h_defopt = NOSTR;
	head.h_others = NOSTRPTR;
	head.h_seq = 0;
	mail1(&head, 0, NOSTR);
	return(0);
}

/*
 * Send mail to a bunch of user names.  The interface is through
 * the mail routine below.
 * save a copy of the letter
 */
static int
Sendmail(char *str)
{
	struct header head;

	if (blankline(str))
		head.h_to = NOSTR;
	else
		head.h_to = addto(NOSTR, str);
	head.h_subject = head.h_cc = head.h_bcc = head.h_defopt = NOSTR;
	head.h_others = NOSTRPTR;
	head.h_seq = 0;
	mail1(&head, 1, NOSTR);
	return(0);
}

/*
 * Walk the list of fds, closing all but one.
 */
static int
closefd_walk(void *special_fd, int fd)
{
	if (fd > STDERR_FILENO && fd != *(int *)special_fd)
		(void) close(fd);
	return (0);
}

/*
 * Mail a message on standard input to the people indicated
 * in the passed header.  (Internal interface).
 */
void
mail1(struct header *hp, int use_to, char *orig_to)
{
	pid_t p, pid;
	int i, s, gotcha;
	char **namelist, *deliver;
	struct name *to, *np;
	FILE *mtf, *fp;
	int remote = rflag != NOSTR || rmail;
	char **t;
	char *deadletter;
	char recfile[PATHSIZE];

	/*
	 * Collect user's mail from standard input.
	 * Get the result as mtf.
	 */

	pid = (pid_t)-1;
	if ((mtf = collect(hp)) == NULL)
		return;
	hp->h_seq = 1;
	if (hp->h_subject == NOSTR)
		hp->h_subject = sflag;
	if (fsize(mtf) == 0 && hp->h_subject == NOSTR) {
		printf(gettext("No message !?!\n"));
		goto out;
	}
	if (intty) {
		printf(gettext("EOT\n"));
		flush();
	}

	/*
	 * If we need to use the To: line to determine the record
	 * file, save a copy of it before it's sorted below.
	 */

	if (use_to && orig_to == NOSTR && hp->h_to != NOSTR)
		orig_to = strcpy((char *)salloc(strlen(hp->h_to)+1), hp->h_to);
	else if (orig_to == NOSTR)
		orig_to = "";

	/*
	 * Now, take the user names from the combined
	 * to and cc lists and do all the alias
	 * processing.
	 */

	senderr = 0;
	to = cat(extract(hp->h_bcc, GBCC),
	     cat(extract(hp->h_to, GTO),
	     extract(hp->h_cc, GCC)));
	to = translate(outpre(elide(usermap(to))));
	if (!senderr)
		mapf(to, myname);
	mechk(to);
	for (gotcha = 0, np = to; np != NIL; np = np->n_flink)
		if ((np->n_type & GDEL) == 0)
			gotcha++;
	hp->h_to = detract(to, GTO);
	hp->h_cc = detract(to, GCC);
	hp->h_bcc = detract(to, GBCC);
	if ((mtf = infix(hp, mtf)) == NULL) {
		fprintf(stderr, gettext(". . . message lost, sorry.\n"));
		return;
	}
	rewind(mtf);
	if (askme && isatty(0)) {
		char ans[64];
		puthead(hp, stdout, GTO|GCC|GBCC, 0);
		printf(gettext("Send? "));
		printf("[yes] ");
		if (fgets(ans, sizeof(ans), stdin) && ans[0] &&
				(tolower(ans[0]) != 'y' && ans[0] != '\n'))
			goto dead;
	}
	if (senderr)
		goto dead;
	/*
	 * Look through the recipient list for names with /'s
	 * in them which we write to as files directly.
	 */
	i = outof(to, mtf);
	rewind(mtf);
	if (!gotcha && !i) {
		printf(gettext("No recipients specified\n"));
		goto dead;
	}
	if (senderr)
		goto dead;

	getrecf(orig_to, recfile, use_to, sizeof (recfile));
	if (recfile != NOSTR && *recfile)
		savemail(safeexpand(recfile), hp, mtf);
	if (!gotcha)
		goto out;
	namelist = unpack(to);
	if (debug) {
		fprintf(stderr, "Recipients of message:\n");
		for (t = namelist; *t != NOSTR; t++)
			fprintf(stderr, " \"%s\"", *t);
		fprintf(stderr, "\n");
		return;
	}

	/*
	 * Wait, to absorb a potential zombie, then
	 * fork, set up the temporary mail file as standard
	 * input for "mail" and exec with the user list we generated
	 * far above. Return the process id to caller in case it
	 * wants to await the completion of mail.
	 */

#ifdef VMUNIX
	while (wait3((int *)0, WNOHANG, (struct rusage *)0) > 0)
		;
#else
#ifdef preSVr4
	wait((int *)0);
#else
	while (waitpid((pid_t)-1, (int *)0, WNOHANG) > 0)
		;
#endif
#endif
	rewind(mtf);
	pid = fork();
	if (pid == (pid_t)-1) {
		perror("fork");
dead:
		deadletter = Getf("DEAD");
		if (fp = fopen(deadletter,
		    value("appenddeadletter") == NOSTR ? "w" : "a")) {
			chmod(deadletter, DEADPERM);
			puthead(hp, fp, GMASK|GCLEN, fsize(mtf) - textpos);
			fseek(mtf, textpos, 0);
			lcwrite(deadletter, mtf, fp,
			    value("appenddeadletter") != NOSTR);
			fclose(fp);
		} else
			perror(deadletter);
		goto out;
	}
	if (pid == 0) {
		sigchild();
#ifdef SIGTSTP
		if (remote == 0) {
			sigset(SIGTSTP, SIG_IGN);
			sigset(SIGTTIN, SIG_IGN);
			sigset(SIGTTOU, SIG_IGN);
		}
#endif
		sigset(SIGHUP, SIG_IGN);
		sigset(SIGINT, SIG_IGN);
		sigset(SIGQUIT, SIG_IGN);
		s = fileno(mtf);
		(void) fdwalk(closefd_walk, &s);
		close(0);
		dup(s);
		close(s);
#ifdef CC
		submit(getpid());
#endif /* CC */
		if ((deliver = value("sendmail")) == NOSTR)
#ifdef SENDMAIL
			deliver = SENDMAIL;
#else
			deliver = MAIL;
#endif
		execvp(safeexpand(deliver), namelist);
		perror(deliver);
		exit(1);
	}

	if (value("sendwait")!=NOSTR)
		remote++;
out:
	if (remote) {
		while ((p = wait(&s)) != pid && p != (pid_t)-1)
			;
		if (s != 0)
			senderr++;
		pid = 0;
	}
	fclose(mtf);
	return;
}

/*
 * Prepend a header in front of the collected stuff
 * and return the new file.
 */

static FILE *
infix(struct header *hp, FILE *fi)
{
	register FILE *nfo, *nfi;
	register int c;
	char *postmark, *returnaddr;
	int fd = -1;

	rewind(fi);
	if ((fd = open(tempMail, O_RDWR|O_CREAT|O_EXCL, 0600)) < 0 ||
	(nfo = fdopen(fd, "w")) == NULL) {
		perror(tempMail);
		return(fi);
	}
	if ((nfi = fopen(tempMail, "r")) == NULL) {
		perror(tempMail);
		fclose(nfo);
		return(fi);
	}
	removefile(tempMail);
	postmark = value("postmark");
	returnaddr = value("returnaddr");
	if ((postmark != NOSTR) || (returnaddr != NOSTR)) {
		if (returnaddr && *returnaddr)
			fprintf(nfo, "From: %s", returnaddr);
		else
			fprintf(nfo, "From: %s@%s", myname, host);
		if (postmark && *postmark)
			fprintf(nfo, " (%s)", postmark);
		putc('\n', nfo);
	}
	puthead(hp, nfo, (GMASK & ~GBCC) | GCLEN, fsize(fi));
	textpos = ftell(nfo);
	while ((c = getc(fi)) != EOF)
		putc(c, nfo);
	if (ferror(fi)) {
		perror("read");
		return(fi);
	}
	fflush(nfo);
	if (fferror(nfo)) {
		perror(tempMail);
		fclose(nfo);
		fclose(nfi);
		return(fi);
	}
	fclose(nfo);
	fclose(fi);
	rewind(nfi);
	return(nfi);
}

/*
 * Dump the message header on the
 * passed file buffer.
 */

int
puthead(struct header *hp, FILE *fo, int w, long clen)
{
	register int gotcha;

	gotcha = 0;
	if (hp->h_to != NOSTR && (w & GTO))
		fprintf(fo, "To: "), fmt(hp->h_to, fo), gotcha++;
	if ((w & GSUBJECT) && (int)value("bsdcompat"))
		if (hp->h_subject != NOSTR && *hp->h_subject)
			fprintf(fo, "Subject: %s\n", hp->h_subject), gotcha++;
		else
			if (sflag && *sflag)
				fprintf(fo, "Subject: %s\n", sflag), gotcha++;
	if (hp->h_cc != NOSTR && (w & GCC))
		fprintf(fo, "Cc: "), fmt(hp->h_cc, fo), gotcha++;
	if (hp->h_bcc != NOSTR && (w & GBCC))
		fprintf(fo, "Bcc: "), fmt(hp->h_bcc, fo), gotcha++;
	if (hp->h_defopt != NOSTR && (w & GDEFOPT))
		if (receipt_flg)
			fprintf(fo, "Return-Receipt-To: %s\n",
				hp->h_defopt), gotcha++;
		else
		fprintf(fo, "Default-Options: %s\n", hp->h_defopt), gotcha++;
	if ((w & GSUBJECT) && !(int)value("bsdcompat"))
		if (hp->h_subject != NOSTR && *hp->h_subject)
			fprintf(fo, "Subject: %s\n", hp->h_subject), gotcha++;
		else
			if (sflag && *sflag)
				fprintf(fo, "Subject: %s\n", sflag), gotcha++;
	if (hp->h_others != NOSTRPTR && (w & GOTHER)) {
		char **p;
		for (p = hp->h_others; *p; p++)
			fprintf(fo, "%s\n", *p);
		gotcha++;
	}
#ifndef preSVr4
	if (w & GCLEN)
		fprintf(fo, "Content-Length: %ld\n", clen), gotcha++;
#endif
	if (gotcha && (w & GNL))
		putc('\n', fo);
	return(0);
}

/*
 * Format the given text to not exceed 78 characters.
 */
static void
fmt(register char *str, register FILE *fo)
{
	register int col = 4;
	char name[256];
	int len;

	str = strcpy((char *)salloc(strlen(str)+1), str);
	while (str = yankword(str, name, sizeof (name), 1)) {
		len = strlen(name);
		if (col > 4) {
			if (col + len > 76) {
				fputs(",\n    ", fo);
				col = 4;
			} else {
				fputs(", ", fo);
				col += 2;
			}
		}
		fputs(name, fo);
		col += len;
	}
	putc('\n', fo);
}

/*
 * Save the outgoing mail on the passed file.
 */
static int
savemail(char name[], struct header *hp, FILE *fi)
{
	register FILE *fo;
	time_t now;
	char *n;
#ifdef preSVr4
	char line[BUFSIZ];
#else
	int c;
#endif

	if (debug)
		fprintf(stderr, gettext("save in '%s'\n"), name);
	if ((fo = fopen(name, "a")) == NULL) {
		perror(name);
		return(-1);
	}
	time(&now);
	n = rflag;
	if (n == NOSTR)
		n = myname;
	fprintf(fo, "From %s %s", n, ctime(&now));
	puthead(hp, fo, GMASK|GCLEN, fsize(fi) - textpos);
	fseek(fi, textpos, 0);
#ifdef preSVr4
	while (fgets(line, sizeof line, fi)) {
		if (!strncmp(line, "From ", 5))
			putc('>', fo);
		fputs(line, fo);
	}
#else
	while ((c = getc(fi)) != EOF)
		putc(c, fo);
#endif
	putc('\n', fo);
	fflush(fo);
	if (fferror(fo))
		perror(name);
	fclose(fo);
	return(0);
}