Path: seismo!harvard!husc6!talcott!panda!genrad!wjh12!mirror!rs (Rich Salz) From: sources-request@panda.UUCP Newsgroups: mod.sources Subject: Patches to BSD4.2 mail (SysV mailx?) Message-ID: <1798@panda.UUCP> Date: 5 May 86 14:01:42 GMT Sender: jpn@panda.UUCP Lines: 542 Approved: jpn@panda.UUCP Mod.sources: Volume 4, Issue 95 Submitted by: mirror!rs (Rich Salz) Some people might find the following patches to BSD4.2 Mail useful. They implement the following changes: 1. If you typed "~r" and left off out filename, the message "Interpolate what file?" is very confusing; I changed it to "Filename missing." 2. On our machines, "everyone" is an alias for every user. Beginning users often confuse the "r" and "R" commands, so that "yes I am interested in lunch" messages go to everyone, rather than just the sender. If the variable "naive" is set, attempts to "reply" when one of the recipients is "everyone" will fail. I put "set naive" in /usr/lib/Mail.rc. 3. If you "save," "write," or "copy" a message, and the name of the file starts with a "|" the message is piped into the given program. Two notes: saying "s |lpr" will print the message on the printer and also mark it for deletion; searching for a pipe in a message subject line no longer works. 4. If the variable "autoquit" is set, referencing past the end of your mailbox via "next" or "dt" will automatically close out the message and exit. This is implemented such that you could ask for verification, but I didn't put that it (because it's kind of stupid). Basically, this means that you can use "dt" to cycle through your mail and exit when done. enjoy, /rich $alz -- Rich $alz {mit-eddie, ihnp4!inmet, wjh12, cca, datacube}!mirror!rs Mirror Systems 2067 Massachusetts Avenue Cambridge, MA, 02140 Telephone: 6,176,610,777 -------------------------------CUT. NOT A SHAR FILE---------------------- *** /src/ucb/ucb/Mail/misc/Mail.help Fri Aug 22 02:44:18 1980 --- ./misc/Mail.help Tue Apr 22 17:36:42 1986 *************** *** 16,22 c [directory] chdir to directory or home if none given A consists of integers, ranges of same, or user names separated ! by spaces. If omitted, Mail uses the last message typed. A consists of user names or distribution names separated by spaces. Distribution names are defined in .sendrc in your home directory. --- 16,22 ----- c [directory] chdir to directory or home if none given A consists of integers, ranges of same, or user names separated ! by spaces. If omitted, Mail uses the last message typed. A ! consists of user names or distribution names separated by spaces. A filename can start with "|", meaning "save to pipe." *************** *** 18,22 A consists of integers, ranges of same, or user names separated by spaces. If omitted, Mail uses the last message typed. ! A consists of user names or distribution names separated by spaces. ! Distribution names are defined in .sendrc in your home directory. --- 19,22 ----- by spaces. If omitted, Mail uses the last message typed. A consists of user names or distribution names separated by spaces. ! A filename can start with "|", meaning "save to pipe." *** /src/ucb/ucb/Mail/cmd2.c Fri Aug 12 01:22:27 1983 --- ./cmd2.c Tue Apr 22 17:58:34 1986 *************** *** 56,61 if (*ip2 == NULL) ip2 = msgvec; } while (ip2 != ip); printf("No messages applicable\n"); return(1); } --- 56,63 ----- if (*ip2 == NULL) ip2 = msgvec; } while (ip2 != ip); + if (value("autoquit") != NOSTR) + autoquit(); printf("No messages applicable\n"); return(1); } *************** *** 77,82 if ((mp->m_flag & (MDELETED|MSAVED)) == 0) break; if (mp >= &message[msgCount]) { printf("At EOF\n"); return(0); } --- 79,86 ----- if ((mp->m_flag & (MDELETED|MSAVED)) == 0) break; if (mp >= &message[msgCount]) { + if (value("autoquit") != NOSTR) + autoquit(); printf("At EOF\n"); return(0); } *************** *** 119,125 save1(str, mark) char str[]; { ! register int *ip, mesg; register struct message *mp; char *file, *disp, *cmd; int f, *msgvec, lc, t; --- 123,129 ----- save1(str, mark) char str[]; { ! register int *ip, mesg, piped; register struct message *mp; char *file, *disp, *cmd; int f, *msgvec, lc, t; *************** *** 141,147 } if (f && getmsglist(str, msgvec, 0) < 0) return(1); ! if ((file = expand(file)) == NOSTR) return(1); printf("\"%s\" ", file); flush(); --- 145,153 ----- } if (f && getmsglist(str, msgvec, 0) < 0) return(1); ! if (piped = *file == '|') ! ; ! else if ((file = expand(file)) == NOSTR) return(1); printf("\"%s\" ", file); flush(); *************** *** 145,151 return(1); printf("\"%s\" ", file); flush(); ! if (stat(file, &statb) >= 0) disp = "[Appended]"; else disp = "[New file]"; --- 151,159 ----- return(1); printf("\"%s\" ", file); flush(); ! if (piped) ! disp = "[Piped]"; ! else if (stat(file, &statb) >= 0) disp = "[Appended]"; else disp = "[New file]"; *************** *** 149,155 disp = "[Appended]"; else disp = "[New file]"; ! if ((obuf = fopen(file, "a")) == NULL) { perror(NOSTR); return(1); } --- 157,163 ----- disp = "[Appended]"; else disp = "[New file]"; ! if ((obuf = piped ? popen(&file[1], "w") : fopen(file, "a")) == NULL) { perror(NOSTR); return(1); } *************** *** 161,167 mp = &message[mesg-1]; if ((t = send(mp, obuf, 0)) < 0) { perror(file); ! fclose(obuf); return(1); } lc += t; --- 169,178 ----- mp = &message[mesg-1]; if ((t = send(mp, obuf, 0)) < 0) { perror(file); ! if (piped) ! pclose(obuf); ! else ! fclose(obuf); return(1); } lc += t; *************** *** 172,178 fflush(obuf); if (ferror(obuf)) perror(file); ! fclose(obuf); printf("%s %d/%ld\n", disp, lc, cc); return(0); } --- 183,192 ----- fflush(obuf); if (ferror(obuf)) perror(file); ! if (piped) ! pclose(obuf); ! else ! fclose(obuf); printf("%s %d/%ld\n", disp, lc, cc); return(0); } *************** *** 185,191 swrite(str) char str[]; { ! register int *ip, mesg; register struct message *mp; register char *file, *disp; char linebuf[BUFSIZ]; --- 199,205 ----- swrite(str) char str[]; { ! register int *ip, mesg, piped; register struct message *mp; register char *file, *disp; char linebuf[BUFSIZ]; *************** *** 196,202 msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec); if ((file = snarf(str, &f)) == NOSTR) return(1); ! if ((file = expand(file)) == NOSTR) return(1); if (!f) { *msgvec = first(0, MMNORM); --- 210,218 ----- msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec); if ((file = snarf(str, &f)) == NOSTR) return(1); ! if (piped = file[0] == '|') ! ; ! else if ((file = expand(file)) == NOSTR) return(1); if (!f) { *msgvec = first(0, MMNORM); *************** *** 210,215 return(1); printf("\"%s\" ", file); flush(); if (stat(file, &statb) >= 0) disp = "[Appended]"; else --- 226,233 ----- return(1); printf("\"%s\" ", file); flush(); + if (piped) + disp = "[Piped]"; if (stat(file, &statb) >= 0) disp = "[Appended]"; else *************** *** 214,220 disp = "[Appended]"; else disp = "[New file]"; ! if ((obuf = fopen(file, "a")) == NULL) { perror(NOSTR); return(1); } --- 232,238 ----- disp = "[Appended]"; else disp = "[New file]"; ! if ((obuf = piped ? popen(&file[1], "w") : fopen(file, "a")) == NULL) { perror(NOSTR); return(1); } *************** *** 237,243 fflush(obuf); if (ferror(obuf)) perror(file); ! fclose(obuf); printf("%s %d/%d\n", disp, lc, cc); return(0); } --- 255,264 ----- fflush(obuf); if (ferror(obuf)) perror(file); ! if (piped) ! pclose(obuf); ! else ! fclose(obuf); printf("%s %d/%d\n", disp, lc, cc); return(0); } *************** *** 257,262 int *flag; { register char *cp; *flag = 1; cp = strlen(linebuf) + linebuf - 1; --- 278,284 ----- int *flag; { register char *cp; + register char *q; *flag = 1; cp = strlen(linebuf) + linebuf - 1; *************** *** 270,275 *++cp = 0; /* * Now search for the beginning of the file name. */ --- 292,306 ----- *++cp = 0; /* + * See if the name has a pipe symbol in it. + */ + if (q = index(linebuf, '|')) { + *q = 0; + if (q = linebuf) + *flag = 0; + return(q + 1); + } + /* * Now search for the beginning of the file name. */ *************** *** 315,320 list[1] = NULL; return(type(list)); } printf("At EOF\n"); return(0); } --- 346,353 ----- list[1] = NULL; return(type(list)); } + if (value("autoquit") != NOSTR) + autoquit(); printf("At EOF\n"); return(0); } *************** *** 319,324 return(0); } else { printf("No more messages\n"); return(0); } --- 352,359 ----- return(0); } else { + if (value("autoquit") != NOSTR) + autoquit(); printf("No more messages\n"); return(0); } *************** *** 323,328 return(0); } } /* * Delete the indicated messages. --- 358,376 ----- return(0); } } + + + autoquit() + { + printf("Last message... exiting\n"); + edstop(); + sigset(SIGHUP, SIG_IGN); + sigset(SIGINT, SIG_IGN); + sigset(SIGQUIT, SIG_IGN); + quit(); + exit(0); + } + /* * Delete the indicated messages. *** /src/ucb/ucb/Mail/cmd3.c Fri Aug 12 01:22:28 1983 --- ./cmd3.c Tue Apr 22 12:53:46 1986 *************** *** 194,199 char buf[2 * LINESIZE], **ap; struct name *np; struct header head; if (msgvec[1] != 0) { printf("Sorry, can't reply to multiple messages at once\n"); --- 194,200 ----- char buf[2 * LINESIZE], **ap; struct name *np; struct header head; + int naive; if (msgvec[1] != 0) { printf("Sorry, can't reply to multiple messages at once\n"); *************** *** 244,249 strcpy(buf, cp); } head.h_to = buf; head.h_subject = hfield("subject", mp); if (head.h_subject == NOSTR) head.h_subject = hfield("subj", mp); --- 245,252 ----- strcpy(buf, cp); } head.h_to = buf; + if ((naive = value("naive") != NOSTR) && *buf && dangerous(buf)) + goto notall; head.h_subject = hfield("subject", mp); if (head.h_subject == NOSTR) head.h_subject = hfield("subj", mp); *************** *** 261,266 head.h_cc = detract(np, 0); } } head.h_bcc = NOSTR; mail1(&head); return(0); --- 264,271 ----- head.h_cc = detract(np, 0); } } + if (naive && head.h_cc != NOSTR && dangerous(head.h_cc)) + goto notall; head.h_bcc = NOSTR; mail1(&head); return(0); *************** *** 264,269 head.h_bcc = NOSTR; mail1(&head); return(0); } /* --- 269,292 ----- head.h_bcc = NOSTR; mail1(&head); return(0); + + notall: + printf("Naive userse can't reply to \"everyone\".\n"); + return(1); + } + + + dangerous(p) + register char *p; + { + static char *text="everyone"; + char *index(); + + if (strlen(p) >= sizeof text - 1) + for (; p = index(p, *text); p++) + if (!strncmp(p, text, sizeof text - 1)) + return(1); + return(0); } /* *** /src/ucb/ucb/Mail/collect.c Fri Aug 12 01:22:28 1983 --- ./collect.c Mon Apr 21 16:42:21 1986 *************** *** 261,267 while (any(*cp, " \t")) cp++; if (*cp == '\0') { ! printf("Interpolate what file?\n"); break; } cp = expand(cp); --- 261,267 ----- while (any(*cp, " \t")) cp++; if (*cp == '\0') { ! printf("Filename missing!?\n"); break; } cp = expand(cp); ---------- end of submission -----------