4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
31 copymt - copy mail (f1) to temp (f2)
34 void copymt(FILE *f1, FILE *f2)
37 The mail messages in /var/mail are copied into
38 the temp file. The file pointers f1 and f2 point
39 to the files, respectively.
44 register FILE *f1
, *f2
;
46 static char pn
[] = "copymt";
49 int StartNewMsg
= TRUE
;
52 int ctf
= FALSE
; /* header continuation flag */
55 int cflg
= 0; /* found Content-length in header */
57 Dout(pn
, 0,"entered\n");
61 let
[0].text
= TRUE
; /* until proven otherwise.... */
64 nextadr
= let
[nlet
].adr
;
67 while ((n
= getaline(line
, sizeof line
, f1
)) > 0) {
70 } else if ((hdr
= isheader (line
, &ctf
)) == FALSE
) {
71 ctf
= FALSE
; /* next line can't be cont. */
73 if (!hdr
&& cflg
) { /* nonheader, Content-length seen */
74 if (clen
< n
) { /* read too much */
75 /* NB: this only can happen if the content-length
76 * says a smaller number than what's seen on the
77 * first non-header line.
79 if (let
[nlet
-1].text
== TRUE
) {
80 let
[nlet
-1].text
= istext((unsigned char*)line
,clen
);
81 Dout(pn
, 0, "1, let[%d].text = %s\n",
83 (let
[nlet
-1].text
? "TRUE":"FALSE"));
85 if (fwrite(line
,1,(int)clen
,f2
) != clen
) {
86 fclose(f1
); fclose(f2
);
88 "Write error in copymt()");
93 strmove (line
, line
+clen
);
96 hdr
= isheader(line
, &ctf
);
100 if (n
== 1 && line
[0] == '\n'){ /* leading empty line */
105 if (let
[nlet
-1].text
== TRUE
) {
106 let
[nlet
-1].text
= istext((unsigned char*)line
,n
);
107 Dout(pn
, 0, "2, let[%d].text = %s\n",
109 (let
[nlet
-1].text
? "TRUE" : "FALSE"));
111 if (fwrite(line
,1,n
,f2
) != n
) {
112 fclose(f1
); fclose(f2
);
114 "Write error in copymt()");
121 n
= clen
< sizeof line
? clen
: sizeof line
;
122 if ((n
= fread (line
, 1, n
, f1
)) <= 0) {
124 "%c%s:\tYour mailfile was found to be corrupted.\n",
127 "\t(Unexpected end-of-file).\n");
129 "\tMessage #%d may be truncated.%c\n\n",
132 clen
= 0; /* stop the loop */
135 /* All done, go to top for next message */
144 if(nlet
>= (MAXLET
-2)) {
146 fprintf(stderr
,"%s: Too many letters, overflowing letters concatenated\n\n",program
);
150 let
[nlet
++].adr
= nextadr
;
151 let
[nlet
].text
= TRUE
;
152 let
[nlet
].change
= ' ';
154 Dout(pn
, 5, "setting StartNewMsg to FALSE\n");
162 cflg
= TRUE
; /* mark for clen processing */
163 clen
= atol (strpbrk (line
, ":")+1);
173 errmsg(E_FILE
,"mailfile does not begin with a 'From' line");
177 if (let
[nlet
-1].text
== TRUE
) {
178 let
[nlet
-1].text
= istext((unsigned char*)line
,n
);
179 Dout(pn
, 5,"3, let[%d].text = %s\n",
180 nlet
-1, (let
[nlet
-1].text
? "TRUE" : "FALSE"));
182 if (fwrite(line
,1,n
,f2
) != n
) {
185 errmsg(E_FILE
,"Write error in copymt()");
188 if (line
[n
-1] == '\n') {
190 if (n
== 1) { /* Blank line. Skip StartNewMsg */
197 if (StartNewMsg
== TRUE
&& ToldUser
== FALSE
) {
199 "%c%s:\tYour mailfile was found to be corrupted\n",
201 fprintf(stderr
, "\t(Content-length mismatch).\n");
202 fprintf(stderr
,"\tMessage #%d may be truncated,\n",
205 "\twith another message concatenated to it.%c\n\n",
214 let
[nlet
].adr
= nextadr
;
215 let
[nlet
].change
= ' ';
216 let
[nlet
].text
= TRUE
;