Index: head/usr.bin/mail/cmd1.c =================================================================== --- head/usr.bin/mail/cmd1.c (revision 302902) +++ head/usr.bin/mail/cmd1.c (revision 302903) @@ -1,466 +1,475 @@ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)cmd1.c 8.2 (Berkeley) 4/20/95"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include "rcv.h" #include "extern.h" /* * Mail -- a mail program * * User commands. */ -extern const struct cmd cmdtab[]; - /* * Print the current active headings. * Don't change dot if invoker didn't give an argument. */ static int screen; int -headers(int *msgvec) +headers(void *v) { + int *msgvec = v; int n, mesg, flag, size; struct message *mp; size = screensize(); n = msgvec[0]; if (n != 0) screen = (n-1)/size; if (screen < 0) screen = 0; mp = &message[screen * size]; if (mp >= &message[msgCount]) mp = &message[msgCount - size]; if (mp < &message[0]) mp = &message[0]; flag = 0; mesg = mp - &message[0]; if (dot != &message[n-1]) dot = mp; for (; mp < &message[msgCount]; mp++) { mesg++; if (mp->m_flag & MDELETED) continue; if (flag++ >= size) break; printhead(mesg); } if (flag == 0) { printf("No more mail.\n"); return (1); } return (0); } /* * Scroll to the next/previous screen */ int -scroll(char arg[]) +scroll(void *v) { + char *arg = v; int s, size; int cur[1]; cur[0] = 0; size = screensize(); s = screen; switch (*arg) { case 0: case '+': s++; if (s * size >= msgCount) { printf("On last screenful of messages\n"); return (0); } screen = s; break; case '-': if (--s < 0) { printf("On first screenful of messages\n"); return (0); } screen = s; break; default: printf("Unrecognized scrolling command \"%s\"\n", arg); return (1); } return (headers(cur)); } /* * Compute screen size. */ int screensize(void) { int s; char *cp; if ((cp = value("screen")) != NULL && (s = atoi(cp)) > 0) return (s); return (screenheight - 4); } /* * Print out the headlines for each message * in the passed message list. */ int -from(int *msgvec) +from(void *v) { + int *msgvec = v; int *ip; for (ip = msgvec; *ip != 0; ip++) printhead(*ip); if (--ip >= msgvec) dot = &message[*ip - 1]; return (0); } /* * Print out the header of a specific message. * This is a slight improvement to the standard one. */ void printhead(int mesg) { struct message *mp; char headline[LINESIZE], wcount[LINESIZE], *subjline, dispc, curind; char pbuf[BUFSIZ]; struct headline hl; int subjlen; char *name; mp = &message[mesg-1]; (void)readline(setinput(mp), headline, LINESIZE); if ((subjline = hfield("subject", mp)) == NULL) subjline = hfield("subj", mp); /* * Bletch! */ curind = dot == mp ? '>' : ' '; dispc = ' '; if (mp->m_flag & MSAVED) dispc = '*'; if (mp->m_flag & MPRESERVE) dispc = 'P'; if ((mp->m_flag & (MREAD|MNEW)) == MNEW) dispc = 'N'; if ((mp->m_flag & (MREAD|MNEW)) == 0) dispc = 'U'; if (mp->m_flag & MBOX) dispc = 'M'; parse(headline, &hl, pbuf); sprintf(wcount, "%3ld/%-5ld", mp->m_lines, mp->m_size); subjlen = screenwidth - 50 - strlen(wcount); name = value("show-rcpt") != NULL ? skin(hfield("to", mp)) : nameof(mp, 0); if (subjline == NULL || subjlen < 0) /* pretty pathetic */ printf("%c%c%3d %-20.20s %16.16s %s\n", curind, dispc, mesg, name, hl.l_date, wcount); else printf("%c%c%3d %-20.20s %16.16s %s \"%.*s\"\n", curind, dispc, mesg, name, hl.l_date, wcount, subjlen, subjline); } /* * Print out the value of dot. */ int pdot(void) { printf("%td\n", dot - &message[0] + 1); return (0); } /* * Print out all the possible commands. */ int pcmdlist(void) { + extern const struct cmd cmdtab[]; const struct cmd *cp; int cc; printf("Commands are:\n"); for (cc = 0, cp = cmdtab; cp->c_name != NULL; cp++) { cc += strlen(cp->c_name) + 2; if (cc > 72) { printf("\n"); cc = strlen(cp->c_name) + 2; } if ((cp+1)->c_name != NULL) printf("%s, ", cp->c_name); else printf("%s\n", cp->c_name); } return (0); } /* * Paginate messages, honor ignored fields. */ int -more(int *msgvec) +more(void *v) { + int *msgvec = v; return (type1(msgvec, 1, 1)); } /* * Paginate messages, even printing ignored fields. */ int -More(int *msgvec) +More(void *v) { + int *msgvec = v; return (type1(msgvec, 0, 1)); } /* * Type out messages, honor ignored fields. */ int -type(int *msgvec) +type(void *v) { + int *msgvec = v; return (type1(msgvec, 1, 0)); } /* * Type out messages, even printing ignored fields. */ int -Type(int *msgvec) +Type(void *v) { + int *msgvec = v; return (type1(msgvec, 0, 0)); } /* * Type out the messages requested. */ static jmp_buf pipestop; int type1(int *msgvec, int doign, int page) { int nlines, *ip; struct message *mp; char *cp; FILE *obuf; obuf = stdout; if (setjmp(pipestop)) goto close_pipe; if (value("interactive") != NULL && (page || (cp = value("crt")) != NULL)) { nlines = 0; if (!page) { for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) nlines += message[*ip - 1].m_lines; } if (page || nlines > (*cp ? atoi(cp) : realscreenheight)) { cp = value("PAGER"); if (cp == NULL || *cp == '\0') cp = _PATH_MORE; obuf = Popen(cp, "w"); if (obuf == NULL) { warnx("%s", cp); obuf = stdout; } else (void)signal(SIGPIPE, brokpipe); } } /* * Send messages to the output. * */ for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) { mp = &message[*ip - 1]; touch(mp); dot = mp; if (value("quiet") == NULL) fprintf(obuf, "Message %d:\n", *ip); (void)sendmessage(mp, obuf, doign ? ignore : 0, NULL); } close_pipe: if (obuf != stdout) { /* * Ignore SIGPIPE so it can't cause a duplicate close. */ (void)signal(SIGPIPE, SIG_IGN); (void)Pclose(obuf); (void)signal(SIGPIPE, SIG_DFL); } return (0); } /* * Respond to a broken pipe signal -- * probably caused by quitting more. */ /*ARGSUSED*/ void brokpipe(int signo __unused) { longjmp(pipestop, 1); } /* * Print the top so many lines of each desired message. * The number of lines is taken from the variable "toplines" * and defaults to 5. */ int -top(int *msgvec) +top(void *v) { + int *msgvec = v; int *ip; struct message *mp; int c, topl, lines, lineb; char *valtop, linebuf[LINESIZE]; FILE *ibuf; topl = 5; valtop = value("toplines"); if (valtop != NULL) { topl = atoi(valtop); if (topl < 0 || topl > 10000) topl = 5; } lineb = 1; for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { mp = &message[*ip - 1]; touch(mp); dot = mp; if (value("quiet") == NULL) printf("Message %d:\n", *ip); ibuf = setinput(mp); c = mp->m_lines; if (!lineb) printf("\n"); for (lines = 0; lines < c && lines <= topl; lines++) { if (readline(ibuf, linebuf, sizeof(linebuf)) < 0) break; puts(linebuf); lineb = strspn(linebuf, " \t") == strlen(linebuf); } } return (0); } /* * Touch all the given messages so that they will * get mboxed. */ int -stouch(int msgvec[]) +stouch(void *v) { + int *msgvec = v; int *ip; for (ip = msgvec; *ip != 0; ip++) { dot = &message[*ip-1]; dot->m_flag |= MTOUCH; dot->m_flag &= ~MPRESERVE; } return (0); } /* * Make sure all passed messages get mboxed. */ int -mboxit(int msgvec[]) +mboxit(void *v) { + int *msgvec = v; int *ip; for (ip = msgvec; *ip != 0; ip++) { dot = &message[*ip-1]; dot->m_flag |= MTOUCH|MBOX; dot->m_flag &= ~MPRESERVE; } return (0); } /* * List the folders the user currently has. */ int folders(void) { char dirname[PATHSIZE]; char *cmd; if (getfold(dirname, sizeof(dirname)) < 0) { printf("No value set for \"folder\"\n"); return (1); } if ((cmd = value("LISTER")) == NULL) cmd = "ls"; (void)run_command(cmd, 0, -1, -1, dirname, NULL); return (0); } /* * Update the mail file with any new messages that have * come in since we started reading mail. */ int inc(void *v __unused) { int nmsg, mdot; nmsg = incfile(); if (nmsg == 0) printf("No new mail.\n"); else if (nmsg > 0) { mdot = newfileinfo(msgCount - nmsg); dot = &message[mdot - 1]; } else printf("\"inc\" command failed...\n"); return (0); } Index: head/usr.bin/mail/cmd2.c =================================================================== --- head/usr.bin/mail/cmd2.c (revision 302902) +++ head/usr.bin/mail/cmd2.c (revision 302903) @@ -1,506 +1,515 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include "rcv.h" #include #include "extern.h" /* * Mail -- a mail program * * More user commands. */ extern int wait_status; /* * If any arguments were given, go to the next applicable argument * following dot, otherwise, go to the next applicable message. * If given as first command with no arguments, print first message. */ int -next(int *msgvec) +next(void *v) { struct message *mp; + int *msgvec = v; int *ip, *ip2, list[2], mdot; if (*msgvec != 0) { /* * If some messages were supplied, find the * first applicable one following dot using * wrap around. */ mdot = dot - &message[0] + 1; /* * Find the first message in the supplied * message list which follows dot. */ for (ip = msgvec; *ip != 0; ip++) if (*ip > mdot) break; if (*ip == 0) ip = msgvec; ip2 = ip; do { mp = &message[*ip2 - 1]; if ((mp->m_flag & MDELETED) == 0) { dot = mp; goto hitit; } if (*ip2 != 0) ip2++; if (*ip2 == 0) ip2 = msgvec; } while (ip2 != ip); printf("No messages applicable\n"); return (1); } /* * If this is the first command, select message 1. * Note that this must exist for us to get here at all. */ if (!sawcom) goto hitit; /* * Just find the next good message after dot, no * wraparound. */ for (mp = dot+1; mp < &message[msgCount]; mp++) if ((mp->m_flag & (MDELETED|MSAVED)) == 0) break; if (mp >= &message[msgCount]) { printf("At EOF\n"); return (0); } dot = mp; hitit: /* * Print dot. */ list[0] = dot - &message[0] + 1; list[1] = 0; return (type(list)); } /* * Save a message in a file. Mark the message as saved * so we can discard when the user quits. */ int save(void *v) { char *str = v; return (save1(str, 1, "save", saveignore)); } /* * Copy a message to a file without affected its saved-ness */ int copycmd(void *v) { char *str = v; return (save1(str, 0, "copy", saveignore)); } /* * Save/copy the indicated messages at the end of the passed file name. * If mark is true, mark the message "saved." */ int save1(char str[], int mark, const char *cmd, struct ignoretab *ignore) { struct message *mp; char *file; const char *disp; int f, *msgvec, *ip; FILE *obuf; msgvec = (int *)salloc((msgCount + 2) * sizeof(*msgvec)); if ((file = snarf(str, &f)) == NULL) return (1); if (!f) { *msgvec = first(0, MMNORM); if (*msgvec == 0) { printf("No messages to %s.\n", cmd); return (1); } msgvec[1] = 0; } if (f && getmsglist(str, msgvec, 0) < 0) return (1); if ((file = expand(file)) == NULL) return (1); printf("\"%s\" ", file); (void)fflush(stdout); if (access(file, 0) >= 0) disp = "[Appended]"; else disp = "[New file]"; if ((obuf = Fopen(file, "a")) == NULL) { warn((char *)NULL); return (1); } for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { mp = &message[*ip - 1]; touch(mp); if (sendmessage(mp, obuf, ignore, NULL) < 0) { warnx("%s", file); (void)Fclose(obuf); return (1); } if (mark) mp->m_flag |= MSAVED; } (void)fflush(obuf); if (ferror(obuf)) warn("%s", file); (void)Fclose(obuf); printf("%s\n", disp); return (0); } /* * Write the indicated messages at the end of the passed * file name, minus header and trailing blank line. */ int -swrite(char str[]) +swrite(void *v) { + char *str = v; return (save1(str, 1, "write", ignoreall)); } /* * Snarf the file from the end of the command line and * return a pointer to it. If there is no file attached, * just return NULL. Put a null in front of the file * name so that the message list processing won't see it, * unless the file name is the only thing on the line, in * which case, return 0 in the reference flag variable. */ char * -snarf(char linebuf[], int *flag) +snarf(char *linebuf, int *flag) { char *cp; *flag = 1; cp = strlen(linebuf) + linebuf - 1; /* * Strip away trailing blanks. */ while (cp > linebuf && isspace((unsigned char)*cp)) cp--; *++cp = '\0'; /* * Now search for the beginning of the file name. */ while (cp > linebuf && !isspace((unsigned char)*cp)) cp--; if (*cp == '\0') { printf("No file specified.\n"); return (NULL); } if (isspace((unsigned char)*cp)) *cp++ = '\0'; else *flag = 0; return (cp); } /* * Delete messages. */ int -delete(int msgvec[]) +deletecmd(void *v) { + int *msgvec = v; delm(msgvec); return (0); } /* * Delete messages, then type the new dot. */ int -deltype(int msgvec[]) +deltype(void *v) { + int *msgvec = v; int list[2]; int lastdot; lastdot = dot - &message[0] + 1; if (delm(msgvec) >= 0) { list[0] = dot - &message[0] + 1; if (list[0] > lastdot) { touch(dot); list[1] = 0; return (type(list)); } printf("At EOF\n"); } else printf("No more messages\n"); return (0); } /* * Delete the indicated messages. * Set dot to some nice place afterwards. * Internal interface. */ int delm(int *msgvec) { struct message *mp; int *ip, last; last = 0; for (ip = msgvec; *ip != 0; ip++) { mp = &message[*ip - 1]; touch(mp); mp->m_flag |= MDELETED|MTOUCH; mp->m_flag &= ~(MPRESERVE|MSAVED|MBOX); last = *ip; } if (last != 0) { dot = &message[last-1]; last = first(0, MDELETED); if (last != 0) { dot = &message[last-1]; return (0); } else { dot = &message[0]; return (-1); } } /* * Following can't happen -- it keeps lint happy */ return (-1); } /* * Undelete the indicated messages. */ int -undelete_messages(int *msgvec) +undeletecmd(void *v) { - struct message *mp; + int *msgvec = v; int *ip; + struct message *mp; for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { mp = &message[*ip - 1]; touch(mp); dot = mp; mp->m_flag &= ~MDELETED; } return (0); } /* * Interactively dump core on "core" */ int core(void) { int pid; switch (pid = fork()) { case -1: warn("fork"); return (1); case 0: abort(); _exit(1); } printf("Okie dokie"); (void)fflush(stdout); wait_child(pid); if (WIFSIGNALED(wait_status) && WCOREDUMP(wait_status)) printf(" -- Core dumped.\n"); else printf(" -- Can't dump core.\n"); return (0); } /* * Clobber as many bytes of stack as the user requests. */ int clobber(char **argv) { int times; if (argv[0] == 0) times = 1; else times = (atoi(argv[0]) + 511) / 512; clob1(times); return (0); } /* * Clobber the stack. */ void clob1(int n) { char buf[512]; char *cp; if (n <= 0) return; for (cp = buf; cp < &buf[512]; *cp++ = 0xFF) ; clob1(n - 1); } /* * Add the given header fields to the retained list. * If no arguments, print the current list of retained fields. */ int -retfield(char *list[]) +retfield(void *v) { + char **list = v; return (ignore1(list, ignore + 1, "retained")); } /* * Add the given header fields to the ignored list. * If no arguments, print the current list of ignored fields. */ int -igfield(char *list[]) +igfield(void *v) { + char **list = v; return (ignore1(list, ignore, "ignored")); } int -saveretfield(char *list[]) +saveretfield(void *v) { + char **list = v; return (ignore1(list, saveignore + 1, "retained")); } int -saveigfield(char *list[]) +saveigfield(void *v) { + char **list = v; return (ignore1(list, saveignore, "ignored")); } int -ignore1(char *list[], struct ignoretab *tab, const char *which) +ignore1(char **list, struct ignoretab *tab, const char *which) { char field[LINESIZE]; - int h; - struct ignore *igp; char **ap; + struct ignore *igp; + int h; if (*list == NULL) return (igshow(tab, which)); for (ap = list; *ap != 0; ap++) { istrncpy(field, *ap, sizeof(field)); if (member(field, tab)) continue; h = hash(field); igp = calloc(1, sizeof(struct ignore)); igp->i_field = calloc((unsigned)strlen(field) + 1, sizeof(char)); strcpy(igp->i_field, field); igp->i_link = tab->i_head[h]; tab->i_head[h] = igp; tab->i_count++; } return (0); } /* * Print out all currently retained fields. */ int igshow(struct ignoretab *tab, const char *which) { int h; struct ignore *igp; char **ap, **ring; if (tab->i_count == 0) { printf("No fields currently being %s.\n", which); return (0); } ring = (char **)salloc((tab->i_count + 1) * sizeof(char *)); ap = ring; for (h = 0; h < HSHSIZE; h++) for (igp = tab->i_head[h]; igp != NULL; igp = igp->i_link) *ap++ = igp->i_field; *ap = 0; qsort(ring, tab->i_count, sizeof(char *), igcomp); for (ap = ring; *ap != 0; ap++) printf("%s\n", *ap); return (0); } /* * Compare two names for sorting ignored field list. */ int igcomp(const void *l, const void *r) { return (strcmp(*(const char **)l, *(const char **)r)); } Index: head/usr.bin/mail/cmd3.c =================================================================== --- head/usr.bin/mail/cmd3.c (revision 302902) +++ head/usr.bin/mail/cmd3.c (revision 302903) @@ -1,716 +1,725 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include "rcv.h" #include "extern.h" /* * Mail -- a mail program * * Still more user commands. */ /* * Process a shell escape by saving signals, ignoring signals, * and forking a sh -c */ int shell(char *str) { sig_t sigint = signal(SIGINT, SIG_IGN); char *sh; char cmd[BUFSIZ]; if (strlcpy(cmd, str, sizeof(cmd)) >= sizeof(cmd)) return (1); if (bangexp(cmd, sizeof(cmd)) < 0) return (1); if ((sh = value("SHELL")) == NULL) sh = _PATH_CSHELL; (void)run_command(sh, 0, -1, -1, "-c", cmd, NULL); (void)signal(SIGINT, sigint); printf("!\n"); return (0); } /* * Fork an interactive shell. */ /*ARGSUSED*/ int dosh(char *str __unused) { sig_t sigint = signal(SIGINT, SIG_IGN); char *sh; if ((sh = value("SHELL")) == NULL) sh = _PATH_CSHELL; (void)run_command(sh, 0, -1, -1, NULL); (void)signal(SIGINT, sigint); printf("\n"); return (0); } /* * Expand the shell escape by expanding unescaped !'s into the * last issued command where possible. */ int bangexp(char *str, size_t strsize) { char bangbuf[BUFSIZ]; static char lastbang[BUFSIZ]; char *cp, *cp2; int n, changed = 0; cp = str; cp2 = bangbuf; n = sizeof(bangbuf); while (*cp != '\0') { if (*cp == '!') { if (n < (int)strlen(lastbang)) { overf: printf("Command buffer overflow\n"); return (-1); } changed++; if (strlcpy(cp2, lastbang, sizeof(bangbuf) - (cp2 - bangbuf)) >= sizeof(bangbuf) - (cp2 - bangbuf)) goto overf; cp2 += strlen(lastbang); n -= strlen(lastbang); cp++; continue; } if (*cp == '\\' && cp[1] == '!') { if (--n <= 1) goto overf; *cp2++ = '!'; cp += 2; changed++; } if (--n <= 1) goto overf; *cp2++ = *cp++; } *cp2 = 0; if (changed) { printf("!%s\n", bangbuf); (void)fflush(stdout); } if (strlcpy(str, bangbuf, strsize) >= strsize) goto overf; if (strlcpy(lastbang, bangbuf, sizeof(lastbang)) >= sizeof(lastbang)) goto overf; return (0); } /* * Print out a nice help message from some file or another. */ int help(void) { int c; FILE *f; if ((f = Fopen(_PATH_HELP, "r")) == NULL) { warn("%s", _PATH_HELP); return (1); } while ((c = getc(f)) != EOF) putchar(c); (void)Fclose(f); return (0); } /* * Change user's working directory. */ int -schdir(char **arglist) +schdir(void *v) { + char **arglist = v; char *cp; if (*arglist == NULL) { if (homedir == NULL) return (1); cp = homedir; } else if ((cp = expand(*arglist)) == NULL) return (1); if (chdir(cp) < 0) { warn("%s", cp); return (1); } return (0); } int -respond(int *msgvec) +respond(void *v) { + int *msgvec = v; + if (value("Replyall") == NULL && value("flipr") == NULL) return (dorespond(msgvec)); else return (doRespond(msgvec)); } /* * Reply to a list of messages. Extract each name from the * message header and send them off to mail1() */ int dorespond(int *msgvec) { struct message *mp; char *cp, *rcv, *replyto; char **ap; struct name *np; struct header head; if (msgvec[1] != 0) { printf("Sorry, can't reply to multiple messages at once\n"); return (1); } mp = &message[msgvec[0] - 1]; touch(mp); dot = mp; if ((rcv = skin(hfield("from", mp))) == NULL) rcv = skin(nameof(mp, 1)); if ((replyto = skin(hfield("reply-to", mp))) != NULL) np = extract(replyto, GTO); else if ((cp = skin(hfield("to", mp))) != NULL) np = extract(cp, GTO); else np = NULL; np = elide(np); /* * Delete my name from the reply list, * and with it, all my alternate names. */ np = delname(np, myname); if (altnames) for (ap = altnames; *ap != NULL; ap++) np = delname(np, *ap); if (np != NULL && replyto == NULL) np = cat(np, extract(rcv, GTO)); else if (np == NULL) { if (replyto != NULL) printf("Empty reply-to field -- replying to author\n"); np = extract(rcv, GTO); } head.h_to = np; if ((head.h_subject = hfield("subject", mp)) == NULL) head.h_subject = hfield("subj", mp); head.h_subject = reedit(head.h_subject); if (replyto == NULL && (cp = skin(hfield("cc", mp))) != NULL) { np = elide(extract(cp, GCC)); np = delname(np, myname); if (altnames != 0) for (ap = altnames; *ap != NULL; ap++) np = delname(np, *ap); head.h_cc = np; } else head.h_cc = NULL; head.h_bcc = NULL; head.h_smopts = NULL; head.h_replyto = value("REPLYTO"); head.h_inreplyto = skin(hfield("message-id", mp)); mail1(&head, 1); return (0); } /* * Modify the subject we are replying to to begin with Re: if * it does not already. */ char * reedit(char *subj) { char *newsubj; if (subj == NULL) return (NULL); if ((subj[0] == 'r' || subj[0] == 'R') && (subj[1] == 'e' || subj[1] == 'E') && subj[2] == ':') return (subj); newsubj = salloc(strlen(subj) + 5); sprintf(newsubj, "Re: %s", subj); return (newsubj); } /* * Preserve the named messages, so that they will be sent * back to the system mailbox. */ int -preserve(int *msgvec) +preserve(void *v) { + int *msgvec = v; int *ip, mesg; struct message *mp; if (edit) { printf("Cannot \"preserve\" in edit mode\n"); return (1); } for (ip = msgvec; *ip != 0; ip++) { mesg = *ip; mp = &message[mesg-1]; mp->m_flag |= MPRESERVE; mp->m_flag &= ~MBOX; dot = mp; } return (0); } /* * Mark all given messages as unread. */ int -unread(int msgvec[]) +unread(void *v) { + int *msgvec = v; int *ip; for (ip = msgvec; *ip != 0; ip++) { dot = &message[*ip-1]; dot->m_flag &= ~(MREAD|MTOUCH); dot->m_flag |= MSTATUS; } return (0); } /* * Print the size of each message. */ int -messize(int *msgvec) +messize(void *v) { + int *msgvec = v; struct message *mp; int *ip, mesg; for (ip = msgvec; *ip != 0; ip++) { mesg = *ip; mp = &message[mesg-1]; printf("%d: %ld/%ld\n", mesg, mp->m_lines, mp->m_size); } return (0); } /* * Quit quickly. If we are sourcing, just pop the input level * by returning an error. */ int -rexit(int e __unused) +rexit(void *v) { if (sourcing) return (1); exit(0); /*NOTREACHED*/ } /* * Set or display a variable value. Syntax is similar to that * of csh. */ int -set(char **arglist) +set(void *v) { + char **arglist = v; struct var *vp; char *cp, *cp2; char varbuf[BUFSIZ], **ap, **p; int errs, h, s; if (*arglist == NULL) { for (h = 0, s = 1; h < HSHSIZE; h++) for (vp = variables[h]; vp != NULL; vp = vp->v_link) s++; ap = (char **)salloc(s * sizeof(*ap)); for (h = 0, p = ap; h < HSHSIZE; h++) for (vp = variables[h]; vp != NULL; vp = vp->v_link) *p++ = vp->v_name; *p = NULL; sort(ap); for (p = ap; *p != NULL; p++) printf("%s\t%s\n", *p, value(*p)); return (0); } errs = 0; for (ap = arglist; *ap != NULL; ap++) { cp = *ap; cp2 = varbuf; while (cp2 < varbuf + sizeof(varbuf) - 1 && *cp != '=' && *cp != '\0') *cp2++ = *cp++; *cp2 = '\0'; if (*cp == '\0') cp = ""; else cp++; if (equal(varbuf, "")) { printf("Non-null variable name required\n"); errs++; continue; } assign(varbuf, cp); } return (errs); } /* * Unset a bunch of variable values. */ int -unset(char **arglist) +unset(void *v) { + char **arglist = v; struct var *vp, *vp2; int errs, h; char **ap; errs = 0; for (ap = arglist; *ap != NULL; ap++) { if ((vp2 = lookup(*ap)) == NULL) { if (getenv(*ap)) unsetenv(*ap); else if (!sourcing) { printf("\"%s\": undefined variable\n", *ap); errs++; } continue; } h = hash(*ap); if (vp2 == variables[h]) { variables[h] = variables[h]->v_link; vfree(vp2->v_name); vfree(vp2->v_value); (void)free(vp2); continue; } for (vp = variables[h]; vp->v_link != vp2; vp = vp->v_link) ; vp->v_link = vp2->v_link; vfree(vp2->v_name); vfree(vp2->v_value); (void)free(vp2); } return (errs); } /* * Put add users to a group. */ int -group(char **argv) +group(void *v) { + char **argv = v; struct grouphead *gh; struct group *gp; char **ap, *gname, **p; int h, s; if (*argv == NULL) { for (h = 0, s = 1; h < HSHSIZE; h++) for (gh = groups[h]; gh != NULL; gh = gh->g_link) s++; ap = (char **)salloc(s * sizeof(*ap)); for (h = 0, p = ap; h < HSHSIZE; h++) for (gh = groups[h]; gh != NULL; gh = gh->g_link) *p++ = gh->g_name; *p = NULL; sort(ap); for (p = ap; *p != NULL; p++) printgroup(*p); return (0); } if (argv[1] == NULL) { printgroup(*argv); return (0); } gname = *argv; h = hash(gname); if ((gh = findgroup(gname)) == NULL) { if ((gh = calloc(1, sizeof(*gh))) == NULL) err(1, "Out of memory"); gh->g_name = vcopy(gname); gh->g_list = NULL; gh->g_link = groups[h]; groups[h] = gh; } /* * Insert names from the command list into the group. * Who cares if there are duplicates? They get tossed * later anyway. */ for (ap = argv+1; *ap != NULL; ap++) { if ((gp = calloc(1, sizeof(*gp))) == NULL) err(1, "Out of memory"); gp->ge_name = vcopy(*ap); gp->ge_link = gh->g_list; gh->g_list = gp; } return (0); } /* * Sort the passed string vecotor into ascending dictionary * order. */ void sort(char **list) { char **ap; for (ap = list; *ap != NULL; ap++) ; if (ap-list < 2) return; qsort(list, ap-list, sizeof(*list), diction); } /* * Do a dictionary order comparison of the arguments from * qsort. */ int diction(const void *a, const void *b) { return (strcmp(*(const char **)a, *(const char **)b)); } /* * The do nothing command for comments. */ /*ARGSUSED*/ int null(int e __unused) { return (0); } /* * Change to another file. With no argument, print information about * the current file. */ int file(char **argv) { if (argv[0] == NULL) { newfileinfo(0); return (0); } if (setfile(*argv) < 0) return (1); announce(); return (0); } /* * Expand file names like echo */ int echo(char **argv) { char **ap, *cp; for (ap = argv; *ap != NULL; ap++) { cp = *ap; if ((cp = expand(cp)) != NULL) { if (ap != argv) printf(" "); printf("%s", cp); } } printf("\n"); return (0); } int Respond(int *msgvec) { if (value("Replyall") == NULL && value("flipr") == NULL) return (doRespond(msgvec)); else return (dorespond(msgvec)); } /* * Reply to a series of messages by simply mailing to the senders * and not messing around with the To: and Cc: lists as in normal * reply. */ int doRespond(int msgvec[]) { struct header head; struct message *mp; int *ap; char *cp, *mid; head.h_to = NULL; for (ap = msgvec; *ap != 0; ap++) { mp = &message[*ap - 1]; touch(mp); dot = mp; if ((cp = skin(hfield("from", mp))) == NULL) cp = skin(nameof(mp, 2)); head.h_to = cat(head.h_to, extract(cp, GTO)); mid = skin(hfield("message-id", mp)); } if (head.h_to == NULL) return (0); mp = &message[msgvec[0] - 1]; if ((head.h_subject = hfield("subject", mp)) == NULL) head.h_subject = hfield("subj", mp); head.h_subject = reedit(head.h_subject); head.h_cc = NULL; head.h_bcc = NULL; head.h_smopts = NULL; head.h_replyto = value("REPLYTO"); head.h_inreplyto = mid; mail1(&head, 1); return (0); } /* * Conditional commands. These allow one to parameterize one's * .mailrc and do some things if sending, others if receiving. */ int ifcmd(char **argv) { char *cp; if (cond != CANY) { printf("Illegal nested \"if\"\n"); return (1); } cond = CANY; cp = argv[0]; switch (*cp) { case 'r': case 'R': cond = CRCV; break; case 's': case 'S': cond = CSEND; break; default: printf("Unrecognized if-keyword: \"%s\"\n", cp); return (1); } return (0); } /* * Implement 'else'. This is pretty simple -- we just * flip over the conditional flag. */ int elsecmd(void) { switch (cond) { case CANY: printf("\"Else\" without matching \"if\"\n"); return (1); case CSEND: cond = CRCV; break; case CRCV: cond = CSEND; break; default: printf("Mail's idea of conditions is screwed up\n"); cond = CANY; break; } return (0); } /* * End of if statement. Just set cond back to anything. */ int endifcmd(void) { if (cond == CANY) { printf("\"Endif\" without matching \"if\"\n"); return (1); } cond = CANY; return (0); } /* * Set the list of alternate names. */ int alternates(char **namelist) { int c; char **ap, **ap2, *cp; c = argcount(namelist) + 1; if (c == 1) { if (altnames == 0) return (0); for (ap = altnames; *ap != NULL; ap++) printf("%s ", *ap); printf("\n"); return (0); } if (altnames != 0) (void)free(altnames); if ((altnames = calloc((unsigned)c, sizeof(char *))) == NULL) err(1, "Out of memory"); for (ap = namelist, ap2 = altnames; *ap != NULL; ap++, ap2++) { cp = calloc((unsigned)strlen(*ap) + 1, sizeof(char)); strcpy(cp, *ap); *ap2 = cp; } *ap2 = 0; return (0); } Index: head/usr.bin/mail/cmdtab.c =================================================================== --- head/usr.bin/mail/cmdtab.c (revision 302902) +++ head/usr.bin/mail/cmdtab.c (revision 302903) @@ -1,121 +1,121 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include "def.h" #include "extern.h" /* * Mail -- a mail program * * Define all of the command names and bindings. */ const struct cmd cmdtab[] = { /* msgmask msgflag */ /* command function argtype result & mask */ /* ------- -------- ------- ------ ------- */ { "next", next, NDMLIST, 0, MMNDEL }, { "alias", group, M|RAWLIST, 0, 1000 }, { "print", type, MSGLIST, 0, MMNDEL }, { "type", type, MSGLIST, 0, MMNDEL }, { "Type", Type, MSGLIST, 0, MMNDEL }, { "Print", Type, MSGLIST, 0, MMNDEL }, { "visual", visual, I|MSGLIST, 0, MMNORM }, { "top", top, MSGLIST, 0, MMNDEL }, { "touch", stouch, W|MSGLIST, 0, MMNDEL }, { "preserve", preserve, W|MSGLIST, 0, MMNDEL }, - { "delete", delete, W|P|MSGLIST, 0, MMNDEL }, + { "delete", deletecmd, W|P|MSGLIST, 0, MMNDEL }, { "dp", deltype, W|MSGLIST, 0, MMNDEL }, { "dt", deltype, W|MSGLIST, 0, MMNDEL }, - { "undelete", undelete_messages, P|MSGLIST, MDELETED,MMNDEL }, + { "undelete", undeletecmd, P|MSGLIST, MDELETED,MMNDEL }, { "unset", unset, M|RAWLIST, 1, 1000 }, { "mail", sendmail, R|M|I|STRLIST, 0, 0 }, { "mbox", mboxit, W|MSGLIST, 0, 0 }, { "more", more, MSGLIST, 0, MMNDEL }, { "page", more, MSGLIST, 0, MMNDEL }, { "More", More, MSGLIST, 0, MMNDEL }, { "Page", More, MSGLIST, 0, MMNDEL }, { "unread", unread, MSGLIST, 0, MMNDEL }, { "!", shell, I|STRLIST, 0, 0 }, { "copy", copycmd, M|STRLIST, 0, 0 }, { "chdir", schdir, M|RAWLIST, 0, 1 }, { "cd", schdir, M|RAWLIST, 0, 1 }, { "save", save, STRLIST, 0, 0 }, { "source", source, M|RAWLIST, 1, 1 }, { "set", set, M|RAWLIST, 0, 1000 }, { "shell", dosh, I|NOLIST, 0, 0 }, { "version", pversion, M|NOLIST, 0, 0 }, { "group", group, M|RAWLIST, 0, 1000 }, { "write", swrite, STRLIST, 0, 0 }, { "from", from, MSGLIST, 0, MMNORM }, { "file", file, T|M|RAWLIST, 0, 1 }, { "folder", file, T|M|RAWLIST, 0, 1 }, { "folders", folders, T|M|NOLIST, 0, 0 }, { "?", help, M|NOLIST, 0, 0 }, { "z", scroll, M|STRLIST, 0, 0 }, { "headers", headers, MSGLIST, 0, MMNDEL }, { "help", help, M|NOLIST, 0, 0 }, { "=", pdot, NOLIST, 0, 0 }, { "Reply", Respond, R|I|MSGLIST, 0, MMNDEL }, { "Respond", Respond, R|I|MSGLIST, 0, MMNDEL }, { "reply", respond, R|I|MSGLIST, 0, MMNDEL }, { "respond", respond, R|I|MSGLIST, 0, MMNDEL }, { "edit", editor, I|MSGLIST, 0, MMNORM }, { "echo", echo, M|RAWLIST, 0, 1000 }, { "quit", quitcmd, NOLIST, 0, 0 }, { "list", pcmdlist, M|NOLIST, 0, 0 }, { "xit", rexit, M|NOLIST, 0, 0 }, { "exit", rexit, M|NOLIST, 0, 0 }, { "size", messize, MSGLIST, 0, MMNDEL }, { "hold", preserve, W|MSGLIST, 0, MMNDEL }, { "if", ifcmd, F|M|RAWLIST, 1, 1 }, { "else", elsecmd, F|M|RAWLIST, 0, 0 }, { "endif", endifcmd, F|M|RAWLIST, 0, 0 }, { "alternates", alternates, M|RAWLIST, 0, 1000 }, { "ignore", igfield, M|RAWLIST, 0, 1000 }, { "discard", igfield, M|RAWLIST, 0, 1000 }, { "retain", retfield, M|RAWLIST, 0, 1000 }, { "saveignore", saveigfield, M|RAWLIST, 0, 1000 }, { "savediscard",saveigfield, M|RAWLIST, 0, 1000 }, { "saveretain", saveretfield, M|RAWLIST, 0, 1000 }, /* { "Header", Header, STRLIST, 0, 1000 }, */ { "core", core, M|NOLIST, 0, 0 }, { "#", null, M|NOLIST, 0, 0 }, { "clobber", clobber, M|RAWLIST, 0, 1 }, { "inc", inc, T|NOLIST, 0, 0 }, { 0, 0, 0, 0, 0 } }; Index: head/usr.bin/mail/extern.h =================================================================== --- head/usr.bin/mail/extern.h (revision 302902) +++ head/usr.bin/mail/extern.h (revision 302903) @@ -1,252 +1,252 @@ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)extern.h 8.2 (Berkeley) 4/20/95 * * $FreeBSD$ */ struct name *cat(struct name *, struct name *); -struct name *delname(struct name *, char []); +struct name *delname(struct name *, char *); struct name *elide(struct name *); -struct name *extract(char [], int); +struct name *extract(char *, int); struct name *gexpand(struct name *, struct grouphead *, int, int); -struct name *nalloc(char [], int); +struct name *nalloc(char *, int); struct name *outof(struct name *, FILE *, struct header *); struct name *put(struct name *, struct name *); struct name *tailof(struct name *); struct name *usermap(struct name *); FILE *Fdopen(int, const char *); FILE *Fopen(const char *, const char *); FILE *Popen(char *, const char *); FILE *collect(struct header *, int); char *copyin(char *, char **); char *detract(struct name *, int); char *expand(char *); char *getdeadletter(void); char *getname(uid_t); char *hfield(const char *, struct message *); FILE *infix(struct header *, FILE *); -char *ishfield(char [], char *, const char *); +char *ishfield(char *, char *, const char *); char *name1(struct message *, int); char *nameof(struct message *, int); char *nextword(char *, char *); -char *readtty(const char *, char []); +char *readtty(const char *, char *); char *reedit(char *); FILE *run_editor(FILE *, off_t, int, int); char *salloc(int); char *savestr(char *); FILE *setinput(struct message *); char *skin(char *); char *skip_comment(char *); -char *snarf(char [], int *); +char *snarf(char *, int *); char *username(void); char *value(const char *); char *vcopy(const char *); -char *yankword(char *, char []); -char *yanklogin(char *, char []); +char *yankword(char *, char *); +char *yanklogin(char *, char *); int Fclose(FILE *); -int More(int *); +int More(void *); int Pclose(FILE *); int Respond(int *); -int Type(int *); -int doRespond(int []); +int Type(void *); +int doRespond(int *); int dorespond(int *); void alter(char *); int alternates(char **); void announce(void); int append(struct message *, FILE *); int argcount(char **); void assign(const char *, const char *); int bangexp(char *, size_t); void brokpipe(int); int charcount(char *, int); int check(int, int); void clob1(int); int clobber(char **); void close_all_files(void); int cmatch(char *, char *); void collhup(int); void collint(int); void collstop(int); void commands(void); int copycmd(void *v); int core(void); int count(struct name *); -int delete(int []); -int delm(int []); -int deltype(int []); +int deletecmd(void *); +int delm(int *); +int deltype(void *); void demail(void); int diction(const void *, const void *); int dosh(char *); int echo(char **); int edit1(int *, int); int editor(int *); void edstop(void); int elsecmd(void); int endifcmd(void); int evalcol(int); -int execute(char [], int); -int exwrite(char [], FILE *, int); +int execute(char *, int); +int exwrite(char *, FILE *, int); void fail(const char *, const char *); int file(char **); struct grouphead * - findgroup(char []); + findgroup(char *); void findmail(char *, char *, int); int first(int, int); void fixhead(struct header *, struct name *); void fmt(const char *, struct name *, FILE *, int); int folders(void); -int forward(char [], FILE *, char *, int); +int forward(char *, FILE *, char *, int); void free_child(int); -int from(int *); +int from(void *); off_t fsize(FILE *); int getfold(char *, int); -int gethfield(FILE *, char [], int, char **); +int gethfield(FILE *, char *, int, char **); int getmsglist(char *, int *, int); -int getrawlist(char [], char **, int); -uid_t getuserid(char []); +int getrawlist(char *, char **, int); +uid_t getuserid(char *); int grabh(struct header *, int); -int group(char **); +int group(void *); void hangup(int); int hash(const char *); void hdrstop(int); -int headers(int *); +int headers(void *); int help(void); void holdsigs(void); int ifcmd(char **); int igcomp(const void *, const void *); -int igfield(char *[]); -int ignore1(char *[], struct ignoretab *, const char *); +int igfield(void *); +int ignore1(char **, struct ignoretab *, const char *); int igshow(struct ignoretab *, const char *); int inc(void *); int incfile(void); void intr(int); -int isdate(char []); -int isdir(char []); +int isdate(char *); +int isdir(char *); int isfileaddr(char *); -int ishead(char []); +int ishead(char *); int isign(const char *, struct ignoretab []); int isprefix(const char *, const char *); void istrncpy(char *, const char *, size_t); const struct cmd * - lex(char []); + lex(char *); void load(char *); struct var * lookup(const char *); int mail(struct name *, struct name *, struct name *, struct name *, char *, char *); void mail1(struct header *, int); void makemessage(FILE *, int); void mark(int); -int markall(char [], int); +int markall(char *, int); int matchsender(char *, int); int matchfield(char *, int); -int mboxit(int []); +int mboxit(void *); int member(char *, struct ignoretab *); void mesedit(FILE *, int); -void mespipe(FILE *, char []); -int messize(int *); +void mespipe(FILE *, char *); +int messize(void *); int metamess(int, int); -int more(int *); +int more(void *); int newfileinfo(int); -int next(int *); +int next(void *); int null(int); -void parse(char [], struct headline *, char []); +void parse(char *, struct headline *, char *); int pcmdlist(void); int pdot(void); void prepare_child(sigset_t *, int, int); -int preserve(int *); +int preserve(void *); void prettyprint(struct name *); -void printgroup(char []); +void printgroup(char *); void printhead(int); int puthead(struct header *, FILE *, int); int putline(FILE *, char *, int); int pversion(int); void quit(void); int quitcmd(void); int readline(FILE *, char *, int); void register_file(FILE *, int, int); void regret(int); void relsesigs(void); -int respond(int *); -int retfield(char *[]); -int rexit(int); +int respond(void *); +int retfield(void *); +int rexit(void *); int rm(char *); int run_command(char *, sigset_t *, int, int, ...); int save(void *v); -int save1(char [], int, const char *, struct ignoretab *); +int save1(char *, int, const char *, struct ignoretab *); void savedeadletter(FILE *); -int saveigfield(char *[]); -int savemail(char [], FILE *); -int saveretfield(char *[]); +int saveigfield(void *); +int savemail(char *, FILE *); +int saveretfield(void *); int scan(char **); void scaninit(void); -int schdir(char **); +int schdir(void *); int screensize(void); -int scroll(char []); +int scroll(void *); int sendmessage(struct message *, FILE *, struct ignoretab *, char *); int sendmail(char *); -int set(char **); +int set(void *); int setfile(char *); void setmsize(int); void setptr(FILE *, off_t); void setscreensize(void); int shell(char *); void sigchild(int); void sort(char **); int source(char **); void spreserve(void); void sreset(void); int start_command(char *, sigset_t *, int, int, ...); void statusput(struct message *, FILE *, char *); void stop(int); -int stouch(int []); -int swrite(char []); +int stouch(void *); +int swrite(void *); void tinit(void); -int top(int *); +int top(void *); void touch(struct message *); void ttyint(int); void ttystop(int); -int type(int *); +int type(void *); int type1(int *, int, int); -int undelete_messages(int *); +int undeletecmd(void *); void unmark(int); char **unpack(struct name *); -int unread(int []); +int unread(void *); void unregister_file(FILE *); -int unset(char **); +int unset(void *); int unstack(void); void vfree(char *); int visual(int *); int wait_child(int); int wait_command(int); int writeback(FILE *); extern char *__progname; extern char *tmpdir; Index: head/usr.bin/mail/names.c =================================================================== --- head/usr.bin/mail/names.c (revision 302902) +++ head/usr.bin/mail/names.c (revision 302903) @@ -1,762 +1,762 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)names.c 8.1 (Berkeley) 6/6/93"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); /* * Mail -- a mail program * * Handle name lists. */ #include "rcv.h" #include #include "extern.h" /* * Allocate a single element of a name list, * initialize its name field to the passed * name and return it. */ struct name * nalloc(char str[], int ntype) { struct name *np; np = (struct name *)salloc(sizeof(*np)); np->n_flink = NULL; np->n_blink = NULL; np->n_type = ntype; np->n_name = savestr(str); return (np); } /* * Find the tail of a list and return it. */ struct name * tailof(struct name *name) { struct name *np; np = name; if (np == NULL) return (NULL); while (np->n_flink != NULL) np = np->n_flink; return (np); } /* * Extract a list of names from a line, * and make a list of names from it. * Return the list or NULL if none found. */ struct name * -extract(char line[], int ntype) +extract(char *line, int ntype) { char *cp, *nbuf; struct name *top, *np, *t; if (line == NULL || *line == '\0') return (NULL); if ((nbuf = malloc(strlen(line) + 1)) == NULL) err(1, "Out of memory"); top = NULL; np = NULL; cp = line; while ((cp = yankword(cp, nbuf)) != NULL) { t = nalloc(nbuf, ntype); if (top == NULL) top = t; else np->n_flink = t; t->n_blink = np; np = t; } (void)free(nbuf); return (top); } /* * Turn a list of names into a string of the same names. */ char * detract(struct name *np, int ntype) { int s, comma; char *cp, *top; struct name *p; comma = ntype & GCOMMA; if (np == NULL) return (NULL); ntype &= ~GCOMMA; s = 0; if (debug && comma) fprintf(stderr, "detract asked to insert commas\n"); for (p = np; p != NULL; p = p->n_flink) { if (ntype && (p->n_type & GMASK) != ntype) continue; s += strlen(p->n_name) + 1; if (comma) s++; } if (s == 0) return (NULL); s += 2; top = salloc(s); cp = top; for (p = np; p != NULL; p = p->n_flink) { if (ntype && (p->n_type & GMASK) != ntype) continue; cp += strlcpy(cp, p->n_name, strlen(p->n_name) + 1); if (comma && p->n_flink != NULL) *cp++ = ','; *cp++ = ' '; } *--cp = '\0'; if (comma && *--cp == ',') *cp = '\0'; return (top); } /* * Grab a single word (liberal word) * Throw away things between ()'s, and take anything between <>. */ char * -yankword(char *ap, char wbuf[]) +yankword(char *ap, char *wbuf) { char *cp, *cp2; cp = ap; for (;;) { if (*cp == '\0') return (NULL); if (*cp == '(') { int nesting = 0; while (*cp != '\0') { switch (*cp++) { case '(': nesting++; break; case ')': --nesting; break; } if (nesting <= 0) break; } } else if (*cp == ' ' || *cp == '\t' || *cp == ',') cp++; else break; } if (*cp == '<') for (cp2 = wbuf; *cp && (*cp2++ = *cp++) != '>';) ; else for (cp2 = wbuf; *cp != '\0' && strchr(" \t,(", *cp) == NULL; *cp2++ = *cp++) ; *cp2 = '\0'; return (cp); } /* * Grab a single login name (liberal word) * Throw away things between ()'s, take anything between <>, * and look for words before metacharacters %, @, !. */ char * -yanklogin(char *ap, char wbuf[]) +yanklogin(char *ap, char *wbuf) { char *cp, *cp2, *cp_temp; int n; cp = ap; for (;;) { if (*cp == '\0') return (NULL); if (*cp == '(') { int nesting = 0; while (*cp != '\0') { switch (*cp++) { case '(': nesting++; break; case ')': --nesting; break; } if (nesting <= 0) break; } } else if (*cp == ' ' || *cp == '\t' || *cp == ',') cp++; else break; } /* * Now, let's go forward till we meet the needed character, * and step one word back. */ /* First, remember current point. */ cp_temp = cp; n = 0; /* * Note that we look ahead in a cycle. This is safe, since * non-end of string is checked first. */ while(*cp != '\0' && strchr("@%!", *(cp + 1)) == NULL) cp++; /* * Now, start stepping back to the first non-word character, * while counting the number of symbols in a word. */ while(cp != cp_temp && strchr(" \t,<>", *(cp - 1)) == NULL) { n++; cp--; } /* Finally, grab the word forward. */ cp2 = wbuf; while(n >= 0) { *cp2++=*cp++; n--; } *cp2 = '\0'; return (cp); } /* * For each recipient in the passed name list with a / * in the name, append the message to the end of the named file * and remove him from the recipient list. * * Recipients whose name begins with | are piped through the given * program and removed. */ struct name * outof(struct name *names, FILE *fo, struct header *hp) { int c, ispipe; struct name *np, *top; time_t now; char *date, *fname; FILE *fout, *fin; top = names; np = names; (void)time(&now); date = ctime(&now); while (np != NULL) { if (!isfileaddr(np->n_name) && np->n_name[0] != '|') { np = np->n_flink; continue; } ispipe = np->n_name[0] == '|'; if (ispipe) fname = np->n_name+1; else fname = expand(np->n_name); /* * See if we have copied the complete message out yet. * If not, do so. */ if (image < 0) { int fd; char tempname[PATHSIZE]; (void)snprintf(tempname, sizeof(tempname), "%s/mail.ReXXXXXXXXXX", tmpdir); if ((fd = mkstemp(tempname)) == -1 || (fout = Fdopen(fd, "a")) == NULL) { warn("%s", tempname); senderr++; goto cant; } image = open(tempname, O_RDWR); (void)rm(tempname); if (image < 0) { warn("%s", tempname); senderr++; (void)Fclose(fout); goto cant; } (void)fcntl(image, F_SETFD, 1); fprintf(fout, "From %s %s", myname, date); puthead(hp, fout, GTO|GSUBJECT|GCC|GREPLYTO|GINREPLYTO|GNL); while ((c = getc(fo)) != EOF) (void)putc(c, fout); rewind(fo); fprintf(fout, "\n"); (void)fflush(fout); if (ferror(fout)) { warn("%s", tempname); senderr++; (void)Fclose(fout); goto cant; } (void)Fclose(fout); } /* * Now either copy "image" to the desired file * or give it as the standard input to the desired * program as appropriate. */ if (ispipe) { int pid; char *sh; sigset_t nset; /* * XXX * We can't really reuse the same image file, * because multiple piped recipients will * share the same lseek location and trample * on one another. */ if ((sh = value("SHELL")) == NULL) sh = _PATH_CSHELL; (void)sigemptyset(&nset); (void)sigaddset(&nset, SIGHUP); (void)sigaddset(&nset, SIGINT); (void)sigaddset(&nset, SIGQUIT); pid = start_command(sh, &nset, image, -1, "-c", fname, NULL); if (pid < 0) { senderr++; goto cant; } free_child(pid); } else { int f; if ((fout = Fopen(fname, "a")) == NULL) { warn("%s", fname); senderr++; goto cant; } if ((f = dup(image)) < 0) { warn("dup"); fin = NULL; } else fin = Fdopen(f, "r"); if (fin == NULL) { fprintf(stderr, "Can't reopen image\n"); (void)Fclose(fout); senderr++; goto cant; } rewind(fin); while ((c = getc(fin)) != EOF) (void)putc(c, fout); if (ferror(fout)) { warnx("%s", fname); senderr++; (void)Fclose(fout); (void)Fclose(fin); goto cant; } (void)Fclose(fout); (void)Fclose(fin); } cant: /* * In days of old we removed the entry from the * the list; now for sake of header expansion * we leave it in and mark it as deleted. */ np->n_type |= GDEL; np = np->n_flink; } if (image >= 0) { (void)close(image); image = -1; } return (top); } /* * Determine if the passed address is a local "send to file" address. * If any of the network metacharacters precedes any slashes, it can't * be a filename. We cheat with .'s to allow path names like ./... */ int isfileaddr(char *name) { char *cp; if (*name == '+') return (1); for (cp = name; *cp != '\0'; cp++) { if (*cp == '!' || *cp == '%' || *cp == '@') return (0); if (*cp == '/') return (1); } return (0); } /* * Map all of the aliased users in the invoker's mailrc * file and insert them into the list. * Changed after all these months of service to recursively * expand names (2/14/80). */ struct name * usermap(struct name *names) { struct name *new, *np, *cp; struct grouphead *gh; int metoo; new = NULL; np = names; metoo = (value("metoo") != NULL); while (np != NULL) { if (np->n_name[0] == '\\') { cp = np->n_flink; new = put(new, np); np = cp; continue; } gh = findgroup(np->n_name); cp = np->n_flink; if (gh != NULL) new = gexpand(new, gh, metoo, np->n_type); else new = put(new, np); np = cp; } return (new); } /* * Recursively expand a group name. We limit the expansion to some * fixed level to keep things from going haywire. * Direct recursion is not expanded for convenience. */ struct name * gexpand(struct name *nlist, struct grouphead *gh, int metoo, int ntype) { struct group *gp; struct grouphead *ngh; struct name *np; static int depth; char *cp; if (depth > MAXEXP) { printf("Expanding alias to depth larger than %d\n", MAXEXP); return (nlist); } depth++; for (gp = gh->g_list; gp != NULL; gp = gp->ge_link) { cp = gp->ge_name; if (*cp == '\\') goto quote; if (strcmp(cp, gh->g_name) == 0) goto quote; if ((ngh = findgroup(cp)) != NULL) { nlist = gexpand(nlist, ngh, metoo, ntype); continue; } quote: np = nalloc(cp, ntype); /* * At this point should allow to expand * to self if only person in group */ if (gp == gh->g_list && gp->ge_link == NULL) goto skip; if (!metoo && strcmp(cp, myname) == 0) np->n_type |= GDEL; skip: nlist = put(nlist, np); } depth--; return (nlist); } /* * Concatenate the two passed name lists, return the result. */ struct name * cat(struct name *n1, struct name *n2) { struct name *tail; if (n1 == NULL) return (n2); if (n2 == NULL) return (n1); tail = tailof(n1); tail->n_flink = n2; n2->n_blink = tail; return (n1); } /* * Unpack the name list onto a vector of strings. * Return an error if the name list won't fit. */ char ** unpack(struct name *np) { char **ap, **top; struct name *n; int t, extra, metoo, verbose; n = np; if ((t = count(n)) == 0) errx(1, "No names to unpack"); /* * Compute the number of extra arguments we will need. * We need at least two extra -- one for "mail" and one for * the terminating 0 pointer. Additional spots may be needed * to pass along -f to the host mailer. */ extra = 2; extra++; metoo = value("metoo") != NULL; if (metoo) extra++; verbose = value("verbose") != NULL; if (verbose) extra++; top = (char **)salloc((t + extra) * sizeof(*top)); ap = top; *ap++ = "send-mail"; *ap++ = "-i"; if (metoo) *ap++ = "-m"; if (verbose) *ap++ = "-v"; for (; n != NULL; n = n->n_flink) if ((n->n_type & GDEL) == 0) *ap++ = n->n_name; *ap = NULL; return (top); } /* * Remove all of the duplicates from the passed name list by * insertion sorting them, then checking for dups. * Return the head of the new list. */ struct name * elide(struct name *names) { struct name *np, *t, *new; struct name *x; if (names == NULL) return (NULL); new = names; np = names; np = np->n_flink; if (np != NULL) np->n_blink = NULL; new->n_flink = NULL; while (np != NULL) { t = new; while (strcasecmp(t->n_name, np->n_name) < 0) { if (t->n_flink == NULL) break; t = t->n_flink; } /* * If we ran out of t's, put the new entry after * the current value of t. */ if (strcasecmp(t->n_name, np->n_name) < 0) { t->n_flink = np; np->n_blink = t; t = np; np = np->n_flink; t->n_flink = NULL; continue; } /* * Otherwise, put the new entry in front of the * current t. If at the front of the list, * the new guy becomes the new head of the list. */ if (t == new) { t = np; np = np->n_flink; t->n_flink = new; new->n_blink = t; t->n_blink = NULL; new = t; continue; } /* * The normal case -- we are inserting into the * middle of the list. */ x = np; np = np->n_flink; x->n_flink = t; x->n_blink = t->n_blink; t->n_blink->n_flink = x; t->n_blink = x; } /* * Now the list headed up by new is sorted. * Go through it and remove duplicates. */ np = new; while (np != NULL) { t = np; while (t->n_flink != NULL && strcasecmp(np->n_name, t->n_flink->n_name) == 0) t = t->n_flink; if (t == np || t == NULL) { np = np->n_flink; continue; } /* * Now t points to the last entry with the same name * as np. Make np point beyond t. */ np->n_flink = t->n_flink; if (t->n_flink != NULL) t->n_flink->n_blink = np; np = np->n_flink; } return (new); } /* * Put another node onto a list of names and return * the list. */ struct name * put(struct name *list, struct name *node) { node->n_flink = list; node->n_blink = NULL; if (list != NULL) list->n_blink = node; return (node); } /* * Determine the number of undeleted elements in * a name list and return it. */ int count(struct name *np) { int c; for (c = 0; np != NULL; np = np->n_flink) if ((np->n_type & GDEL) == 0) c++; return (c); } /* * Delete the given name from a namelist. */ struct name * delname(struct name *np, char name[]) { struct name *p; for (p = np; p != NULL; p = p->n_flink) if (strcasecmp(p->n_name, name) == 0) { if (p->n_blink == NULL) { if (p->n_flink != NULL) p->n_flink->n_blink = NULL; np = p->n_flink; continue; } if (p->n_flink == NULL) { if (p->n_blink != NULL) p->n_blink->n_flink = NULL; continue; } p->n_blink->n_flink = p->n_flink; p->n_flink->n_blink = p->n_blink; } return (np); } /* * Pretty print a name list * Uncomment it if you need it. */ /* void prettyprint(struct name *name) { struct name *np; np = name; while (np != NULL) { fprintf(stderr, "%s(%d) ", np->n_name, np->n_type); np = np->n_flink; } fprintf(stderr, "\n"); } */