version 1.1, 1995/10/18 08:45:39 |
version 1.2, 1996/06/11 12:53:48 |
|
|
|
/* $OpenBSD$ */ |
|
/* $NetBSD: quit.c,v 1.5 1996/06/08 19:48:37 christos Exp $ */ |
|
|
/* |
/* |
* Copyright (c) 1980, 1993 |
* Copyright (c) 1980, 1993 |
* The Regents of the University of California. All rights reserved. |
* The Regents of the University of California. All rights reserved. |
|
|
*/ |
*/ |
|
|
#ifndef lint |
#ifndef lint |
static char sccsid[] = "from: @(#)quit.c 8.1 (Berkeley) 6/6/93"; |
#if 0 |
static char rcsid[] = "$Id$"; |
static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93"; |
|
#else |
|
static char rcsid[] = "$OpenBSD$"; |
|
#endif |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
#include "rcv.h" |
#include "rcv.h" |
|
|
* The "quit" command. |
* The "quit" command. |
*/ |
*/ |
int |
int |
quitcmd() |
quitcmd(v) |
|
void *v; |
{ |
{ |
/* |
/* |
* If we are sourcing, then return 1 so execute() can handle it. |
* If we are sourcing, then return 1 so execute() can handle it. |
|
|
quit() |
quit() |
{ |
{ |
int mcount, p, modify, autohold, anystat, holdbit, nohold; |
int mcount, p, modify, autohold, anystat, holdbit, nohold; |
FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf; |
FILE *ibuf = NULL, *obuf, *fbuf, *rbuf, *readstat = NULL, *abuf; |
register struct message *mp; |
register struct message *mp; |
register int c; |
register int c; |
extern char *tempQuit, *tempResid; |
extern char *tempQuit, *tempResid; |
|
|
fbuf = Fopen(mailname, "r"); |
fbuf = Fopen(mailname, "r"); |
if (fbuf == NULL) |
if (fbuf == NULL) |
goto newmail; |
goto newmail; |
flock(fileno(fbuf), LOCK_EX); |
if (flock(fileno(fbuf), LOCK_EX) == -1) { |
|
nolock: |
|
perror("Unable to lock mailbox"); |
|
Fclose(fbuf); |
|
return; |
|
} |
|
if (dot_lock(mailname, 1, stdout, ".") == -1) |
|
goto nolock; |
rbuf = NULL; |
rbuf = NULL; |
if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { |
if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { |
printf("New mail has arrived.\n"); |
printf("New mail has arrived.\n"); |
|
|
printf("Held %d message%s in %s\n", |
printf("Held %d message%s in %s\n", |
p, p == 1 ? "" : "s", mailname); |
p, p == 1 ? "" : "s", mailname); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
if (c == 0) { |
if (c == 0) { |
if (p != 0) { |
if (p != 0) { |
writeback(rbuf); |
writeback(rbuf); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
goto cream; |
goto cream; |
|
|
if ((obuf = Fopen(tempQuit, "w")) == NULL) { |
if ((obuf = Fopen(tempQuit, "w")) == NULL) { |
perror(tempQuit); |
perror(tempQuit); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
if ((ibuf = Fopen(tempQuit, "r")) == NULL) { |
if ((ibuf = Fopen(tempQuit, "r")) == NULL) { |
|
|
rm(tempQuit); |
rm(tempQuit); |
Fclose(obuf); |
Fclose(obuf); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
rm(tempQuit); |
rm(tempQuit); |
|
|
Fclose(ibuf); |
Fclose(ibuf); |
Fclose(obuf); |
Fclose(obuf); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
Fclose(obuf); |
Fclose(obuf); |
|
|
perror(mbox); |
perror(mbox); |
Fclose(ibuf); |
Fclose(ibuf); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
} |
} |
if (value("append") != NOSTR) { |
else { |
if ((obuf = Fopen(mbox, "a")) == NULL) { |
if ((obuf = Fopen(mbox, "a")) == NULL) { |
perror(mbox); |
perror(mbox); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
fchmod(fileno(obuf), 0600); |
fchmod(fileno(obuf), 0600); |
|
|
Fclose(ibuf); |
Fclose(ibuf); |
Fclose(obuf); |
Fclose(obuf); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
|
|
|
|
perror(mbox); |
perror(mbox); |
Fclose(obuf); |
Fclose(obuf); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
Fclose(obuf); |
Fclose(obuf); |
|
|
if (p != 0) { |
if (p != 0) { |
writeback(rbuf); |
writeback(rbuf); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
|
|
|
|
Fclose(abuf); |
Fclose(abuf); |
alter(mailname); |
alter(mailname); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
} |
} |
demail(); |
demail(); |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
return; |
return; |
|
|
newmail: |
newmail: |
printf("Thou hast new mail.\n"); |
printf("Thou hast new mail.\n"); |
if (fbuf != NULL) |
if (fbuf != NULL) { |
Fclose(fbuf); |
Fclose(fbuf); |
|
dot_unlock(mailname); |
|
} |
} |
} |
|
|
/* |
/* |
|
|
extern char *tmpdir; |
extern char *tmpdir; |
register int gotcha, c; |
register int gotcha, c; |
register struct message *mp; |
register struct message *mp; |
FILE *obuf, *ibuf, *readstat; |
FILE *obuf, *ibuf, *readstat = NULL; |
struct stat statb; |
struct stat statb; |
char *tempname; |
char *tempname; |
|
|