4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
25 #pragma ident "%Z%%M% %I% %E% SMI"
29 * cksaved - check for an orphaned save file
32 * void cksaved(char *user)
35 * cksaved() looks to see if there is a saved-mail file sitting
36 * around which should be reinstated. These files should be sitting
37 * around only in the case of a crash during rewriting a mail message.
39 * The strategy is simple: if the file exists it is appended to
40 * the end of $MAIL. It is better that a user potentially sees the
41 * mail twice than to lose it.
43 * If $MAIL doesn't exist, then a simple rename() will suffice.
53 char save
[MAXFILENAME
], mail
[MAXFILENAME
];
55 cat(mail
, maildir
, user
);
56 cat(save
, mailsave
, user
);
59 * If no save file, or size is 0, return.
61 if ((stat(save
, &stbuf
) != 0) || (stbuf
.st_size
== 0))
65 * Ok, we have a savefile. If no mailfile exists,
66 * then we want to restore to the mailfile,
67 * else we append to the mailfile.
70 if (stat(mail
, &stbuf
) != 0) {
72 * Restore from the save file by linking
73 * it to $MAIL then unlinking save file
77 if (link(save
, mail
) != 0) {
79 perror("Restore failed to link to mailfile");
83 if (unlink(save
) != 0) {
85 perror("Cannot unlink saved file");
89 if (rename(save
, mail
) != 0) {
91 perror("Cannot rename saved file");
96 (void) snprintf(command
, sizeof (command
),
97 "echo \"Your mailfile was just restored by the mail "
98 "program.\nPermissions of your mailfile are set "
99 "to 0660.\"| mail %s", user
);
103 FILE *Istream
, *Ostream
;
104 if ((Ostream
= fopen(mail
, "a")) == NULL
) {
105 (void) fprintf(stderr
,
106 "%s: Cannot open file '%s' for output\n",
111 if ((Istream
= fopen(save
, "r")) == NULL
) {
112 (void) fprintf(stderr
, "%s: Cannot open saved "
113 "file '%s' for reading\n", program
, save
);
118 copystream(Istream
, Ostream
);
122 if (unlink(save
) != 0) {
123 perror("Unlink of save file failed");
127 (void) snprintf(command
, sizeof (command
),
128 "echo \"Your mail save file has just been appended "
129 "to your mail box by the mail program.\" | mail %s", user
);
133 * Try to send mail to the user whose file