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