xref: /illumos-gate/usr/src/cmd/mail/copylet.c (revision 55fea89d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23d7c57852SGary Mills  * Copyright 2017 Gary Mills
24b7d62af5Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
28b7d62af5Sceastha /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29b7d62af5Sceastha /*	  All Rights Reserved  	*/
30b7d62af5Sceastha 
317c478bd9Sstevel@tonic-gate #include "mail.h"
32b7d62af5Sceastha 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate     NAME
357c478bd9Sstevel@tonic-gate 	copylet - copy a given letter to a file pointer
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate     SYNOPSIS
387c478bd9Sstevel@tonic-gate 	int copylet(int letnum, FILE *f, int type)
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate     DESCRIPTION
417c478bd9Sstevel@tonic-gate 	Copylet() will copy the letter "letnum" to the
427c478bd9Sstevel@tonic-gate 	given file pointer.
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 		letnum	-> index into: letter table
457c478bd9Sstevel@tonic-gate 		f	-> file pointer to copy file to
467c478bd9Sstevel@tonic-gate 		type	-> copy type
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate 	Returns TRUE on a completely successful copy.
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate 
51b7d62af5Sceastha int
copylet(int letnum,FILE * f,int type)52*55fea89dSDan Cross copylet(int letnum, FILE *f, int type)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate 	int		pos = ftell(f);
557c478bd9Sstevel@tonic-gate 	int		rc  = xxxcopylet(letnum, f, type);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	if (fflush(f) != 0)
587c478bd9Sstevel@tonic-gate 		rc = FALSE;
59*55fea89dSDan Cross 
607c478bd9Sstevel@tonic-gate 	/*
617c478bd9Sstevel@tonic-gate 	 * On error, truncate the file to its original position so that a
627c478bd9Sstevel@tonic-gate 	 * partial message is not left in the mailbox.
637c478bd9Sstevel@tonic-gate 	 */
647c478bd9Sstevel@tonic-gate 	if (rc == FALSE)
657c478bd9Sstevel@tonic-gate 		ftruncate(fileno(f), pos);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	return(rc);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate 
70b7d62af5Sceastha int
xxxcopylet(int letnum,FILE * f,int type)71*55fea89dSDan Cross xxxcopylet(int letnum, FILE *f, int type)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate 	static char	pn[] = "copylet";
747c478bd9Sstevel@tonic-gate 	char	buf[LSIZE], lastc;
757c478bd9Sstevel@tonic-gate 	char	wbuf[LSIZE];
767c478bd9Sstevel@tonic-gate 	int	n;
777c478bd9Sstevel@tonic-gate 	long	i, k;
787c478bd9Sstevel@tonic-gate 	int	num;
797c478bd9Sstevel@tonic-gate 	int	rtrncont = 1;	/* True: nondelivery&content included, or regular mail */
807c478bd9Sstevel@tonic-gate 	int	suppress = FALSE;
817c478bd9Sstevel@tonic-gate 	int	sav_suppress = FALSE; /* Did we suppress previous hdr line? */
827c478bd9Sstevel@tonic-gate 	int	print_from_struct = FALSE; /* print from hdrlines struct */
837c478bd9Sstevel@tonic-gate 					   /* rather than fgets() buffer */
847c478bd9Sstevel@tonic-gate 	int	pushrest = FALSE;
857c478bd9Sstevel@tonic-gate 	int	ctf = FALSE;
867c478bd9Sstevel@tonic-gate 	int	didafflines = FALSE;	/* Did we already put out any */
877c478bd9Sstevel@tonic-gate 					/* H_AFWDFROM lines? */
887c478bd9Sstevel@tonic-gate 	int	didrcvlines = FALSE;	/* Did we already put out any */
897c478bd9Sstevel@tonic-gate 					/* H_RECEIVED lines? */
907c478bd9Sstevel@tonic-gate 	long	clen = -1L;
917c478bd9Sstevel@tonic-gate 	int	htype;			/* header type */
927c478bd9Sstevel@tonic-gate 	struct hdrs *hptr;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	if (!sending) {
957c478bd9Sstevel@tonic-gate 		/* Clear out any saved header info from previous message */
967c478bd9Sstevel@tonic-gate 		clr_hinfo();
977c478bd9Sstevel@tonic-gate 	}
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	fseek(tmpf, let[letnum].adr, 0);
1007c478bd9Sstevel@tonic-gate 	/* Get size of message as stored into tempfile by copymt() */
1017c478bd9Sstevel@tonic-gate 	k = let[letnum+1].adr - let[letnum].adr;
1027c478bd9Sstevel@tonic-gate 	Dout(pn, 1, "(letnum = %d, type = %d), k = %ld\n", letnum, type, k);
1037c478bd9Sstevel@tonic-gate 	while (k>0) {	/* process header */
1047c478bd9Sstevel@tonic-gate 		num = ((k < sizeof(buf)) ? k+1 : sizeof(buf));
1057c478bd9Sstevel@tonic-gate 		if (fgets (buf, num, tmpf) == NULL) {
1067c478bd9Sstevel@tonic-gate 			return (FALSE);
1077c478bd9Sstevel@tonic-gate 		}
1087c478bd9Sstevel@tonic-gate 		if ((n = strlen (buf)) == 0) {
1097c478bd9Sstevel@tonic-gate 			k = 0;
1107c478bd9Sstevel@tonic-gate 			break;
1117c478bd9Sstevel@tonic-gate 		}
1127c478bd9Sstevel@tonic-gate 		k -= n;
1137c478bd9Sstevel@tonic-gate 		lastc = buf[n-1];
1147c478bd9Sstevel@tonic-gate 		if (pushrest) {
1157c478bd9Sstevel@tonic-gate 			pushrest = (lastc != '\n');
1167c478bd9Sstevel@tonic-gate 			continue;
1177c478bd9Sstevel@tonic-gate 		}
1187c478bd9Sstevel@tonic-gate 		htype = isheader (buf, &ctf);
1197c478bd9Sstevel@tonic-gate 		Dout(pn, 5, "loop 1: buf = %s, htype= %d/%s\n", buf, htype, header[htype].tag);
1207c478bd9Sstevel@tonic-gate 		if (htype == H_CLEN) {
1217c478bd9Sstevel@tonic-gate 			if (!sending) {
1227c478bd9Sstevel@tonic-gate 				savehdrs(buf,htype);
1237c478bd9Sstevel@tonic-gate 			}
1247c478bd9Sstevel@tonic-gate 			if ((hptr = hdrlines[H_CLEN].head) !=
1257c478bd9Sstevel@tonic-gate 			    (struct hdrs *)NULL) {
1267c478bd9Sstevel@tonic-gate 				clen = atol (hptr->value);
1277c478bd9Sstevel@tonic-gate 			}
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 		if (type == ZAP) {
1307c478bd9Sstevel@tonic-gate 			if (htype != FALSE) {
1317c478bd9Sstevel@tonic-gate 				pushrest = (lastc != '\n');
1327c478bd9Sstevel@tonic-gate 				continue;
1337c478bd9Sstevel@tonic-gate 			}
1347c478bd9Sstevel@tonic-gate 			/* end of header.  Print non-blank line and bail. */
1357c478bd9Sstevel@tonic-gate 			Dout(pn, 5, "ZAP end header; n=%d, buf[0] = %d\n", n, buf[0]);
1367c478bd9Sstevel@tonic-gate 			if (buf[0] != '\n') {
1377c478bd9Sstevel@tonic-gate 				if (fwrite(buf,1,n,f) != n) {
1387c478bd9Sstevel@tonic-gate 					sav_errno = errno;
1397c478bd9Sstevel@tonic-gate 					return(FALSE);
1407c478bd9Sstevel@tonic-gate 				}
1417c478bd9Sstevel@tonic-gate 			} else {
1427c478bd9Sstevel@tonic-gate 				n = 0;
1437c478bd9Sstevel@tonic-gate 			}
1447c478bd9Sstevel@tonic-gate 			break;
1457c478bd9Sstevel@tonic-gate 		}
1467c478bd9Sstevel@tonic-gate 		/* Copy From line appropriately */
1477c478bd9Sstevel@tonic-gate 		if (fwrite(buf,1,n-1,f) != n-1)  {
1487c478bd9Sstevel@tonic-gate 			sav_errno = errno;
1497c478bd9Sstevel@tonic-gate 			return(FALSE);
1507c478bd9Sstevel@tonic-gate 		}
1517c478bd9Sstevel@tonic-gate 		if (lastc != '\n') {
1527c478bd9Sstevel@tonic-gate 			if (fwrite(&lastc,1,1,f) != 1) {
1537c478bd9Sstevel@tonic-gate 				sav_errno = errno;
1547c478bd9Sstevel@tonic-gate 				return(FALSE);
1557c478bd9Sstevel@tonic-gate 			}
1567c478bd9Sstevel@tonic-gate 			continue;
1577c478bd9Sstevel@tonic-gate 		}
1587c478bd9Sstevel@tonic-gate 		switch(type) {
1597c478bd9Sstevel@tonic-gate 			case REMOTE:
1607c478bd9Sstevel@tonic-gate 				if (fprintf(f, rmtmsg, thissys) < 0)
1617c478bd9Sstevel@tonic-gate 				{
1627c478bd9Sstevel@tonic-gate 					sav_errno = errno;
1637c478bd9Sstevel@tonic-gate 					return(FALSE);
1647c478bd9Sstevel@tonic-gate 				}
165*55fea89dSDan Cross 
1667c478bd9Sstevel@tonic-gate 				break;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 			case TTY:
1697c478bd9Sstevel@tonic-gate 			case ORDINARY:
1707c478bd9Sstevel@tonic-gate 			default:
1717c478bd9Sstevel@tonic-gate 				if (fprintf(f, "\n") < 0)
1727c478bd9Sstevel@tonic-gate 				{
1737c478bd9Sstevel@tonic-gate 					sav_errno = errno;
1747c478bd9Sstevel@tonic-gate 					return(FALSE);
1757c478bd9Sstevel@tonic-gate 				}
1767c478bd9Sstevel@tonic-gate 				break;
1777c478bd9Sstevel@tonic-gate 		}
1787c478bd9Sstevel@tonic-gate 		if ((error > 0) && (dflag == 1)) {
1797c478bd9Sstevel@tonic-gate 			Dout(pn, 3, "before gendeliv(), uval = '%s'\n", uval);
1807c478bd9Sstevel@tonic-gate 			gendeliv(f, dflag, uval);
1817c478bd9Sstevel@tonic-gate 			if (!(ckdlivopts(H_TCOPY, (int*)0) & RETURN)) {
1827c478bd9Sstevel@tonic-gate 				rtrncont = 0;
1837c478bd9Sstevel@tonic-gate 			} else {
1847c478bd9Sstevel@tonic-gate 				/* Account for content-type info */
1857c478bd9Sstevel@tonic-gate 				/* of returned msg */
1867c478bd9Sstevel@tonic-gate 				if (fprintf(f, "%s %s\n", header[H_CTYPE].tag,
1877c478bd9Sstevel@tonic-gate 				    (let[letnum].text == TRUE ? "text/plain" : "application/octet-stream")) < 0)
1887c478bd9Sstevel@tonic-gate 				{
1897c478bd9Sstevel@tonic-gate 					sav_errno = errno;
1907c478bd9Sstevel@tonic-gate 					return(FALSE);
1917c478bd9Sstevel@tonic-gate 				}
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 				/* Compute Content-Length of what's being */
1947c478bd9Sstevel@tonic-gate 				/* returned... */
1957c478bd9Sstevel@tonic-gate 				i = k;
1967c478bd9Sstevel@tonic-gate 				/* Account for H_AFWDFROM, H_AFWDCNT, */
1977c478bd9Sstevel@tonic-gate 				/* H_TCOPY, or H_RECEIVED lines which may */
1987c478bd9Sstevel@tonic-gate 				/* be added later */
1997c478bd9Sstevel@tonic-gate 				if (affcnt > 0) {
2007c478bd9Sstevel@tonic-gate 					sprintf(wbuf, "%d", affcnt);
2017c478bd9Sstevel@tonic-gate 					i += (affbytecnt
2027c478bd9Sstevel@tonic-gate 						+ strlen(header[H_AFWDCNT].tag)
2037c478bd9Sstevel@tonic-gate 						+ strlen(wbuf) + 2);
2047c478bd9Sstevel@tonic-gate 				}
2057c478bd9Sstevel@tonic-gate 				if (orig_tcopy) {
2067c478bd9Sstevel@tonic-gate 				    if ((hptr = hdrlines[H_TCOPY].head) !=
2077c478bd9Sstevel@tonic-gate 							(struct hdrs *)NULL) {
2087c478bd9Sstevel@tonic-gate 				        i +=
2097c478bd9Sstevel@tonic-gate 					  strlen(hdrlines[H_TCOPY].head->value);
2107c478bd9Sstevel@tonic-gate 				    }
2117c478bd9Sstevel@tonic-gate 				}
2127c478bd9Sstevel@tonic-gate 				if ((hptr = hdrlines[H_RECEIVED].head) !=
2137c478bd9Sstevel@tonic-gate 							(struct hdrs *)NULL) {
2147c478bd9Sstevel@tonic-gate 				    i += rcvbytecnt;
2157c478bd9Sstevel@tonic-gate 				}
2167c478bd9Sstevel@tonic-gate 				/* Add in strlen of MIME-Version:, */
2177c478bd9Sstevel@tonic-gate 				/* Content-Length: and Content-Type: */
2187c478bd9Sstevel@tonic-gate 				/* values for msg being returned... */
2197c478bd9Sstevel@tonic-gate 				if ((hptr = hdrlines[H_MIMEVERS].head) !=
2207c478bd9Sstevel@tonic-gate 							(struct hdrs *)NULL) {
2217c478bd9Sstevel@tonic-gate 				    i += strlen(hdrlines[H_MIMEVERS].head->value);
2227c478bd9Sstevel@tonic-gate 				}
2237c478bd9Sstevel@tonic-gate 				if ((hptr = hdrlines[H_CTYPE].head) !=
2247c478bd9Sstevel@tonic-gate 							(struct hdrs *)NULL) {
2257c478bd9Sstevel@tonic-gate 				    i += strlen(hdrlines[H_CTYPE].head->value);
2267c478bd9Sstevel@tonic-gate 				}
2277c478bd9Sstevel@tonic-gate 				if ((hptr = hdrlines[H_CLEN].head) !=
2287c478bd9Sstevel@tonic-gate 							(struct hdrs *)NULL) {
2297c478bd9Sstevel@tonic-gate 				    i += strlen(hdrlines[H_CLEN].head->value);
2307c478bd9Sstevel@tonic-gate 				}
2317c478bd9Sstevel@tonic-gate 				if (fprintf(f, "%s %ld\n", header[H_CLEN].tag, i) < 0)
2327c478bd9Sstevel@tonic-gate 				{
2337c478bd9Sstevel@tonic-gate 					sav_errno = errno;
2347c478bd9Sstevel@tonic-gate 					return(FALSE);
2357c478bd9Sstevel@tonic-gate 				}
2367c478bd9Sstevel@tonic-gate 			}
2377c478bd9Sstevel@tonic-gate 			if (fprintf(f, "\n") < 0)
2387c478bd9Sstevel@tonic-gate 			{
2397c478bd9Sstevel@tonic-gate 				sav_errno = errno;
2407c478bd9Sstevel@tonic-gate 				return(FALSE);
2417c478bd9Sstevel@tonic-gate 			}
2427c478bd9Sstevel@tonic-gate 		}
2437c478bd9Sstevel@tonic-gate 		if (fflush(f))
2447c478bd9Sstevel@tonic-gate 		{
2457c478bd9Sstevel@tonic-gate 			sav_errno = errno;
2467c478bd9Sstevel@tonic-gate 			return(FALSE);
2477c478bd9Sstevel@tonic-gate 		}
248*55fea89dSDan Cross 
2497c478bd9Sstevel@tonic-gate 		break;
2507c478bd9Sstevel@tonic-gate 	}
2517c478bd9Sstevel@tonic-gate 	/* if not ZAP, copy balance of header */
2527c478bd9Sstevel@tonic-gate 	n = 0;
2537c478bd9Sstevel@tonic-gate 	if ((type != ZAP) && rtrncont)
2547c478bd9Sstevel@tonic-gate 		while (k>0 || n>0) {
2557c478bd9Sstevel@tonic-gate 			if ((n > 0) && !suppress) {
2567c478bd9Sstevel@tonic-gate 				if (print_from_struct == TRUE) {
2577c478bd9Sstevel@tonic-gate 					if (printhdr (type, htype, hptr, f) < 0) {
2587c478bd9Sstevel@tonic-gate 						return (FALSE);
2597c478bd9Sstevel@tonic-gate 					}
2607c478bd9Sstevel@tonic-gate 				} else {
2617c478bd9Sstevel@tonic-gate 				    if (sel_disp(type, htype, buf) >= 0) {
2627c478bd9Sstevel@tonic-gate 					if (fwrite(buf,1,n,f) != n)  {
2637c478bd9Sstevel@tonic-gate 						sav_errno = errno;
2647c478bd9Sstevel@tonic-gate 						return(FALSE);
2657c478bd9Sstevel@tonic-gate 					}
2667c478bd9Sstevel@tonic-gate 				    }
2677c478bd9Sstevel@tonic-gate 				}
2687c478bd9Sstevel@tonic-gate 				if (htype == H_DATE) {
2697c478bd9Sstevel@tonic-gate 					dumprcv(type, htype,&didrcvlines,&suppress,f);
2707c478bd9Sstevel@tonic-gate 					dumpaff(type, htype,&didafflines,&suppress,f);
2717c478bd9Sstevel@tonic-gate 				}
2727c478bd9Sstevel@tonic-gate 			}
2737c478bd9Sstevel@tonic-gate 			if (k <= 0) {
2747c478bd9Sstevel@tonic-gate 				/* Can only get here if k=0 && n>0, which occurs */
2757c478bd9Sstevel@tonic-gate 				/* in a message with header lines but no content. */
2767c478bd9Sstevel@tonic-gate 				/* If we haven't already done it, force out any */
2777c478bd9Sstevel@tonic-gate 				/* H_AFWDFROM or H_RECEIVED lines */
2787c478bd9Sstevel@tonic-gate 				dumprcv(type, -1,&didrcvlines,&suppress,f);
2797c478bd9Sstevel@tonic-gate 				dumpaff(type, -1,&didafflines,&suppress,f);
2807c478bd9Sstevel@tonic-gate 				break;
2817c478bd9Sstevel@tonic-gate 			}
2827c478bd9Sstevel@tonic-gate 			num = ((k < sizeof(buf)) ? k+1 : sizeof(buf));
2837c478bd9Sstevel@tonic-gate 			if (fgets (buf, num, tmpf) == NULL) {
2847c478bd9Sstevel@tonic-gate 				return (FALSE);
2857c478bd9Sstevel@tonic-gate 			}
2867c478bd9Sstevel@tonic-gate 			n = strlen (buf);
2877c478bd9Sstevel@tonic-gate 			k -= n;
2887c478bd9Sstevel@tonic-gate 			lastc = buf[n-1];
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 			if (pushrest) {
2917c478bd9Sstevel@tonic-gate 				pushrest = (lastc != '\n');
2927c478bd9Sstevel@tonic-gate 				continue;
2937c478bd9Sstevel@tonic-gate 			}
2947c478bd9Sstevel@tonic-gate 			sav_suppress = suppress;
2957c478bd9Sstevel@tonic-gate 			suppress = FALSE;
2967c478bd9Sstevel@tonic-gate 			print_from_struct = FALSE;
2977c478bd9Sstevel@tonic-gate 			htype = isheader (buf, &ctf);
2987c478bd9Sstevel@tonic-gate 			Dout(pn, 5, "loop 2: buf = %s, htype= %d/%s\n", buf, htype, header[htype].tag);
2997c478bd9Sstevel@tonic-gate 			/* The following order is defined in the MTA documents. */
3007c478bd9Sstevel@tonic-gate 			switch (htype) {
3017c478bd9Sstevel@tonic-gate 			case H_CONT:
3027c478bd9Sstevel@tonic-gate 			    if (sending) {
3037c478bd9Sstevel@tonic-gate 				suppress = sav_suppress;
3047c478bd9Sstevel@tonic-gate 			    }
3057c478bd9Sstevel@tonic-gate 			    continue;
3067c478bd9Sstevel@tonic-gate 			case H_TCOPY:
3077c478bd9Sstevel@tonic-gate 			case H_MIMEVERS:
3087c478bd9Sstevel@tonic-gate 			case H_CTYPE:
3097c478bd9Sstevel@tonic-gate 			case H_CLEN:
3107c478bd9Sstevel@tonic-gate 				if (!sending) {
3117c478bd9Sstevel@tonic-gate 					savehdrs(buf,htype);
3127c478bd9Sstevel@tonic-gate 				}
3137c478bd9Sstevel@tonic-gate 				hptr = hdrlines[htype].head;
3147c478bd9Sstevel@tonic-gate 				if (htype == H_CLEN) {
3157c478bd9Sstevel@tonic-gate 					clen = atol (hptr->value);
3167c478bd9Sstevel@tonic-gate 				}
3177c478bd9Sstevel@tonic-gate 				/*
3187c478bd9Sstevel@tonic-gate 				 * Use values saved in hdrlines[] structure
3197c478bd9Sstevel@tonic-gate 				 * rather than what was read from tmp file.
3207c478bd9Sstevel@tonic-gate 				 */
3217c478bd9Sstevel@tonic-gate 				print_from_struct = TRUE;
3227c478bd9Sstevel@tonic-gate 				/* FALLTHROUGH */
3237c478bd9Sstevel@tonic-gate 			case H_EOH:
3247c478bd9Sstevel@tonic-gate 			case H_AFWDFROM:
3257c478bd9Sstevel@tonic-gate 			case H_AFWDCNT:
3267c478bd9Sstevel@tonic-gate 			case H_RECEIVED:
3277c478bd9Sstevel@tonic-gate 				dumprcv(type, htype,&didrcvlines,&suppress,f);
3287c478bd9Sstevel@tonic-gate 				dumpaff(type, htype,&didafflines,&suppress,f);
3297c478bd9Sstevel@tonic-gate 				continue;	/* next header line */
3307c478bd9Sstevel@tonic-gate 			default:
3317c478bd9Sstevel@tonic-gate 				pushrest = (lastc != '\n');
3327c478bd9Sstevel@tonic-gate 				continue;	/* next header line */
3337c478bd9Sstevel@tonic-gate 			case FALSE:	/* end of header */
3347c478bd9Sstevel@tonic-gate 				break;
3357c478bd9Sstevel@tonic-gate 			}
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 			/* Found the blank line after the headers. */
3387c478bd9Sstevel@tonic-gate 			if (n > 0) {
3397c478bd9Sstevel@tonic-gate 				if (fwrite(buf,1,n,f) != n)  {
3407c478bd9Sstevel@tonic-gate 					sav_errno = errno;
3417c478bd9Sstevel@tonic-gate 					return(FALSE);
3427c478bd9Sstevel@tonic-gate 				}
3437c478bd9Sstevel@tonic-gate 			}
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 			Dout(pn, 3,", let[%d].text = %s\n",
3467c478bd9Sstevel@tonic-gate 				letnum, (let[letnum].text ? "TRUE" : "FALSE"));
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 			if ((type == TTY) && (let[letnum].text == FALSE) && !pflg) {
3497c478bd9Sstevel@tonic-gate 				if (fprintf (f, "\n%s\n", binmsg) < 0)
3507c478bd9Sstevel@tonic-gate 				{
3517c478bd9Sstevel@tonic-gate 					sav_errno = errno;
3527c478bd9Sstevel@tonic-gate 					return(FALSE);
3537c478bd9Sstevel@tonic-gate 				}
3547c478bd9Sstevel@tonic-gate 				return (TRUE);
3557c478bd9Sstevel@tonic-gate 			}
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 			if (n == 1 && buf[0] == '\n') {
3587c478bd9Sstevel@tonic-gate 				n = 0;
3597c478bd9Sstevel@tonic-gate 			}
3607c478bd9Sstevel@tonic-gate 			break;
3617c478bd9Sstevel@tonic-gate 		}
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	Dout(pn, 1, "header processed, clen/k/n = %ld/%ld/%d\n", clen, k, n);
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	if (clen >= 0) {
3667c478bd9Sstevel@tonic-gate 		if (((clen - n) == k) || ((clen - n) == (k - 1))) {
3677c478bd9Sstevel@tonic-gate 			k = clen - n;
3687c478bd9Sstevel@tonic-gate 		} else {
3697c478bd9Sstevel@tonic-gate 			/* probable content-length mismatch. show it ALL! */
3707c478bd9Sstevel@tonic-gate 			Dout(pn, 1, "clen conflict. using k = %ld\n", k);
3717c478bd9Sstevel@tonic-gate 		}
3727c478bd9Sstevel@tonic-gate 	}
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	/* copy balance of message */
3757c478bd9Sstevel@tonic-gate 	if (rtrncont)
3767c478bd9Sstevel@tonic-gate 		while (k > 0) {
3777c478bd9Sstevel@tonic-gate 			num = ((k < sizeof(buf)) ? k : sizeof(buf));
3787c478bd9Sstevel@tonic-gate 			if ((n = fread (buf, 1, num, tmpf)) <= 0) {
3797c478bd9Sstevel@tonic-gate 				Dout(pn, 1, "content-length mismatch. return(FALSE)\n");
3807c478bd9Sstevel@tonic-gate 				return(FALSE);
3817c478bd9Sstevel@tonic-gate 			}
3827c478bd9Sstevel@tonic-gate 			k -= n;
3837c478bd9Sstevel@tonic-gate 			if (fwrite(buf,1,n,f) != n)  {
3847c478bd9Sstevel@tonic-gate 				sav_errno = errno;
3857c478bd9Sstevel@tonic-gate 				return(FALSE);
3867c478bd9Sstevel@tonic-gate 			}
3877c478bd9Sstevel@tonic-gate 		}
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 	Dout(pn, 3, "body processed, k=%ld\n", k);
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 	if (rtrncont && type != ZAP && type != REMOTE) {
3927c478bd9Sstevel@tonic-gate 		if (fwrite("\n",1,1,f) != 1)  {
3937c478bd9Sstevel@tonic-gate 			sav_errno = errno;
3947c478bd9Sstevel@tonic-gate 			return(FALSE);
3957c478bd9Sstevel@tonic-gate 		}
3967c478bd9Sstevel@tonic-gate 	}
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 	return(TRUE);
3997c478bd9Sstevel@tonic-gate }
400