-# $OpenBSD: Makefile,v 1.4 1996/12/08 14:32:29 downsj Exp $
+# $OpenBSD: Makefile,v 1.5 1997/03/29 03:01:43 millert Exp $
# $NetBSD: Makefile,v 1.8 1996/06/08 19:48:09 christos Exp $
PROG= mail
-SRCS= version.c aux.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c dotlock.c \
+SRCS= version.c aux.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c \
edit.c fio.c getname.c head.c v7.local.c lex.c list.c main.c names.c \
popen.c quit.c send.c strings.c temp.c tty.c vars.c
SFILES= mail.help mail.tildehelp
-/* $OpenBSD: cmd1.c,v 1.3 1996/06/11 12:53:32 deraadt Exp $ */
+/* $OpenBSD: cmd1.c,v 1.4 1997/03/29 03:01:44 millert Exp $ */
/* $NetBSD: cmd1.c,v 1.5 1996/06/08 19:48:11 christos Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)cmd1.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: cmd1.c,v 1.3 1996/06/11 12:53:32 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: cmd1.c,v 1.4 1997/03/29 03:01:44 millert Exp $";
#endif
#endif /* not lint */
if (mp->m_flag & MBOX)
dispc = 'M';
parse(headline, &hl, pbuf);
- sprintf(wcount, "%3d/%-5ld", mp->m_lines, mp->m_size);
+ sprintf(wcount, "%3d/%-5d", mp->m_lines, mp->m_size);
subjlen = screenwidth - 50 - strlen(wcount);
name = value("show-rcpt") != NOSTR ?
skin(hfield("to", mp)) : nameof(mp, 0);
-/* $OpenBSD: cmd3.c,v 1.2 1996/06/11 12:53:34 deraadt Exp $ */
+/* $OpenBSD: cmd3.c,v 1.3 1997/03/29 03:01:44 millert Exp $ */
/* $NetBSD: cmd3.c,v 1.5 1996/06/08 19:48:14 christos Exp $ */
/*
#if 0
static char sccsid[] = "@(#)cmd3.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: cmd3.c,v 1.2 1996/06/11 12:53:34 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: cmd3.c,v 1.3 1997/03/29 03:01:44 millert Exp $";
#endif
#endif /* not lint */
for (ip = msgvec; *ip != NULL; ip++) {
mesg = *ip;
mp = &message[mesg-1];
- printf("%d: %d/%ld\n", mesg, mp->m_lines, mp->m_size);
+ printf("%d: %d/%d\n", mesg, mp->m_lines, mp->m_size);
}
return(0);
}
-/* $OpenBSD: def.h,v 1.3 1997/02/03 00:25:18 deraadt Exp $ */
+/* $OpenBSD: def.h,v 1.4 1997/03/29 03:01:45 millert Exp $ */
/* $NetBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $ */
/*
* Copyright (c) 1980, 1993
struct message {
short m_flag; /* flags, see below */
- short m_block; /* block number of this message */
- short m_offset; /* offset in block of message */
- long m_size; /* Bytes in the message */
- long m_lines; /* Lines in the message */
+ int m_block; /* block number of this message */
+ int m_offset; /* offset in block of message */
+ int m_size; /* Bytes in the message */
+ int m_lines; /* Lines in the message */
};
/*
-/* $OpenBSD: extern.h,v 1.3 1996/06/11 12:53:39 deraadt Exp $ */
+/* $OpenBSD: extern.h,v 1.4 1997/03/29 03:01:45 millert Exp $ */
/* $NetBSD: extern.h,v 1.4 1996/06/08 19:48:21 christos Exp $ */
/*-
void sigchild __P((int));
void sort __P((char **));
int source __P((void *));
+int spool_lock __P((void));
+int spool_unlock __P((void));
void spreserve __P((void));
void sreset __P((void));
int start_command __P((char *, sigset_t *, int, int, char *, char *, char *));
-/* $OpenBSD: fio.c,v 1.3 1997/01/17 07:12:46 millert Exp $ */
+/* $OpenBSD: fio.c,v 1.4 1997/03/29 03:01:46 millert Exp $ */
/* $NetBSD: fio.c,v 1.5 1996/06/08 19:48:22 christos Exp $ */
/*
#if 0
static char sccsid[] = "@(#)fio.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: fio.c,v 1.3 1997/01/17 07:12:46 millert Exp $";
+static char rcsid[] = "$OpenBSD: fio.c,v 1.4 1997/03/29 03:01:46 millert Exp $";
#endif
#endif /* not lint */
char linebuf[LINESIZE];
/* Get temporary file. */
- (void)sprintf(linebuf, "%s/mail.XXXXXX", tmpdir);
+ (void)sprintf(linebuf, "%s/mail.XXXXXXXXXX", tmpdir);
if ((c = mkstemp(linebuf)) == -1 ||
(mestmp = Fdopen(c, "r+")) == NULL) {
(void)fprintf(stderr, "mail: can't open %s\n", linebuf);
-/* $OpenBSD: pathnames.h,v 1.2 1996/06/11 12:53:46 deraadt Exp $ */
+/* $OpenBSD: pathnames.h,v 1.3 1997/03/29 03:01:46 millert Exp $ */
/* $NetBSD: pathnames.h,v 1.4 1996/06/08 19:48:34 christos Exp $ */
/*
#define _PATH_TILDE "/usr/share/misc/mail.tildehelp"
#define _PATH_MASTER_RC "/etc/mail.rc"
#define _PATH_MORE "/usr/bin/more"
+#define _PATH_MAIL_LOCAL "/usr/libexec/mail.local"
-/* $OpenBSD: popen.c,v 1.3 1996/06/26 21:22:34 dm Exp $ */
+/* $OpenBSD: popen.c,v 1.4 1997/03/29 03:01:47 millert Exp $ */
/* $NetBSD: popen.c,v 1.4 1996/06/08 19:48:35 christos Exp $ */
/*
#if 0
static char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: popen.c,v 1.3 1996/06/26 21:22:34 dm Exp $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.4 1997/03/29 03:01:47 millert Exp $";
#endif
#endif /* not lint */
static struct child *findchild __P((int));
static void delchild __P((struct child *));
static int file_pid __P((FILE *));
+static int handle_spool_locks __P((int));
FILE *
Fopen(file, mode)
cp->free = 1;
sigprocmask(SIG_SETMASK, &oset, NULL);
}
+
+/*
+ * Lock(1)/unlock(0) mail spool using mail.local's -H flag.
+ * Returns 1 for success, 0 for failure, -1 for bad usage.
+ */
+static int
+handle_spool_locks(action)
+ int action;
+{
+ char *cmd;
+ static FILE *lockfp = NULL;
+ static int lock_pid;
+
+ if (action == 0) {
+ /* Clear the lock */
+ if (lockfp == NULL) {
+ fprintf(stderr,
+ "handle_spool_locks: no spool lock to remove.\n");
+ return (-1);
+ }
+ (void)kill(lock_pid, SIGTERM);
+ Pclose(lockfp);
+ lockfp = NULL;
+ } else if (action == 1) {
+ /* Create the lock */
+ if ((cmd = (char *) malloc(sizeof(_PATH_MAIL_LOCAL) + 3)) == NULL)
+ panic("Out of memory");
+ sprintf(cmd, "%s -H", _PATH_MAIL_LOCAL);
+ if ((lockfp = Popen(cmd, "r")) == NULL || getc(lockfp) != '1') {
+ lockfp = NULL;
+ free(cmd);
+ return (0);
+ }
+
+ lock_pid = fp_head->pid; /* new entries added at head */
+ free(cmd);
+ } else {
+ fprintf(stderr, "handle_spool_locks: unknown action %d\n",
+ action);
+ return (-1);
+ }
+
+ return (1);
+}
+
+int
+spool_lock()
+{
+ return(handle_spool_locks(1));
+}
+
+int
+spool_unlock()
+{
+ return(handle_spool_locks(0));
+}
-/* $OpenBSD: quit.c,v 1.2 1996/06/11 12:53:48 deraadt Exp $ */
+/* $OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $ */
/* $NetBSD: quit.c,v 1.5 1996/06/08 19:48:37 christos Exp $ */
/*
#if 0
static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: quit.c,v 1.2 1996/06/11 12:53:48 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $";
#endif
#endif /* not lint */
if (fbuf == NULL)
goto newmail;
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;
+ if (!spool_lock()) {
+ Fclose(fbuf);
+ return; /* mail.local printed error for us */
+ }
rbuf = NULL;
if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
printf("New mail has arrived.\n");
printf("Held %d message%s in %s\n",
p, p == 1 ? "" : "s", mailname);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
if (c == 0) {
if (p != 0) {
writeback(rbuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
goto cream;
if ((obuf = Fopen(tempQuit, "w")) == NULL) {
perror(tempQuit);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
if ((ibuf = Fopen(tempQuit, "r")) == NULL) {
rm(tempQuit);
Fclose(obuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
rm(tempQuit);
Fclose(ibuf);
Fclose(obuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
Fclose(obuf);
perror(mbox);
Fclose(ibuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
}
if ((obuf = Fopen(mbox, "a")) == NULL) {
perror(mbox);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
fchmod(fileno(obuf), 0600);
Fclose(ibuf);
Fclose(obuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
perror(mbox);
Fclose(obuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
Fclose(obuf);
if (p != 0) {
writeback(rbuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
Fclose(abuf);
alter(mailname);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
demail();
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
newmail:
printf("Thou hast new mail.\n");
if (fbuf != NULL) {
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
}
}
register struct message *mp;
FILE *obuf, *ibuf, *readstat = NULL;
struct stat statb;
- char *tempname;
+ char tempname[MAXPATHLEN];
if (readonly)
return;
goto done;
ibuf = NULL;
if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) {
- tempname = tempnam(tmpdir, "mbox");
+ int fd;
- if ((obuf = Fopen(tempname, "w")) == NULL) {
+ snprintf(tempname, sizeof(tempname), "%s/%s", tmpdir,
+ "mboxXXXXXXXXXX");
+ if ((fd = mkstemp(tempname)) == -1 ||
+ (obuf = Fdopen(fd, "w")) == NULL) {
perror(tempname);
relsesigs();
reset(0);
reset(0);
}
rm(tempname);
- free(tempname);
}
printf("\"%s\" ", mailname);
fflush(stdout);
-/* $OpenBSD: temp.c,v 1.4 1996/10/28 00:42:21 millert Exp $ */
+/* $OpenBSD: temp.c,v 1.5 1997/03/29 03:01:47 millert Exp $ */
/* $NetBSD: temp.c,v 1.5 1996/06/08 19:48:42 christos Exp $ */
/*
#if 0
static char sccsid[] = "@(#)temp.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: temp.c,v 1.4 1996/10/28 00:42:21 millert Exp $";
+static char rcsid[] = "$OpenBSD: temp.c,v 1.5 1997/03/29 03:01:47 millert Exp $";
#endif
#endif /* not lint */
{
register char *cp;
- if ((tmpdir = getenv("TMPDIR")) == NULL) {
+ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
tmpdir = _PATH_TMP;
+ if ((tmpdir = strdup(tmpdir)) == NULL)
+ panic("Out of memory");
+
+ /* Strip trailing '/' if necesary */
+ cp = tmpdir + strlen(tmpdir) - 1;
+ while (cp > tmpdir && *cp == '/') {
+ *cp = '\0';
+ cp--;
}
tempMail = tempnam(tmpdir, "Rs");