1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 28*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include "mail.h" 34*7c478bd9Sstevel@tonic-gate /* 35*7c478bd9Sstevel@tonic-gate NAME 36*7c478bd9Sstevel@tonic-gate copylet - copy a given letter to a file pointer 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate SYNOPSIS 39*7c478bd9Sstevel@tonic-gate int copylet(int letnum, FILE *f, int type) 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate DESCRIPTION 42*7c478bd9Sstevel@tonic-gate Copylet() will copy the letter "letnum" to the 43*7c478bd9Sstevel@tonic-gate given file pointer. 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate letnum -> index into: letter table 46*7c478bd9Sstevel@tonic-gate f -> file pointer to copy file to 47*7c478bd9Sstevel@tonic-gate type -> copy type 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate Returns TRUE on a completely successful copy. 50*7c478bd9Sstevel@tonic-gate */ 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate copylet(letnum, f, type) 53*7c478bd9Sstevel@tonic-gate register FILE *f; 54*7c478bd9Sstevel@tonic-gate { 55*7c478bd9Sstevel@tonic-gate int pos = ftell(f); 56*7c478bd9Sstevel@tonic-gate int rc = xxxcopylet(letnum, f, type); 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate if (fflush(f) != 0) 59*7c478bd9Sstevel@tonic-gate rc = FALSE; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* 62*7c478bd9Sstevel@tonic-gate * On error, truncate the file to its original position so that a 63*7c478bd9Sstevel@tonic-gate * partial message is not left in the mailbox. 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate if (rc == FALSE) 66*7c478bd9Sstevel@tonic-gate ftruncate(fileno(f), pos); 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate return(rc); 69*7c478bd9Sstevel@tonic-gate } 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate xxxcopylet(letnum, f, type) 72*7c478bd9Sstevel@tonic-gate register FILE *f; 73*7c478bd9Sstevel@tonic-gate { 74*7c478bd9Sstevel@tonic-gate static char pn[] = "copylet"; 75*7c478bd9Sstevel@tonic-gate char buf[LSIZE], lastc; 76*7c478bd9Sstevel@tonic-gate char wbuf[LSIZE]; 77*7c478bd9Sstevel@tonic-gate int n; 78*7c478bd9Sstevel@tonic-gate long i, k; 79*7c478bd9Sstevel@tonic-gate int num; 80*7c478bd9Sstevel@tonic-gate int rtrncont = 1; /* True: nondelivery&content included, or regular mail */ 81*7c478bd9Sstevel@tonic-gate int suppress = FALSE; 82*7c478bd9Sstevel@tonic-gate int sav_suppress = FALSE; /* Did we suppress previous hdr line? */ 83*7c478bd9Sstevel@tonic-gate int print_from_struct = FALSE; /* print from hdrlines struct */ 84*7c478bd9Sstevel@tonic-gate /* rather than fgets() buffer */ 85*7c478bd9Sstevel@tonic-gate int pushrest = FALSE; 86*7c478bd9Sstevel@tonic-gate int ctf = FALSE; 87*7c478bd9Sstevel@tonic-gate int didafflines = FALSE; /* Did we already put out any */ 88*7c478bd9Sstevel@tonic-gate /* H_AFWDFROM lines? */ 89*7c478bd9Sstevel@tonic-gate int didrcvlines = FALSE; /* Did we already put out any */ 90*7c478bd9Sstevel@tonic-gate /* H_RECEIVED lines? */ 91*7c478bd9Sstevel@tonic-gate long clen = -1L; 92*7c478bd9Sstevel@tonic-gate int htype; /* header type */ 93*7c478bd9Sstevel@tonic-gate int sav_htype; /* Header type of last non-H_CONT header line */ 94*7c478bd9Sstevel@tonic-gate struct hdrs *hptr; 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate if (!sending) { 97*7c478bd9Sstevel@tonic-gate /* Clear out any saved header info from previous message */ 98*7c478bd9Sstevel@tonic-gate clr_hinfo(); 99*7c478bd9Sstevel@tonic-gate } 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate fseek(tmpf, let[letnum].adr, 0); 102*7c478bd9Sstevel@tonic-gate /* Get size of message as stored into tempfile by copymt() */ 103*7c478bd9Sstevel@tonic-gate k = let[letnum+1].adr - let[letnum].adr; 104*7c478bd9Sstevel@tonic-gate Dout(pn, 1, "(letnum = %d, type = %d), k = %ld\n", letnum, type, k); 105*7c478bd9Sstevel@tonic-gate while (k>0) { /* process header */ 106*7c478bd9Sstevel@tonic-gate num = ((k < sizeof(buf)) ? k+1 : sizeof(buf)); 107*7c478bd9Sstevel@tonic-gate if (fgets (buf, num, tmpf) == NULL) { 108*7c478bd9Sstevel@tonic-gate return (FALSE); 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate if ((n = strlen (buf)) == 0) { 111*7c478bd9Sstevel@tonic-gate k = 0; 112*7c478bd9Sstevel@tonic-gate break; 113*7c478bd9Sstevel@tonic-gate } 114*7c478bd9Sstevel@tonic-gate k -= n; 115*7c478bd9Sstevel@tonic-gate lastc = buf[n-1]; 116*7c478bd9Sstevel@tonic-gate if (pushrest) { 117*7c478bd9Sstevel@tonic-gate pushrest = (lastc != '\n'); 118*7c478bd9Sstevel@tonic-gate continue; 119*7c478bd9Sstevel@tonic-gate } 120*7c478bd9Sstevel@tonic-gate htype = isheader (buf, &ctf); 121*7c478bd9Sstevel@tonic-gate Dout(pn, 5, "loop 1: buf = %s, htype= %d/%s\n", buf, htype, header[htype].tag); 122*7c478bd9Sstevel@tonic-gate if (htype == H_CLEN) { 123*7c478bd9Sstevel@tonic-gate if (!sending) { 124*7c478bd9Sstevel@tonic-gate savehdrs(buf,htype); 125*7c478bd9Sstevel@tonic-gate } 126*7c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CLEN].head) != 127*7c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 128*7c478bd9Sstevel@tonic-gate clen = atol (hptr->value); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate if (type == ZAP) { 132*7c478bd9Sstevel@tonic-gate if (htype != FALSE) { 133*7c478bd9Sstevel@tonic-gate pushrest = (lastc != '\n'); 134*7c478bd9Sstevel@tonic-gate continue; 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate /* end of header. Print non-blank line and bail. */ 137*7c478bd9Sstevel@tonic-gate Dout(pn, 5, "ZAP end header; n=%d, buf[0] = %d\n", n, buf[0]); 138*7c478bd9Sstevel@tonic-gate if (buf[0] != '\n') { 139*7c478bd9Sstevel@tonic-gate if (fwrite(buf,1,n,f) != n) { 140*7c478bd9Sstevel@tonic-gate sav_errno = errno; 141*7c478bd9Sstevel@tonic-gate return(FALSE); 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate } else { 144*7c478bd9Sstevel@tonic-gate n = 0; 145*7c478bd9Sstevel@tonic-gate } 146*7c478bd9Sstevel@tonic-gate break; 147*7c478bd9Sstevel@tonic-gate } 148*7c478bd9Sstevel@tonic-gate /* Copy From line appropriately */ 149*7c478bd9Sstevel@tonic-gate if (fwrite(buf,1,n-1,f) != n-1) { 150*7c478bd9Sstevel@tonic-gate sav_errno = errno; 151*7c478bd9Sstevel@tonic-gate return(FALSE); 152*7c478bd9Sstevel@tonic-gate } 153*7c478bd9Sstevel@tonic-gate if (lastc != '\n') { 154*7c478bd9Sstevel@tonic-gate if (fwrite(&lastc,1,1,f) != 1) { 155*7c478bd9Sstevel@tonic-gate sav_errno = errno; 156*7c478bd9Sstevel@tonic-gate return(FALSE); 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate continue; 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate switch(type) { 161*7c478bd9Sstevel@tonic-gate case REMOTE: 162*7c478bd9Sstevel@tonic-gate if (fprintf(f, rmtmsg, thissys) < 0) 163*7c478bd9Sstevel@tonic-gate { 164*7c478bd9Sstevel@tonic-gate sav_errno = errno; 165*7c478bd9Sstevel@tonic-gate return(FALSE); 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate break; 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate case TTY: 171*7c478bd9Sstevel@tonic-gate case ORDINARY: 172*7c478bd9Sstevel@tonic-gate default: 173*7c478bd9Sstevel@tonic-gate if (fprintf(f, "\n") < 0) 174*7c478bd9Sstevel@tonic-gate { 175*7c478bd9Sstevel@tonic-gate sav_errno = errno; 176*7c478bd9Sstevel@tonic-gate return(FALSE); 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate break; 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate if ((error > 0) && (dflag == 1)) { 181*7c478bd9Sstevel@tonic-gate Dout(pn, 3, "before gendeliv(), uval = '%s'\n", uval); 182*7c478bd9Sstevel@tonic-gate gendeliv(f, dflag, uval); 183*7c478bd9Sstevel@tonic-gate if (!(ckdlivopts(H_TCOPY, (int*)0) & RETURN)) { 184*7c478bd9Sstevel@tonic-gate rtrncont = 0; 185*7c478bd9Sstevel@tonic-gate } else { 186*7c478bd9Sstevel@tonic-gate /* Account for content-type info */ 187*7c478bd9Sstevel@tonic-gate /* of returned msg */ 188*7c478bd9Sstevel@tonic-gate if (fprintf(f, "%s %s\n", header[H_CTYPE].tag, 189*7c478bd9Sstevel@tonic-gate (let[letnum].text == TRUE ? "text/plain" : "application/octet-stream")) < 0) 190*7c478bd9Sstevel@tonic-gate { 191*7c478bd9Sstevel@tonic-gate sav_errno = errno; 192*7c478bd9Sstevel@tonic-gate return(FALSE); 193*7c478bd9Sstevel@tonic-gate } 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate /* Compute Content-Length of what's being */ 196*7c478bd9Sstevel@tonic-gate /* returned... */ 197*7c478bd9Sstevel@tonic-gate i = k; 198*7c478bd9Sstevel@tonic-gate /* Account for H_AFWDFROM, H_AFWDCNT, */ 199*7c478bd9Sstevel@tonic-gate /* H_TCOPY, or H_RECEIVED lines which may */ 200*7c478bd9Sstevel@tonic-gate /* be added later */ 201*7c478bd9Sstevel@tonic-gate if (affcnt > 0) { 202*7c478bd9Sstevel@tonic-gate sprintf(wbuf, "%d", affcnt); 203*7c478bd9Sstevel@tonic-gate i += (affbytecnt 204*7c478bd9Sstevel@tonic-gate + strlen(header[H_AFWDCNT].tag) 205*7c478bd9Sstevel@tonic-gate + strlen(wbuf) + 2); 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate if (orig_tcopy) { 208*7c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_TCOPY].head) != 209*7c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 210*7c478bd9Sstevel@tonic-gate i += 211*7c478bd9Sstevel@tonic-gate strlen(hdrlines[H_TCOPY].head->value); 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_RECEIVED].head) != 215*7c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 216*7c478bd9Sstevel@tonic-gate i += rcvbytecnt; 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate /* Add in strlen of MIME-Version:, */ 219*7c478bd9Sstevel@tonic-gate /* Content-Length: and Content-Type: */ 220*7c478bd9Sstevel@tonic-gate /* values for msg being returned... */ 221*7c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_MIMEVERS].head) != 222*7c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 223*7c478bd9Sstevel@tonic-gate i += strlen(hdrlines[H_MIMEVERS].head->value); 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CTYPE].head) != 226*7c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 227*7c478bd9Sstevel@tonic-gate i += strlen(hdrlines[H_CTYPE].head->value); 228*7c478bd9Sstevel@tonic-gate } 229*7c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CLEN].head) != 230*7c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 231*7c478bd9Sstevel@tonic-gate i += strlen(hdrlines[H_CLEN].head->value); 232*7c478bd9Sstevel@tonic-gate } 233*7c478bd9Sstevel@tonic-gate if (fprintf(f, "%s %ld\n", header[H_CLEN].tag, i) < 0) 234*7c478bd9Sstevel@tonic-gate { 235*7c478bd9Sstevel@tonic-gate sav_errno = errno; 236*7c478bd9Sstevel@tonic-gate return(FALSE); 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate } 239*7c478bd9Sstevel@tonic-gate if (fprintf(f, "\n") < 0) 240*7c478bd9Sstevel@tonic-gate { 241*7c478bd9Sstevel@tonic-gate sav_errno = errno; 242*7c478bd9Sstevel@tonic-gate return(FALSE); 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate } 245*7c478bd9Sstevel@tonic-gate if (fflush(f)) 246*7c478bd9Sstevel@tonic-gate { 247*7c478bd9Sstevel@tonic-gate sav_errno = errno; 248*7c478bd9Sstevel@tonic-gate return(FALSE); 249*7c478bd9Sstevel@tonic-gate } 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate break; 252*7c478bd9Sstevel@tonic-gate } 253*7c478bd9Sstevel@tonic-gate /* if not ZAP, copy balance of header */ 254*7c478bd9Sstevel@tonic-gate n = 0; 255*7c478bd9Sstevel@tonic-gate if ((type != ZAP) && rtrncont) 256*7c478bd9Sstevel@tonic-gate while (k>0 || n>0) { 257*7c478bd9Sstevel@tonic-gate if ((n > 0) && !suppress) { 258*7c478bd9Sstevel@tonic-gate if (print_from_struct == TRUE) { 259*7c478bd9Sstevel@tonic-gate if (printhdr (type, htype, hptr, f) < 0) { 260*7c478bd9Sstevel@tonic-gate return (FALSE); 261*7c478bd9Sstevel@tonic-gate } 262*7c478bd9Sstevel@tonic-gate } else { 263*7c478bd9Sstevel@tonic-gate if (sel_disp(type, htype, buf) >= 0) { 264*7c478bd9Sstevel@tonic-gate if (fwrite(buf,1,n,f) != n) { 265*7c478bd9Sstevel@tonic-gate sav_errno = errno; 266*7c478bd9Sstevel@tonic-gate return(FALSE); 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate } 269*7c478bd9Sstevel@tonic-gate } 270*7c478bd9Sstevel@tonic-gate if (htype == H_DATE) { 271*7c478bd9Sstevel@tonic-gate dumprcv(type, htype,&didrcvlines,&suppress,f); 272*7c478bd9Sstevel@tonic-gate dumpaff(type, htype,&didafflines,&suppress,f); 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate } 275*7c478bd9Sstevel@tonic-gate if (k <= 0) { 276*7c478bd9Sstevel@tonic-gate /* Can only get here if k=0 && n>0, which occurs */ 277*7c478bd9Sstevel@tonic-gate /* in a message with header lines but no content. */ 278*7c478bd9Sstevel@tonic-gate /* If we haven't already done it, force out any */ 279*7c478bd9Sstevel@tonic-gate /* H_AFWDFROM or H_RECEIVED lines */ 280*7c478bd9Sstevel@tonic-gate dumprcv(type, -1,&didrcvlines,&suppress,f); 281*7c478bd9Sstevel@tonic-gate dumpaff(type, -1,&didafflines,&suppress,f); 282*7c478bd9Sstevel@tonic-gate break; 283*7c478bd9Sstevel@tonic-gate } 284*7c478bd9Sstevel@tonic-gate num = ((k < sizeof(buf)) ? k+1 : sizeof(buf)); 285*7c478bd9Sstevel@tonic-gate if (fgets (buf, num, tmpf) == NULL) { 286*7c478bd9Sstevel@tonic-gate return (FALSE); 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate n = strlen (buf); 289*7c478bd9Sstevel@tonic-gate k -= n; 290*7c478bd9Sstevel@tonic-gate lastc = buf[n-1]; 291*7c478bd9Sstevel@tonic-gate 292*7c478bd9Sstevel@tonic-gate if (pushrest) { 293*7c478bd9Sstevel@tonic-gate pushrest = (lastc != '\n'); 294*7c478bd9Sstevel@tonic-gate continue; 295*7c478bd9Sstevel@tonic-gate } 296*7c478bd9Sstevel@tonic-gate sav_suppress = suppress; 297*7c478bd9Sstevel@tonic-gate suppress = FALSE; 298*7c478bd9Sstevel@tonic-gate print_from_struct = FALSE; 299*7c478bd9Sstevel@tonic-gate sav_htype = htype; 300*7c478bd9Sstevel@tonic-gate htype = isheader (buf, &ctf); 301*7c478bd9Sstevel@tonic-gate Dout(pn, 5, "loop 2: buf = %s, htype= %d/%s\n", buf, htype, header[htype].tag); 302*7c478bd9Sstevel@tonic-gate /* The following order is defined in the MTA documents. */ 303*7c478bd9Sstevel@tonic-gate switch (htype) { 304*7c478bd9Sstevel@tonic-gate case H_CONT: 305*7c478bd9Sstevel@tonic-gate if (sending) { 306*7c478bd9Sstevel@tonic-gate suppress = sav_suppress; 307*7c478bd9Sstevel@tonic-gate } 308*7c478bd9Sstevel@tonic-gate continue; 309*7c478bd9Sstevel@tonic-gate case H_TCOPY: 310*7c478bd9Sstevel@tonic-gate case H_MIMEVERS: 311*7c478bd9Sstevel@tonic-gate case H_CTYPE: 312*7c478bd9Sstevel@tonic-gate case H_CLEN: 313*7c478bd9Sstevel@tonic-gate if (!sending) { 314*7c478bd9Sstevel@tonic-gate savehdrs(buf,htype); 315*7c478bd9Sstevel@tonic-gate } 316*7c478bd9Sstevel@tonic-gate hptr = hdrlines[htype].head; 317*7c478bd9Sstevel@tonic-gate if (htype == H_CLEN) { 318*7c478bd9Sstevel@tonic-gate clen = atol (hptr->value); 319*7c478bd9Sstevel@tonic-gate } 320*7c478bd9Sstevel@tonic-gate /* 321*7c478bd9Sstevel@tonic-gate * Use values saved in hdrlines[] structure 322*7c478bd9Sstevel@tonic-gate * rather than what was read from tmp file. 323*7c478bd9Sstevel@tonic-gate */ 324*7c478bd9Sstevel@tonic-gate print_from_struct = TRUE; 325*7c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 326*7c478bd9Sstevel@tonic-gate case H_EOH: 327*7c478bd9Sstevel@tonic-gate case H_AFWDFROM: 328*7c478bd9Sstevel@tonic-gate case H_AFWDCNT: 329*7c478bd9Sstevel@tonic-gate case H_RECEIVED: 330*7c478bd9Sstevel@tonic-gate dumprcv(type, htype,&didrcvlines,&suppress,f); 331*7c478bd9Sstevel@tonic-gate dumpaff(type, htype,&didafflines,&suppress,f); 332*7c478bd9Sstevel@tonic-gate continue; /* next header line */ 333*7c478bd9Sstevel@tonic-gate default: 334*7c478bd9Sstevel@tonic-gate pushrest = (lastc != '\n'); 335*7c478bd9Sstevel@tonic-gate continue; /* next header line */ 336*7c478bd9Sstevel@tonic-gate case FALSE: /* end of header */ 337*7c478bd9Sstevel@tonic-gate break; 338*7c478bd9Sstevel@tonic-gate } 339*7c478bd9Sstevel@tonic-gate 340*7c478bd9Sstevel@tonic-gate /* Found the blank line after the headers. */ 341*7c478bd9Sstevel@tonic-gate if (n > 0) { 342*7c478bd9Sstevel@tonic-gate if (fwrite(buf,1,n,f) != n) { 343*7c478bd9Sstevel@tonic-gate sav_errno = errno; 344*7c478bd9Sstevel@tonic-gate return(FALSE); 345*7c478bd9Sstevel@tonic-gate } 346*7c478bd9Sstevel@tonic-gate } 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate Dout(pn, 3,", let[%d].text = %s\n", 349*7c478bd9Sstevel@tonic-gate letnum, (let[letnum].text ? "TRUE" : "FALSE")); 350*7c478bd9Sstevel@tonic-gate 351*7c478bd9Sstevel@tonic-gate if ((type == TTY) && (let[letnum].text == FALSE) && !pflg) { 352*7c478bd9Sstevel@tonic-gate if (fprintf (f, "\n%s\n", binmsg) < 0) 353*7c478bd9Sstevel@tonic-gate { 354*7c478bd9Sstevel@tonic-gate sav_errno = errno; 355*7c478bd9Sstevel@tonic-gate return(FALSE); 356*7c478bd9Sstevel@tonic-gate } 357*7c478bd9Sstevel@tonic-gate return (TRUE); 358*7c478bd9Sstevel@tonic-gate } 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate if (n == 1 && buf[0] == '\n') { 361*7c478bd9Sstevel@tonic-gate n = 0; 362*7c478bd9Sstevel@tonic-gate } 363*7c478bd9Sstevel@tonic-gate break; 364*7c478bd9Sstevel@tonic-gate } 365*7c478bd9Sstevel@tonic-gate 366*7c478bd9Sstevel@tonic-gate Dout(pn, 1, "header processed, clen/k/n = %ld/%ld/%d\n", clen, k, n); 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate if (clen >= 0) { 369*7c478bd9Sstevel@tonic-gate if (((clen - n) == k) || ((clen - n) == (k - 1))) { 370*7c478bd9Sstevel@tonic-gate k = clen - n; 371*7c478bd9Sstevel@tonic-gate } else { 372*7c478bd9Sstevel@tonic-gate /* probable content-length mismatch. show it ALL! */ 373*7c478bd9Sstevel@tonic-gate Dout(pn, 1, "clen conflict. using k = %ld\n", k); 374*7c478bd9Sstevel@tonic-gate } 375*7c478bd9Sstevel@tonic-gate } 376*7c478bd9Sstevel@tonic-gate 377*7c478bd9Sstevel@tonic-gate /* copy balance of message */ 378*7c478bd9Sstevel@tonic-gate if (rtrncont) 379*7c478bd9Sstevel@tonic-gate while (k > 0) { 380*7c478bd9Sstevel@tonic-gate num = ((k < sizeof(buf)) ? k : sizeof(buf)); 381*7c478bd9Sstevel@tonic-gate if ((n = fread (buf, 1, num, tmpf)) <= 0) { 382*7c478bd9Sstevel@tonic-gate Dout(pn, 1, "content-length mismatch. return(FALSE)\n"); 383*7c478bd9Sstevel@tonic-gate return(FALSE); 384*7c478bd9Sstevel@tonic-gate } 385*7c478bd9Sstevel@tonic-gate k -= n; 386*7c478bd9Sstevel@tonic-gate if (fwrite(buf,1,n,f) != n) { 387*7c478bd9Sstevel@tonic-gate sav_errno = errno; 388*7c478bd9Sstevel@tonic-gate return(FALSE); 389*7c478bd9Sstevel@tonic-gate } 390*7c478bd9Sstevel@tonic-gate } 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate Dout(pn, 3, "body processed, k=%ld\n", k); 393*7c478bd9Sstevel@tonic-gate 394*7c478bd9Sstevel@tonic-gate if (rtrncont && type != ZAP && type != REMOTE) { 395*7c478bd9Sstevel@tonic-gate if (fwrite("\n",1,1,f) != 1) { 396*7c478bd9Sstevel@tonic-gate sav_errno = errno; 397*7c478bd9Sstevel@tonic-gate return(FALSE); 398*7c478bd9Sstevel@tonic-gate } 399*7c478bd9Sstevel@tonic-gate } 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate return(TRUE); 402*7c478bd9Sstevel@tonic-gate } 403