* Still more user commands.
*/
-static char *SccsId = "@(#)cmd3.c 1.5 %G%";
+static char *SccsId = "@(#)cmd3.c 2.11 %G%";
/*
* Process a shell escape by saving signals, ignoring signals,
if ((Shell = value("SHELL")) == NOSTR)
Shell = SHELL;
for (t = 2; t < 4; t++)
- sig[t-2] = signal(t, SIG_IGN);
+ sig[t-2] = sigset(t, SIG_IGN);
t = vfork();
if (t == 0) {
+ sigchild();
for (t = 2; t < 4; t++)
if (sig[t-2] != SIG_IGN)
- signal(t, SIG_DFL);
+ sigsys(t, SIG_DFL);
execl(Shell, Shell, "-c", cmd, 0);
perror(Shell);
_exit(1);
if (t == -1)
perror("fork");
for (t = 2; t < 4; t++)
- signal(t, sig[t-2]);
+ sigset(t, sig[t-2]);
printf("!\n");
return(0);
}
if ((Shell = value("SHELL")) == NOSTR)
Shell = SHELL;
for (t = 2; t < 4; t++)
- sig[t-2] = signal(t, SIG_IGN);
+ sig[t-2] = sigset(t, SIG_IGN);
t = vfork();
if (t == 0) {
+ sigchild();
for (t = 2; t < 4; t++)
if (sig[t-2] != SIG_IGN)
- signal(t, SIG_DFL);
+ sigsys(t, SIG_DFL);
execl(Shell, Shell, 0);
perror(Shell);
_exit(1);
if (t == -1)
perror("fork");
for (t = 2; t < 4; t++)
- signal(t, sig[t-2]);
+ sigsys(t, sig[t-2]);
putchar('\n');
return(0);
}
register FILE *f;
if ((f = fopen(HELPFILE, "r")) == NULL) {
- printf("No help just now.\n");
+ perror(HELPFILE);
return(1);
}
while ((c = getc(f)) != EOF)
int *msgvec;
{
struct message *mp;
- char *cp, buf[2 * LINESIZE], *rcv;
+ char *cp, *cp2, *cp3, *rcv, *replyto;
+ char buf[2 * LINESIZE], **ap;
struct name *np;
struct header head;
- char *netmap();
if (msgvec[1] != 0) {
printf("Sorry, can't reply to multiple messages at once\n");
}
mp = &message[msgvec[0] - 1];
dot = mp;
- rcv = nameof(mp);
+ rcv = nameof(mp, 1);
+ replyto = skin(hfield("reply-to", mp));
strcpy(buf, "");
- cp = hfield("to", mp);
- if (cp != NOSTR)
- strcpy(buf, cp);
+ if (replyto != NOSTR)
+ strcpy(buf, replyto);
+ else {
+ cp = hfield("to", mp);
+ if (cp != NOSTR)
+ strcpy(buf, cp);
+ }
np = elide(extract(buf, GTO));
/* rcv = rename(rcv); */
mapf(np, rcv);
- np = delname(np, myname);
+ /*
+ * Delete my name from the reply list,
+ * and with it, all my alternate names.
+ */
+ np = delname(np, myname, icequal);
+ if (altnames)
+ for (ap = altnames; *ap; ap++)
+ np = delname(np, *ap, icequal);
head.h_seq = 1;
cp = detract(np, 0);
- if (cp != NOSTR) {
+ if (cp != NOSTR && replyto == NOSTR) {
strcpy(buf, cp);
strcat(buf, " ");
strcat(buf, rcv);
}
- else
- strcpy(buf, rcv);
+ else {
+ if (cp == NOSTR && replyto != NOSTR)
+ printf("Empty reply-to field -- replying to author\n");
+ if (cp == NOSTR)
+ strcpy(buf, rcv);
+ else
+ strcpy(buf, cp);
+ }
head.h_to = buf;
head.h_subject = hfield("subject", mp);
if (head.h_subject == NOSTR)
head.h_subject = hfield("subj", mp);
+ head.h_subject = reedit(head.h_subject);
head.h_cc = NOSTR;
- cp = hfield("cc", mp);
- if (cp != NOSTR) {
- np = elide(extract(cp, GCC));
- mapf(np, rcv);
- np = delname(np, myname);
- head.h_cc = detract(np, 0);
+ if (replyto == NOSTR) {
+ cp = hfield("cc", mp);
+ if (cp != NOSTR) {
+ np = elide(extract(cp, GCC));
+ mapf(np, rcv);
+ np = delname(np, myname, icequal);
+ if (altnames != 0)
+ for (ap = altnames; *ap; ap++)
+ np = delname(np, *ap, icequal);
+ head.h_cc = detract(np, 0);
+ }
}
head.h_bcc = NOSTR;
mail1(&head);
return(0);
}
+/*
+ * Modify the subject we are replying to to begin with Re: if
+ * it does not already.
+ */
+
+char *
+reedit(subj)
+ char *subj;
+{
+ char sbuf[10];
+ register char *newsubj;
+
+ if (subj == NOSTR)
+ return(NOSTR);
+ strncpy(sbuf, subj, 3);
+ sbuf[3] = 0;
+ if (icequal(sbuf, "re:"))
+ return(subj);
+ newsubj = salloc(strlen(subj) + 6);
+ sprintf(newsubj, "Re: %s", subj);
+ return(newsubj);
+}
+
/*
* Preserve the named messages, so that they will be sent
* back to the system mailbox.
mesg = *ip;
mp = &message[mesg-1];
mp->m_flag |= MPRESERVE;
+ mp->m_flag &= ~MBOX;
dot = mp;
}
return(0);
for (ip = msgvec; *ip != NULL; ip++) {
mesg = *ip;
mp = &message[mesg-1];
- printf("%d: %d\n", mesg, msize(mp));
+ printf("%d: %ld\n", mesg, mp->m_size);
}
return(0);
}
{
if (sourcing)
return(1);
+ if (Tflag != NOSTR)
+ close(creat(Tflag, 0600));
exit(e);
}
{
register char *cp;
char fname[BUFSIZ];
+ int edit;
if (argv[0] == NOSTR) {
- if (edit)
- printf("Reading \"%s\"", editfile);
- else
- printf("Reading %s's mail",
- rindex(mailname, '/') + 1);
- printf("; %d message(s)\n", msgCount);
+ newfileinfo();
return(0);
}
* string -- reads the given file
*/
- cp = getfilename(argv[0]);
+ cp = getfilename(argv[0], &edit);
if (cp == NOSTR)
return(-1);
- return(setfile(cp, 1));
+ if (setfile(cp, edit)) {
+ perror(cp);
+ return(-1);
+ }
+ newfileinfo();
}
/*
char prevfile[PATHSIZE];
char *
-getfilename(name)
+getfilename(name, aedit)
char *name;
+ int *aedit;
{
register char *cp;
char savename[BUFSIZ];
+ char oldmailname[BUFSIZ];
+ /*
+ * Assume we will be in "edit file" mode, until
+ * proven wrong.
+ */
+ *aedit = 1;
switch (*name) {
case '%':
+ *aedit = 0;
strcpy(prevfile, mailname);
if (name[1] != 0) {
strcpy(savename, myname);
+ strcpy(oldmailname, mailname);
strncpy(myname, name+1, PATHSIZE-1);
myname[PATHSIZE-1] = 0;
findmail();
- cp = mailname;
+ cp = savestr(mailname);
strcpy(myname, savename);
+ strcpy(mailname, oldmailname);
return(cp);
}
+ strcpy(oldmailname, mailname);
findmail();
- return(mailname);
+ cp = savestr(mailname);
+ strcpy(mailname, oldmailname);
+ return(cp);
case '#':
if (name[1] != 0)
printf("No previous file\n");
return(NOSTR);
}
- strcpy(savename, prevfile);
+ cp = savestr(prevfile);
strcpy(prevfile, mailname);
- strcpy(mailname, savename);
- return(mailname);
+ return(cp);
case '&':
strcpy(prevfile, mailname);
for (ap = argv; *ap != NOSTR; ap++) {
cp = *ap;
if ((cp = expand(cp)) != NOSTR)
- printf("%s\n", cp);
+ printf("%s ", cp);
}
return(0);
}
for (s = 0, ap = msgvec; *ap != 0; ap++) {
mp = &message[*ap - 1];
dot = mp;
- s += strlen(nameof(mp)) + 1;
+ s += strlen(nameof(mp, 2)) + 1;
}
if (s == 0)
return(0);
head.h_to = cp;
for (ap = msgvec; *ap != 0; ap++) {
mp = &message[*ap - 1];
- cp = copy(nameof(mp), cp);
+ cp = copy(nameof(mp, 2), cp);
*cp++ = ' ';
}
*--cp = 0;
head.h_seq = 0;
if (subject == NOSTR)
subject = hfield("subj", mp);
- head.h_subject = subject;
+ head.h_subject = reedit(subject);
if (subject != NOSTR)
head.h_seq++;
head.h_cc = NOSTR;
cond = CANY;
return(0);
}
+
+/*
+ * Set the list of alternate names.
+ */
+alternates(namelist)
+ char **namelist;
+{
+ register int c;
+ register char **ap, **ap2, *cp;
+
+ c = argcount(namelist) + 1;
+ if (c == 1) {
+ if (altnames == 0)
+ return(0);
+ for (ap = altnames; *ap; ap++)
+ printf("%s ", *ap);
+ printf("\n");
+ return(0);
+ }
+ if (altnames != 0)
+ cfree((char *) altnames);
+ altnames = (char **) calloc(c, sizeof (char *));
+ for (ap = namelist, ap2 = altnames; *ap; ap++, ap2++) {
+ cp = (char *) calloc(strlen(*ap) + 1, sizeof (char));
+ strcpy(cp, *ap);
+ *ap2 = cp;
+ }
+ *ap2 = 0;
+ return(0);
+}