Deleted Added
full compact
quit.c (40171) quit.c (74769)
1/*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
1/*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
35static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93";
36static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/usr.bin/mail/quit.c 74769 2001-03-25 04:57:05Z mikeh $";
36#endif /* not lint */
37
38#include "rcv.h"
39#include <fcntl.h>
40#include "extern.h"
41
42/*
43 * Rcv -- receive mail rationally.

--- 23 unchanged lines hidden (view full) ---

67 */
68void
69quit()
70{
71 int mcount, p, modify, autohold, anystat, holdbit, nohold;
72 FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf;
73 register struct message *mp;
74 register int c;
40#endif /* not lint */
41
42#include "rcv.h"
43#include <fcntl.h>
44#include "extern.h"
45
46/*
47 * Rcv -- receive mail rationally.

--- 23 unchanged lines hidden (view full) ---

71 */
72void
73quit()
74{
75 int mcount, p, modify, autohold, anystat, holdbit, nohold;
76 FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf;
77 register struct message *mp;
78 register int c;
75 extern char *tempQuit, *tempResid;
79 int fd;
76 struct stat minfo;
80 struct stat minfo;
77 char *mbox;
81 char *mbox, tempname[PATHSIZE];
78
79 /*
80 * If we are read only, we can't do anything,
81 * so just return quickly.
82 */
83 if (readonly)
84 return;
85 /*

--- 17 unchanged lines hidden (view full) ---

103
104 fbuf = Fopen(mailname, "r");
105 if (fbuf == NULL)
106 goto newmail;
107 flock(fileno(fbuf), LOCK_EX);
108 rbuf = NULL;
109 if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
110 printf("New mail has arrived.\n");
82
83 /*
84 * If we are read only, we can't do anything,
85 * so just return quickly.
86 */
87 if (readonly)
88 return;
89 /*

--- 17 unchanged lines hidden (view full) ---

107
108 fbuf = Fopen(mailname, "r");
109 if (fbuf == NULL)
110 goto newmail;
111 flock(fileno(fbuf), LOCK_EX);
112 rbuf = NULL;
113 if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
114 printf("New mail has arrived.\n");
111 rbuf = Fopen(tempResid, "w");
112 if (rbuf == NULL || fbuf == NULL)
115 snprintf(tempname, sizeof(tempname), "%s/mail.RqXXXXXXXXXX", tmpdir);
116 if ((fd = mkstemp(tempname)) == -1 ||
117 (rbuf = Fdopen(fd, "w")) == NULL)
113 goto newmail;
114#ifdef APPEND
115 fseek(fbuf, (long)mailsize, 0);
116 while ((c = getc(fbuf)) != EOF)
117 (void) putc(c, rbuf);
118#else
119 p = minfo.st_size - mailsize;
120 while (p-- > 0) {
121 c = getc(fbuf);
122 if (c == EOF)
123 goto newmail;
124 (void) putc(c, rbuf);
125 }
126#endif
127 Fclose(rbuf);
118 goto newmail;
119#ifdef APPEND
120 fseek(fbuf, (long)mailsize, 0);
121 while ((c = getc(fbuf)) != EOF)
122 (void) putc(c, rbuf);
123#else
124 p = minfo.st_size - mailsize;
125 while (p-- > 0) {
126 c = getc(fbuf);
127 if (c == EOF)
128 goto newmail;
129 (void) putc(c, rbuf);
130 }
131#endif
132 Fclose(rbuf);
128 if ((rbuf = Fopen(tempResid, "r")) == NULL)
133 if ((rbuf = Fopen(tempname, "r")) == NULL)
129 goto newmail;
134 goto newmail;
130 rm(tempResid);
135 rm(tempname);
131 }
132
133 /*
134 * Adjust the message flags in each message.
135 */
136
137 anystat = 0;
138 autohold = value("hold") != NOSTR;

--- 54 unchanged lines hidden (view full) ---

193 * darin. If there is no mbox, copy nothing.
194 * If he has specified "append" don't copy his mailbox,
195 * just copy saveable entries at the end.
196 */
197
198 mbox = expand("&");
199 mcount = c;
200 if (value("append") == NOSTR) {
136 }
137
138 /*
139 * Adjust the message flags in each message.
140 */
141
142 anystat = 0;
143 autohold = value("hold") != NOSTR;

--- 54 unchanged lines hidden (view full) ---

198 * darin. If there is no mbox, copy nothing.
199 * If he has specified "append" don't copy his mailbox,
200 * just copy saveable entries at the end.
201 */
202
203 mbox = expand("&");
204 mcount = c;
205 if (value("append") == NOSTR) {
201 if ((obuf = Fopen(tempQuit, "w")) == NULL) {
202 perror(tempQuit);
206 snprintf(tempname, sizeof(tempname), "%s/mail.RmXXXXXXXXXX", tmpdir);
207 if ((fd = mkstemp(tempname)) == -1 ||
208 (obuf = Fdopen(fd, "w")) == NULL) {
209 warn("%s", tempname);
203 Fclose(fbuf);
204 return;
205 }
210 Fclose(fbuf);
211 return;
212 }
206 if ((ibuf = Fopen(tempQuit, "r")) == NULL) {
207 perror(tempQuit);
208 rm(tempQuit);
213 if ((ibuf = Fopen(tempname, "r")) == NULL) {
214 warn("%s", tempname);
215 rm(tempname);
209 Fclose(obuf);
210 Fclose(fbuf);
211 return;
212 }
216 Fclose(obuf);
217 Fclose(fbuf);
218 return;
219 }
213 rm(tempQuit);
220 rm(tempname);
214 if ((abuf = Fopen(mbox, "r")) != NULL) {
215 while ((c = getc(abuf)) != EOF)
216 (void) putc(c, obuf);
217 Fclose(abuf);
218 }
219 if (ferror(obuf)) {
221 if ((abuf = Fopen(mbox, "r")) != NULL) {
222 while ((c = getc(abuf)) != EOF)
223 (void) putc(c, obuf);
224 Fclose(abuf);
225 }
226 if (ferror(obuf)) {
220 perror(tempQuit);
227 warnx("%s", tempname);
221 Fclose(ibuf);
222 Fclose(obuf);
223 Fclose(fbuf);
224 return;
225 }
226 Fclose(obuf);
228 Fclose(ibuf);
229 Fclose(obuf);
230 Fclose(fbuf);
231 return;
232 }
233 Fclose(obuf);
227 close(creat(mbox, 0600));
234 close(open(mbox, O_CREAT | O_TRUNC | O_WRONLY, 0600));
228 if ((obuf = Fopen(mbox, "r+")) == NULL) {
235 if ((obuf = Fopen(mbox, "r+")) == NULL) {
229 perror(mbox);
236 warn("%s", mbox);
230 Fclose(ibuf);
231 Fclose(fbuf);
232 return;
233 }
234 }
235 if (value("append") != NOSTR) {
236 if ((obuf = Fopen(mbox, "a")) == NULL) {
237 Fclose(ibuf);
238 Fclose(fbuf);
239 return;
240 }
241 }
242 if (value("append") != NOSTR) {
243 if ((obuf = Fopen(mbox, "a")) == NULL) {
237 perror(mbox);
244 warn("%s", mbox);
238 Fclose(fbuf);
239 return;
240 }
241 fchmod(fileno(obuf), 0600);
242 }
243 for (mp = &message[0]; mp < &message[msgCount]; mp++)
244 if (mp->m_flag & MBOX)
245 Fclose(fbuf);
246 return;
247 }
248 fchmod(fileno(obuf), 0600);
249 }
250 for (mp = &message[0]; mp < &message[msgCount]; mp++)
251 if (mp->m_flag & MBOX)
245 if (send(mp, obuf, saveignore, NOSTR) < 0) {
246 perror(mbox);
252 if (sendmessage(mp, obuf, saveignore, NOSTR) < 0) {
253 warnx("%s", mbox);
247 Fclose(ibuf);
248 Fclose(obuf);
249 Fclose(fbuf);
250 return;
251 }
252
253 /*
254 * Copy the user's old mbox contents back

--- 10 unchanged lines hidden (view full) ---

265 break;
266 c = getc(ibuf);
267 }
268 Fclose(ibuf);
269 fflush(obuf);
270 }
271 trunc(obuf);
272 if (ferror(obuf)) {
254 Fclose(ibuf);
255 Fclose(obuf);
256 Fclose(fbuf);
257 return;
258 }
259
260 /*
261 * Copy the user's old mbox contents back

--- 10 unchanged lines hidden (view full) ---

272 break;
273 c = getc(ibuf);
274 }
275 Fclose(ibuf);
276 fflush(obuf);
277 }
278 trunc(obuf);
279 if (ferror(obuf)) {
273 perror(mbox);
280 warn("%s", mbox);
274 Fclose(obuf);
275 Fclose(fbuf);
276 return;
277 }
278 Fclose(obuf);
279 if (mcount == 1)
280 printf("Saved 1 message in mbox\n");
281 else

--- 50 unchanged lines hidden (view full) ---

332 register FILE *res;
333{
334 register struct message *mp;
335 register int p, c;
336 FILE *obuf;
337
338 p = 0;
339 if ((obuf = Fopen(mailname, "r+")) == NULL) {
281 Fclose(obuf);
282 Fclose(fbuf);
283 return;
284 }
285 Fclose(obuf);
286 if (mcount == 1)
287 printf("Saved 1 message in mbox\n");
288 else

--- 50 unchanged lines hidden (view full) ---

339 register FILE *res;
340{
341 register struct message *mp;
342 register int p, c;
343 FILE *obuf;
344
345 p = 0;
346 if ((obuf = Fopen(mailname, "r+")) == NULL) {
340 perror(mailname);
347 warn("%s", mailname);
341 return(-1);
342 }
343#ifndef APPEND
344 if (res != NULL)
345 while ((c = getc(res)) != EOF)
346 (void) putc(c, obuf);
347#endif
348 for (mp = &message[0]; mp < &message[msgCount]; mp++)
349 if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
350 p++;
348 return(-1);
349 }
350#ifndef APPEND
351 if (res != NULL)
352 while ((c = getc(res)) != EOF)
353 (void) putc(c, obuf);
354#endif
355 for (mp = &message[0]; mp < &message[msgCount]; mp++)
356 if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
357 p++;
351 if (send(mp, obuf, (struct ignoretab *)0, NOSTR) < 0) {
352 perror(mailname);
358 if (sendmessage(mp, obuf, (struct ignoretab *)0, NOSTR) < 0) {
359 warnx("%s", mailname);
353 Fclose(obuf);
354 return(-1);
355 }
356 }
357#ifdef APPEND
358 if (res != NULL)
359 while ((c = getc(res)) != EOF)
360 (void) putc(c, obuf);
361#endif
362 fflush(obuf);
363 trunc(obuf);
364 if (ferror(obuf)) {
360 Fclose(obuf);
361 return(-1);
362 }
363 }
364#ifdef APPEND
365 if (res != NULL)
366 while ((c = getc(res)) != EOF)
367 (void) putc(c, obuf);
368#endif
369 fflush(obuf);
370 trunc(obuf);
371 if (ferror(obuf)) {
365 perror(mailname);
372 warn("%s", mailname);
366 Fclose(obuf);
367 return(-1);
368 }
369 if (res != NULL)
370 Fclose(res);
371 Fclose(obuf);
372 alter(mailname);
373 if (p == 1)

--- 5 unchanged lines hidden (view full) ---

379
380/*
381 * Terminate an editing session by attempting to write out the user's
382 * file from the temporary. Save any new stuff appended to the file.
383 */
384void
385edstop()
386{
373 Fclose(obuf);
374 return(-1);
375 }
376 if (res != NULL)
377 Fclose(res);
378 Fclose(obuf);
379 alter(mailname);
380 if (p == 1)

--- 5 unchanged lines hidden (view full) ---

386
387/*
388 * Terminate an editing session by attempting to write out the user's
389 * file from the temporary. Save any new stuff appended to the file.
390 */
391void
392edstop()
393{
387 extern char *tmpdir;
388 register int gotcha, c;
389 register struct message *mp;
390 FILE *obuf, *ibuf, *readstat;
391 struct stat statb;
394 register int gotcha, c;
395 register struct message *mp;
396 FILE *obuf, *ibuf, *readstat;
397 struct stat statb;
392 char tempname[30];
393 char *mktemp();
398 char tempname[PATHSIZE];
394
395 if (readonly)
396 return;
397 holdsigs();
398 if (Tflag != NOSTR) {
399 if ((readstat = Fopen(Tflag, "w")) == NULL)
400 Tflag = NOSTR;
401 }

--- 12 unchanged lines hidden (view full) ---

414 }
415 }
416 if (Tflag != NOSTR)
417 Fclose(readstat);
418 if (!gotcha || Tflag != NOSTR)
419 goto done;
420 ibuf = NULL;
421 if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) {
399
400 if (readonly)
401 return;
402 holdsigs();
403 if (Tflag != NOSTR) {
404 if ((readstat = Fopen(Tflag, "w")) == NULL)
405 Tflag = NOSTR;
406 }

--- 12 unchanged lines hidden (view full) ---

419 }
420 }
421 if (Tflag != NOSTR)
422 Fclose(readstat);
423 if (!gotcha || Tflag != NOSTR)
424 goto done;
425 ibuf = NULL;
426 if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) {
422 strcpy(tempname, tmpdir);
423 strcat(tempname, "mboxXXXXXX");
424 mktemp(tempname);
425 if ((obuf = Fopen(tempname, "w")) == NULL) {
426 perror(tempname);
427 int fd;
428
429 snprintf(tempname, sizeof(tempname), "%s/mbox.XXXXXXXXXX", tmpdir);
430 if ((fd = mkstemp(tempname)) == -1 || (obuf = Fdopen(fd, "w")) == NULL) {
431 warn("%s", tempname);
427 relsesigs();
428 reset(0);
429 }
430 if ((ibuf = Fopen(mailname, "r")) == NULL) {
432 relsesigs();
433 reset(0);
434 }
435 if ((ibuf = Fopen(mailname, "r")) == NULL) {
431 perror(mailname);
436 warn("%s", mailname);
432 Fclose(obuf);
433 rm(tempname);
434 relsesigs();
435 reset(0);
436 }
437 fseek(ibuf, (long)mailsize, 0);
438 while ((c = getc(ibuf)) != EOF)
439 (void) putc(c, obuf);
440 Fclose(ibuf);
441 Fclose(obuf);
442 if ((ibuf = Fopen(tempname, "r")) == NULL) {
437 Fclose(obuf);
438 rm(tempname);
439 relsesigs();
440 reset(0);
441 }
442 fseek(ibuf, (long)mailsize, 0);
443 while ((c = getc(ibuf)) != EOF)
444 (void) putc(c, obuf);
445 Fclose(ibuf);
446 Fclose(obuf);
447 if ((ibuf = Fopen(tempname, "r")) == NULL) {
443 perror(tempname);
448 warn("%s", tempname);
444 rm(tempname);
445 relsesigs();
446 reset(0);
447 }
448 rm(tempname);
449 }
450 printf("\"%s\" ", mailname);
451 fflush(stdout);
452 if ((obuf = Fopen(mailname, "r+")) == NULL) {
449 rm(tempname);
450 relsesigs();
451 reset(0);
452 }
453 rm(tempname);
454 }
455 printf("\"%s\" ", mailname);
456 fflush(stdout);
457 if ((obuf = Fopen(mailname, "r+")) == NULL) {
453 perror(mailname);
458 warn("%s", mailname);
454 relsesigs();
455 reset(0);
456 }
457 trunc(obuf);
458 c = 0;
459 for (mp = &message[0]; mp < &message[msgCount]; mp++) {
460 if ((mp->m_flag & MDELETED) != 0)
461 continue;
462 c++;
459 relsesigs();
460 reset(0);
461 }
462 trunc(obuf);
463 c = 0;
464 for (mp = &message[0]; mp < &message[msgCount]; mp++) {
465 if ((mp->m_flag & MDELETED) != 0)
466 continue;
467 c++;
463 if (send(mp, obuf, (struct ignoretab *) NULL, NOSTR) < 0) {
464 perror(mailname);
468 if (sendmessage(mp, obuf, (struct ignoretab *) NULL, NOSTR) < 0) {
469 warnx("%s", mailname);
465 relsesigs();
466 reset(0);
467 }
468 }
469 gotcha = (c == 0 && ibuf == NULL);
470 if (ibuf != NULL) {
471 while ((c = getc(ibuf)) != EOF)
472 (void) putc(c, obuf);
473 Fclose(ibuf);
474 }
475 fflush(obuf);
476 if (ferror(obuf)) {
470 relsesigs();
471 reset(0);
472 }
473 }
474 gotcha = (c == 0 && ibuf == NULL);
475 if (ibuf != NULL) {
476 while ((c = getc(ibuf)) != EOF)
477 (void) putc(c, obuf);
478 Fclose(ibuf);
479 }
480 fflush(obuf);
481 if (ferror(obuf)) {
477 perror(mailname);
482 warn("%s", mailname);
478 relsesigs();
479 reset(0);
480 }
481 Fclose(obuf);
482 if (gotcha) {
483 rm(mailname);
484 printf("removed\n");
485 } else
486 printf("complete\n");
487 fflush(stdout);
488
489done:
490 relsesigs();
491}
483 relsesigs();
484 reset(0);
485 }
486 Fclose(obuf);
487 if (gotcha) {
488 rm(mailname);
489 printf("removed\n");
490 } else
491 printf("complete\n");
492 fflush(stdout);
493
494done:
495 relsesigs();
496}