17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate 237c478bd9Sstevel@tonic-gate /* 24*6c83d09fSrobbin * Copyright 2002 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 28*6c83d09fSrobbin /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 29*6c83d09fSrobbin /* All Rights Reserved */ 30*6c83d09fSrobbin 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 337c478bd9Sstevel@tonic-gate * The Regents of the University of California 347c478bd9Sstevel@tonic-gate * All Rights Reserved 357c478bd9Sstevel@tonic-gate * 367c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 377c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 387c478bd9Sstevel@tonic-gate * contributors. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include "rcv.h" 447c478bd9Sstevel@tonic-gate #include <locale.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /* 477c478bd9Sstevel@tonic-gate * mailx -- a modified version of a University of California at Berkeley 487c478bd9Sstevel@tonic-gate * mail program 497c478bd9Sstevel@tonic-gate * 507c478bd9Sstevel@tonic-gate * Still more user commands. 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate static int bangexp(char *str); 547c478bd9Sstevel@tonic-gate static int diction(const void *a, const void *b); 557c478bd9Sstevel@tonic-gate static char *getfilename(char *name, int *aedit); 567c478bd9Sstevel@tonic-gate static int resp1(int *msgvec, int useauthor); 577c478bd9Sstevel@tonic-gate static int Resp1(int *msgvec, int useauthor); 587c478bd9Sstevel@tonic-gate static char *reedit(char *subj); 597c478bd9Sstevel@tonic-gate static int shell1(char *str); 607c478bd9Sstevel@tonic-gate static void sort(char **list); 617c478bd9Sstevel@tonic-gate static char *replyto(struct message *mp, char **f); 627c478bd9Sstevel@tonic-gate static int reply2sender(void); 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate static char prevfile[PATHSIZE]; 657c478bd9Sstevel@tonic-gate static char origprevfile[PATHSIZE]; 667c478bd9Sstevel@tonic-gate static char lastbang[BUFSIZ]; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * Process a shell escape by saving signals, ignoring signals, 707c478bd9Sstevel@tonic-gate * and forking a sh -c 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate int 747c478bd9Sstevel@tonic-gate shell(char *str) 757c478bd9Sstevel@tonic-gate { 767c478bd9Sstevel@tonic-gate shell1(str); 777c478bd9Sstevel@tonic-gate printf("!\n"); 787c478bd9Sstevel@tonic-gate return(0); 797c478bd9Sstevel@tonic-gate } 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate static int 827c478bd9Sstevel@tonic-gate shell1(char *str) 837c478bd9Sstevel@tonic-gate { 847c478bd9Sstevel@tonic-gate void (*sig[2])(int); 857c478bd9Sstevel@tonic-gate register int t; 867c478bd9Sstevel@tonic-gate register pid_t p; 877c478bd9Sstevel@tonic-gate char *Shell; 887c478bd9Sstevel@tonic-gate char cmd[BUFSIZ]; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate nstrcpy(cmd, sizeof (cmd), str); 917c478bd9Sstevel@tonic-gate if (bangexp(cmd) < 0) 927c478bd9Sstevel@tonic-gate return(-1); 937c478bd9Sstevel@tonic-gate if ((Shell = value("SHELL")) == NOSTR || *Shell=='\0') 947c478bd9Sstevel@tonic-gate Shell = SHELL; 957c478bd9Sstevel@tonic-gate for (t = SIGINT; t <= SIGQUIT; t++) 967c478bd9Sstevel@tonic-gate sig[t-SIGINT] = sigset(t, SIG_IGN); 977c478bd9Sstevel@tonic-gate p = vfork(); 987c478bd9Sstevel@tonic-gate if (p == 0) { 997c478bd9Sstevel@tonic-gate setuid(getuid()); 1007c478bd9Sstevel@tonic-gate sigchild(); 1017c478bd9Sstevel@tonic-gate for (t = SIGINT; t <= SIGQUIT; t++) 1027c478bd9Sstevel@tonic-gate if (sig[t-SIGINT] != SIG_IGN) 1037c478bd9Sstevel@tonic-gate sigsys(t, SIG_DFL); 1047c478bd9Sstevel@tonic-gate execlp(Shell, Shell, "-c", cmd, (char *)0); 1057c478bd9Sstevel@tonic-gate perror(Shell); 1067c478bd9Sstevel@tonic-gate _exit(1); 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate while (wait(0) != p) 1097c478bd9Sstevel@tonic-gate ; 1107c478bd9Sstevel@tonic-gate if (p == (pid_t)-1) 1117c478bd9Sstevel@tonic-gate perror("fork"); 1127c478bd9Sstevel@tonic-gate for (t = SIGINT; t <= SIGQUIT; t++) 1137c478bd9Sstevel@tonic-gate sigset(t, sig[t-SIGINT]); 1147c478bd9Sstevel@tonic-gate return(0); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * Fork an interactive shell. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate int 1227c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1237c478bd9Sstevel@tonic-gate dosh(char *) 1247c478bd9Sstevel@tonic-gate #else 1257c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1267c478bd9Sstevel@tonic-gate dosh(char *s) 1277c478bd9Sstevel@tonic-gate #endif 1287c478bd9Sstevel@tonic-gate { 1297c478bd9Sstevel@tonic-gate void (*sig[2])(int); 1307c478bd9Sstevel@tonic-gate register int t; 1317c478bd9Sstevel@tonic-gate register pid_t p; 1327c478bd9Sstevel@tonic-gate char *Shell; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate if ((Shell = value("SHELL")) == NOSTR || *Shell=='\0') 1357c478bd9Sstevel@tonic-gate Shell = SHELL; 1367c478bd9Sstevel@tonic-gate for (t = SIGINT; t <= SIGQUIT; t++) 1377c478bd9Sstevel@tonic-gate sig[t-SIGINT] = sigset(t, SIG_IGN); 1387c478bd9Sstevel@tonic-gate p = vfork(); 1397c478bd9Sstevel@tonic-gate if (p == 0) { 1407c478bd9Sstevel@tonic-gate setuid(getuid()); 1417c478bd9Sstevel@tonic-gate sigchild(); 1427c478bd9Sstevel@tonic-gate for (t = SIGINT; t <= SIGQUIT; t++) 1437c478bd9Sstevel@tonic-gate if (sig[t-SIGINT] != SIG_IGN) 1447c478bd9Sstevel@tonic-gate sigset(t, SIG_DFL); 1457c478bd9Sstevel@tonic-gate execlp(Shell, Shell, (char *)0); 1467c478bd9Sstevel@tonic-gate perror(Shell); 1477c478bd9Sstevel@tonic-gate _exit(1); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate while (wait(0) != p) 1507c478bd9Sstevel@tonic-gate ; 1517c478bd9Sstevel@tonic-gate if (p == (pid_t)-1) 1527c478bd9Sstevel@tonic-gate perror("fork"); 1537c478bd9Sstevel@tonic-gate for (t = SIGINT; t <= SIGQUIT; t++) 1547c478bd9Sstevel@tonic-gate sigset(t, sig[t-SIGINT]); 1557c478bd9Sstevel@tonic-gate putchar('\n'); 1567c478bd9Sstevel@tonic-gate return(0); 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* 1607c478bd9Sstevel@tonic-gate * Expand the shell escape by expanding unescaped !'s into the 1617c478bd9Sstevel@tonic-gate * last issued command where possible. 1627c478bd9Sstevel@tonic-gate */ 1637c478bd9Sstevel@tonic-gate static int 1647c478bd9Sstevel@tonic-gate bangexp(char *str) 1657c478bd9Sstevel@tonic-gate { 1667c478bd9Sstevel@tonic-gate char bangbuf[BUFSIZ]; 1677c478bd9Sstevel@tonic-gate register char *cp, *cp2; 1687c478bd9Sstevel@tonic-gate register int n; 1697c478bd9Sstevel@tonic-gate int changed = 0; 1707c478bd9Sstevel@tonic-gate int bangit = (value("bang")!=NOSTR); 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate cp = str; 1737c478bd9Sstevel@tonic-gate cp2 = bangbuf; 1747c478bd9Sstevel@tonic-gate n = BUFSIZ; 1757c478bd9Sstevel@tonic-gate while (*cp) { 1767c478bd9Sstevel@tonic-gate if (*cp=='!' && bangit) { 1777c478bd9Sstevel@tonic-gate if (n < (int)strlen(lastbang)) { 1787c478bd9Sstevel@tonic-gate overf: 1797c478bd9Sstevel@tonic-gate printf(gettext("Command buffer overflow\n")); 1807c478bd9Sstevel@tonic-gate return(-1); 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate changed++; 1837c478bd9Sstevel@tonic-gate strcpy(cp2, lastbang); 1847c478bd9Sstevel@tonic-gate cp2 += strlen(lastbang); 1857c478bd9Sstevel@tonic-gate n -= strlen(lastbang); 1867c478bd9Sstevel@tonic-gate cp++; 1877c478bd9Sstevel@tonic-gate continue; 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate if (*cp == '\\' && cp[1] == '!') { 1907c478bd9Sstevel@tonic-gate if (--n <= 1) 1917c478bd9Sstevel@tonic-gate goto overf; 1927c478bd9Sstevel@tonic-gate *cp2++ = '!'; 1937c478bd9Sstevel@tonic-gate cp += 2; 1947c478bd9Sstevel@tonic-gate changed++; 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate if (--n <= 1) 1977c478bd9Sstevel@tonic-gate goto overf; 1987c478bd9Sstevel@tonic-gate *cp2++ = *cp++; 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate *cp2 = 0; 2017c478bd9Sstevel@tonic-gate if (changed) { 2027c478bd9Sstevel@tonic-gate printf("!%s\n", bangbuf); 2037c478bd9Sstevel@tonic-gate fflush(stdout); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate nstrcpy(str, BUFSIZ, bangbuf); 2067c478bd9Sstevel@tonic-gate nstrcpy(lastbang, sizeof (lastbang), bangbuf); 2077c478bd9Sstevel@tonic-gate return(0); 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * Print out a nice help message from some file or another. 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate int 2157c478bd9Sstevel@tonic-gate help(void) 2167c478bd9Sstevel@tonic-gate { 217*6c83d09fSrobbin int c; 2187c478bd9Sstevel@tonic-gate register FILE *f; 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate if ((f = fopen(HELPFILE, "r")) == NULL) { 2217c478bd9Sstevel@tonic-gate printf(gettext("No help just now.\n")); 2227c478bd9Sstevel@tonic-gate return(1); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate while ((c = getc(f)) != EOF) 2257c478bd9Sstevel@tonic-gate putchar(c); 2267c478bd9Sstevel@tonic-gate fclose(f); 2277c478bd9Sstevel@tonic-gate return(0); 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * Change user's working directory. 2327c478bd9Sstevel@tonic-gate */ 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate int 2357c478bd9Sstevel@tonic-gate schdir(char *str) 2367c478bd9Sstevel@tonic-gate { 2377c478bd9Sstevel@tonic-gate register char *cp; 2387c478bd9Sstevel@tonic-gate char cwd[PATHSIZE], file[PATHSIZE]; 2397c478bd9Sstevel@tonic-gate static char efile[PATHSIZE]; 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate for (cp = str; *cp == ' '; cp++) 2427c478bd9Sstevel@tonic-gate ; 2437c478bd9Sstevel@tonic-gate if (*cp == '\0') 2447c478bd9Sstevel@tonic-gate cp = homedir; 2457c478bd9Sstevel@tonic-gate else 2467c478bd9Sstevel@tonic-gate if ((cp = expand(cp)) == NOSTR) 2477c478bd9Sstevel@tonic-gate return(1); 2487c478bd9Sstevel@tonic-gate if (editfile != NOSTR && (*editfile != '/' || mailname[0] != '/')) { 2497c478bd9Sstevel@tonic-gate if (getcwd(cwd, (int)sizeof (cwd)) == 0) { 2507c478bd9Sstevel@tonic-gate fprintf(stderr, 2517c478bd9Sstevel@tonic-gate gettext("Can't get current directory: %s\n"), cwd); 2527c478bd9Sstevel@tonic-gate return(1); 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate if (chdir(cp) < 0) { 2567c478bd9Sstevel@tonic-gate perror(cp); 2577c478bd9Sstevel@tonic-gate return(1); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate /* 2607c478bd9Sstevel@tonic-gate * Convert previously relative names to absolute names. 2617c478bd9Sstevel@tonic-gate */ 2627c478bd9Sstevel@tonic-gate if (editfile != NOSTR && *editfile != '/') { 2637c478bd9Sstevel@tonic-gate snprintf(file, sizeof (file), "%s/%s", cwd, editfile); 2647c478bd9Sstevel@tonic-gate nstrcpy(efile, sizeof (efile), file); 2657c478bd9Sstevel@tonic-gate editfile = efile; 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate if (mailname[0] != '/') { 2687c478bd9Sstevel@tonic-gate snprintf(file, sizeof (file), "%s/%s", cwd, mailname); 2697c478bd9Sstevel@tonic-gate nstrcpy(mailname, PATHSIZE, file); 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate return(0); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate /* 2757c478bd9Sstevel@tonic-gate * Two versions of reply. Reply to all names in message or reply 2767c478bd9Sstevel@tonic-gate * to only sender of message, depending on setting of "replyall". 2777c478bd9Sstevel@tonic-gate */ 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate int 2807c478bd9Sstevel@tonic-gate respond(int *msgvec) 2817c478bd9Sstevel@tonic-gate { 2827c478bd9Sstevel@tonic-gate if (reply2sender()) 2837c478bd9Sstevel@tonic-gate return(resp1(msgvec, 0)); 2847c478bd9Sstevel@tonic-gate else 2857c478bd9Sstevel@tonic-gate return(Resp1(msgvec, 0)); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate int 2897c478bd9Sstevel@tonic-gate followup(int *msgvec) 2907c478bd9Sstevel@tonic-gate { 2917c478bd9Sstevel@tonic-gate if (reply2sender()) 2927c478bd9Sstevel@tonic-gate return(resp1(msgvec, 1)); 2937c478bd9Sstevel@tonic-gate else 2947c478bd9Sstevel@tonic-gate return(Resp1(msgvec, 1)); 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate int 2987c478bd9Sstevel@tonic-gate replyall(int *msgvec) 2997c478bd9Sstevel@tonic-gate { 3007c478bd9Sstevel@tonic-gate return(resp1(msgvec, 0)); 3017c478bd9Sstevel@tonic-gate } 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate static int 3047c478bd9Sstevel@tonic-gate resp1(int *msgvec, int useauthor) 3057c478bd9Sstevel@tonic-gate { 3067c478bd9Sstevel@tonic-gate struct message *mp; 3077c478bd9Sstevel@tonic-gate char *cp, *buf, *rcv, *skin_rcv, *reply2, **ap, *returnaddr; 3087c478bd9Sstevel@tonic-gate struct name *np; 3097c478bd9Sstevel@tonic-gate struct header head; 3107c478bd9Sstevel@tonic-gate char mylocalname[BUFSIZ], mydomname[BUFSIZ]; 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate if (msgvec[1] != 0) { 3137c478bd9Sstevel@tonic-gate printf(gettext( 3147c478bd9Sstevel@tonic-gate "Sorry, can't reply to multiple messages at once\n")); 3157c478bd9Sstevel@tonic-gate return(1); 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate snprintf(mydomname, sizeof (mydomname), "%s@%s", myname, domain); 3187c478bd9Sstevel@tonic-gate snprintf(mylocalname, sizeof (mylocalname), "%s@%s", myname, host); 3197c478bd9Sstevel@tonic-gate returnaddr = value("returnaddr"); 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate mp = &message[msgvec[0] - 1]; 3227c478bd9Sstevel@tonic-gate dot = mp; 3237c478bd9Sstevel@tonic-gate reply2 = replyto(mp, &rcv); 3247c478bd9Sstevel@tonic-gate cp = skin(hfield("to", mp, addto)); 3257c478bd9Sstevel@tonic-gate if (cp != NOSTR) { 3267c478bd9Sstevel@tonic-gate buf = (char *)salloc(strlen(reply2) + strlen(cp) + 2); 3277c478bd9Sstevel@tonic-gate strcpy(buf, reply2); 3287c478bd9Sstevel@tonic-gate strcat(buf, " "); 3297c478bd9Sstevel@tonic-gate strcat(buf, cp); 3307c478bd9Sstevel@tonic-gate } else 3317c478bd9Sstevel@tonic-gate buf = reply2; 3327c478bd9Sstevel@tonic-gate np = elide(extract(buf, GTO)); 3337c478bd9Sstevel@tonic-gate #ifdef OPTIM 3347c478bd9Sstevel@tonic-gate /* rcv = netrename(rcv); */ 3357c478bd9Sstevel@tonic-gate #endif /* OPTIM */ 3367c478bd9Sstevel@tonic-gate /* 3377c478bd9Sstevel@tonic-gate * Delete my name from the reply list, 3387c478bd9Sstevel@tonic-gate * and with it, all my alternate names. 3397c478bd9Sstevel@tonic-gate */ 3407c478bd9Sstevel@tonic-gate skin_rcv = skin(rcv); 3417c478bd9Sstevel@tonic-gate mapf(np, skin_rcv); 3427c478bd9Sstevel@tonic-gate np = delname(np, myname); 3437c478bd9Sstevel@tonic-gate np = delname(np, mylocalname); 3447c478bd9Sstevel@tonic-gate np = delname(np, mydomname); 3457c478bd9Sstevel@tonic-gate if (returnaddr && *returnaddr) 3467c478bd9Sstevel@tonic-gate np = delname(np, returnaddr); 3477c478bd9Sstevel@tonic-gate if (altnames != 0) 3487c478bd9Sstevel@tonic-gate for (ap = altnames; *ap; ap++) 3497c478bd9Sstevel@tonic-gate np = delname(np, *ap); 3507c478bd9Sstevel@tonic-gate head.h_seq = 1; 3517c478bd9Sstevel@tonic-gate cp = detract(np, 0); 3527c478bd9Sstevel@tonic-gate if (cp == NOSTR) { 3537c478bd9Sstevel@tonic-gate if (reply2) 3547c478bd9Sstevel@tonic-gate cp = unuucp(reply2); 3557c478bd9Sstevel@tonic-gate else 3567c478bd9Sstevel@tonic-gate cp = unuucp(rcv); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate head.h_to = cp; 3597c478bd9Sstevel@tonic-gate head.h_subject = hfield("subject", mp, addone); 3607c478bd9Sstevel@tonic-gate if (head.h_subject == NOSTR) 3617c478bd9Sstevel@tonic-gate head.h_subject = hfield("subj", mp, addone); 3627c478bd9Sstevel@tonic-gate head.h_subject = reedit(head.h_subject); 3637c478bd9Sstevel@tonic-gate head.h_cc = NOSTR; 3647c478bd9Sstevel@tonic-gate cp = skin(hfield("cc", mp, addto)); 3657c478bd9Sstevel@tonic-gate if (cp != NOSTR) { 3667c478bd9Sstevel@tonic-gate np = elide(extract(cp, GCC)); 3677c478bd9Sstevel@tonic-gate mapf(np, skin_rcv); 3687c478bd9Sstevel@tonic-gate np = delname(np, myname); 3697c478bd9Sstevel@tonic-gate np = delname(np, mylocalname); 3707c478bd9Sstevel@tonic-gate np = delname(np, mydomname); 3717c478bd9Sstevel@tonic-gate if (returnaddr && *returnaddr) 3727c478bd9Sstevel@tonic-gate np = delname(np, returnaddr); 3737c478bd9Sstevel@tonic-gate np = delname(np, skin_rcv); 3747c478bd9Sstevel@tonic-gate if (altnames != 0) 3757c478bd9Sstevel@tonic-gate for (ap = altnames; *ap; ap++) 3767c478bd9Sstevel@tonic-gate np = delname(np, *ap); 3777c478bd9Sstevel@tonic-gate head.h_cc = detract(np, 0); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate head.h_bcc = NOSTR; 3807c478bd9Sstevel@tonic-gate head.h_defopt = NOSTR; 3817c478bd9Sstevel@tonic-gate head.h_others = NOSTRPTR; 3827c478bd9Sstevel@tonic-gate mail1(&head, useauthor, useauthor ? rcv : NOSTR); 3837c478bd9Sstevel@tonic-gate return(0); 3847c478bd9Sstevel@tonic-gate } 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate void 3877c478bd9Sstevel@tonic-gate getrecf(char *buf, char *recfile, int useauthor, int sz_recfile) 3887c478bd9Sstevel@tonic-gate { 3897c478bd9Sstevel@tonic-gate register char *bp, *cp; 3907c478bd9Sstevel@tonic-gate register char *recf = recfile; 3917c478bd9Sstevel@tonic-gate register int folderize; 3927c478bd9Sstevel@tonic-gate char fldr[BUFSIZ]; 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate folderize = (value("outfolder")!=NOSTR && getfold(fldr) == 0); 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate if (useauthor) { 3977c478bd9Sstevel@tonic-gate if (folderize) 3987c478bd9Sstevel@tonic-gate *recf++ = '+'; 3997c478bd9Sstevel@tonic-gate if (debug) fprintf(stderr, "buf='%s'\n", buf); 4007c478bd9Sstevel@tonic-gate for (bp=skin(buf), cp=recf; *bp && !any(*bp, ", "); bp++) { 4017c478bd9Sstevel@tonic-gate if (*bp=='!') 4027c478bd9Sstevel@tonic-gate cp = recf; 4037c478bd9Sstevel@tonic-gate else 4047c478bd9Sstevel@tonic-gate *cp++ = *bp; 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate if (cp >= &recfile[sz_recfile - 1]) { 4077c478bd9Sstevel@tonic-gate printf(gettext("File name buffer overflow\n")); 4087c478bd9Sstevel@tonic-gate break; 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate *cp = '\0'; 4127c478bd9Sstevel@tonic-gate if (cp==recf) 4137c478bd9Sstevel@tonic-gate *recfile = '\0'; 4147c478bd9Sstevel@tonic-gate /* now strip off any Internet host names */ 4157c478bd9Sstevel@tonic-gate if ((cp = strchr(recf, '%')) == NOSTR) 4167c478bd9Sstevel@tonic-gate cp = strchr(recf, '@'); 4177c478bd9Sstevel@tonic-gate if (cp != NOSTR) 4187c478bd9Sstevel@tonic-gate *cp = '\0'; 4197c478bd9Sstevel@tonic-gate } else { 4207c478bd9Sstevel@tonic-gate if (cp = value("record")) { 4217c478bd9Sstevel@tonic-gate int sz = PATHSIZE; 4227c478bd9Sstevel@tonic-gate if (folderize && *cp!='+' && *cp!='/' 4237c478bd9Sstevel@tonic-gate && *safeexpand(cp)!='/') { 4247c478bd9Sstevel@tonic-gate *recf++ = '+'; 4257c478bd9Sstevel@tonic-gate sz--; 4267c478bd9Sstevel@tonic-gate } 4277c478bd9Sstevel@tonic-gate nstrcpy(recf, sz, cp); 4287c478bd9Sstevel@tonic-gate } else 4297c478bd9Sstevel@tonic-gate *recf = '\0'; 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate if (debug) fprintf(stderr, "recfile='%s'\n", recfile); 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate /* 4357c478bd9Sstevel@tonic-gate * Modify the subject we are replying to to begin with Re: if 4367c478bd9Sstevel@tonic-gate * it does not already. 4377c478bd9Sstevel@tonic-gate */ 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate static char * 4407c478bd9Sstevel@tonic-gate reedit(char *subj) 4417c478bd9Sstevel@tonic-gate { 4427c478bd9Sstevel@tonic-gate char sbuf[10]; 4437c478bd9Sstevel@tonic-gate register char *newsubj; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate if (subj == NOSTR) 4467c478bd9Sstevel@tonic-gate return(NOSTR); 4477c478bd9Sstevel@tonic-gate strncpy(sbuf, subj, 3); 4487c478bd9Sstevel@tonic-gate sbuf[3] = 0; 4497c478bd9Sstevel@tonic-gate if (icequal(sbuf, "re:")) 4507c478bd9Sstevel@tonic-gate return(subj); 4517c478bd9Sstevel@tonic-gate newsubj = (char *)salloc((unsigned)(strlen(subj) + 5)); 4527c478bd9Sstevel@tonic-gate sprintf(newsubj, "Re: %s", subj); 4537c478bd9Sstevel@tonic-gate return(newsubj); 4547c478bd9Sstevel@tonic-gate } 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate /* 4577c478bd9Sstevel@tonic-gate * Preserve the named messages, so that they will be sent 4587c478bd9Sstevel@tonic-gate * back to the system mailbox. 4597c478bd9Sstevel@tonic-gate */ 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate int 4627c478bd9Sstevel@tonic-gate preserve(int *msgvec) 4637c478bd9Sstevel@tonic-gate { 4647c478bd9Sstevel@tonic-gate register struct message *mp; 4657c478bd9Sstevel@tonic-gate register int *ip, mesg; 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate if (edit) { 4687c478bd9Sstevel@tonic-gate printf(gettext("Cannot \"preserve\" in edit mode\n")); 4697c478bd9Sstevel@tonic-gate return(1); 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate for (ip = msgvec; *ip != NULL; ip++) { 4727c478bd9Sstevel@tonic-gate mesg = *ip; 4737c478bd9Sstevel@tonic-gate mp = &message[mesg-1]; 4747c478bd9Sstevel@tonic-gate mp->m_flag |= MPRESERVE; 4757c478bd9Sstevel@tonic-gate mp->m_flag &= ~MBOX; 4767c478bd9Sstevel@tonic-gate dot = mp; 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate return(0); 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate /* 4827c478bd9Sstevel@tonic-gate * Mark all given messages as unread. 4837c478bd9Sstevel@tonic-gate */ 4847c478bd9Sstevel@tonic-gate int 4857c478bd9Sstevel@tonic-gate unread(int msgvec[]) 4867c478bd9Sstevel@tonic-gate { 4877c478bd9Sstevel@tonic-gate register int *ip; 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate for (ip = msgvec; *ip != NULL; ip++) { 4907c478bd9Sstevel@tonic-gate dot = &message[*ip-1]; 4917c478bd9Sstevel@tonic-gate dot->m_flag &= ~(MREAD|MTOUCH); 4927c478bd9Sstevel@tonic-gate dot->m_flag |= MSTATUS; 4937c478bd9Sstevel@tonic-gate } 4947c478bd9Sstevel@tonic-gate return(0); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate /* 4987c478bd9Sstevel@tonic-gate * Print the size of each message. 4997c478bd9Sstevel@tonic-gate */ 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate int 5027c478bd9Sstevel@tonic-gate messize(int *msgvec) 5037c478bd9Sstevel@tonic-gate { 5047c478bd9Sstevel@tonic-gate register struct message *mp; 5057c478bd9Sstevel@tonic-gate register int *ip, mesg; 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate for (ip = msgvec; *ip != NULL; ip++) { 5087c478bd9Sstevel@tonic-gate mesg = *ip; 5097c478bd9Sstevel@tonic-gate mp = &message[mesg-1]; 5107c478bd9Sstevel@tonic-gate dot = mp; 5117c478bd9Sstevel@tonic-gate printf("%d: %ld\n", mesg, mp->m_size); 5127c478bd9Sstevel@tonic-gate } 5137c478bd9Sstevel@tonic-gate return(0); 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate /* 5177c478bd9Sstevel@tonic-gate * Quit quickly. If we are sourcing, just pop the input level 5187c478bd9Sstevel@tonic-gate * by returning an error. 5197c478bd9Sstevel@tonic-gate */ 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate int 5227c478bd9Sstevel@tonic-gate rexit(int e) 5237c478bd9Sstevel@tonic-gate { 5247c478bd9Sstevel@tonic-gate if (sourcing) 5257c478bd9Sstevel@tonic-gate return(1); 5267c478bd9Sstevel@tonic-gate if (Tflag != NOSTR) 5277c478bd9Sstevel@tonic-gate close(creat(Tflag, TEMPPERM)); 5287c478bd9Sstevel@tonic-gate if (!edit) 5297c478bd9Sstevel@tonic-gate Verhogen(); 5307c478bd9Sstevel@tonic-gate exit(e ? e : rpterr); 5317c478bd9Sstevel@tonic-gate /* NOTREACHED */ 5327c478bd9Sstevel@tonic-gate return (0); /* shut up lint and CC */ 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate /* 5367c478bd9Sstevel@tonic-gate * Set or display a variable value. Syntax is similar to that 5377c478bd9Sstevel@tonic-gate * of csh. 5387c478bd9Sstevel@tonic-gate */ 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate int 5417c478bd9Sstevel@tonic-gate set(char **arglist) 5427c478bd9Sstevel@tonic-gate { 5437c478bd9Sstevel@tonic-gate register struct var *vp; 5447c478bd9Sstevel@tonic-gate register char *cp, *cp2; 5457c478bd9Sstevel@tonic-gate char varbuf[BUFSIZ], **ap, **p; 5467c478bd9Sstevel@tonic-gate int errs, h, s; 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate if (argcount(arglist) == 0) { 5497c478bd9Sstevel@tonic-gate for (h = 0, s = 1; h < HSHSIZE; h++) 5507c478bd9Sstevel@tonic-gate for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) 5517c478bd9Sstevel@tonic-gate s++; 5527c478bd9Sstevel@tonic-gate ap = (char **) salloc(s * sizeof *ap); 5537c478bd9Sstevel@tonic-gate for (h = 0, p = ap; h < HSHSIZE; h++) 5547c478bd9Sstevel@tonic-gate for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) 5557c478bd9Sstevel@tonic-gate *p++ = vp->v_name; 5567c478bd9Sstevel@tonic-gate *p = NOSTR; 5577c478bd9Sstevel@tonic-gate sort(ap); 5587c478bd9Sstevel@tonic-gate for (p = ap; *p != NOSTR; p++) 5597c478bd9Sstevel@tonic-gate if (((cp = value(*p)) != 0) && *cp) 5607c478bd9Sstevel@tonic-gate printf("%s=\"%s\"\n", *p, cp); 5617c478bd9Sstevel@tonic-gate else 5627c478bd9Sstevel@tonic-gate printf("%s\n", *p); 5637c478bd9Sstevel@tonic-gate return(0); 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate errs = 0; 5667c478bd9Sstevel@tonic-gate for (ap = arglist; *ap != NOSTR; ap++) { 5677c478bd9Sstevel@tonic-gate cp = *ap; 5687c478bd9Sstevel@tonic-gate cp2 = varbuf; 5697c478bd9Sstevel@tonic-gate while (*cp != '=' && *cp != '\0') 5707c478bd9Sstevel@tonic-gate *cp2++ = *cp++; 5717c478bd9Sstevel@tonic-gate *cp2 = '\0'; 5727c478bd9Sstevel@tonic-gate if (*cp == '\0') 5737c478bd9Sstevel@tonic-gate cp = ""; 5747c478bd9Sstevel@tonic-gate else 5757c478bd9Sstevel@tonic-gate cp++; 5767c478bd9Sstevel@tonic-gate if (equal(varbuf, "")) { 5777c478bd9Sstevel@tonic-gate printf(gettext("Non-null variable name required\n")); 5787c478bd9Sstevel@tonic-gate errs++; 5797c478bd9Sstevel@tonic-gate continue; 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate assign(varbuf, cp); 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate return(errs); 5847c478bd9Sstevel@tonic-gate } 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate /* 5877c478bd9Sstevel@tonic-gate * Unset a bunch of variable values. 5887c478bd9Sstevel@tonic-gate */ 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate int 5917c478bd9Sstevel@tonic-gate unset(char **arglist) 5927c478bd9Sstevel@tonic-gate { 5937c478bd9Sstevel@tonic-gate register int errs; 5947c478bd9Sstevel@tonic-gate register char **ap; 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate errs = 0; 5977c478bd9Sstevel@tonic-gate for (ap = arglist; *ap != NOSTR; ap++) 5987c478bd9Sstevel@tonic-gate errs += deassign(*ap); 5997c478bd9Sstevel@tonic-gate return(errs); 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate /* 6037c478bd9Sstevel@tonic-gate * Add users to a group. 6047c478bd9Sstevel@tonic-gate */ 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate int 6077c478bd9Sstevel@tonic-gate group(char **argv) 6087c478bd9Sstevel@tonic-gate { 6097c478bd9Sstevel@tonic-gate register struct grouphead *gh; 6107c478bd9Sstevel@tonic-gate register struct mgroup *gp; 6117c478bd9Sstevel@tonic-gate register int h; 6127c478bd9Sstevel@tonic-gate int s; 6137c478bd9Sstevel@tonic-gate char **ap, *gname, **p; 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate if (argcount(argv) == 0) { 6167c478bd9Sstevel@tonic-gate for (h = 0, s = 1; h < HSHSIZE; h++) 6177c478bd9Sstevel@tonic-gate for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) 6187c478bd9Sstevel@tonic-gate s++; 6197c478bd9Sstevel@tonic-gate ap = (char **) salloc(s * sizeof *ap); 6207c478bd9Sstevel@tonic-gate for (h = 0, p = ap; h < HSHSIZE; h++) 6217c478bd9Sstevel@tonic-gate for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) 6227c478bd9Sstevel@tonic-gate *p++ = gh->g_name; 6237c478bd9Sstevel@tonic-gate *p = NOSTR; 6247c478bd9Sstevel@tonic-gate sort(ap); 6257c478bd9Sstevel@tonic-gate for (p = ap; *p != NOSTR; p++) 6267c478bd9Sstevel@tonic-gate printgroup(*p); 6277c478bd9Sstevel@tonic-gate return(0); 6287c478bd9Sstevel@tonic-gate } 6297c478bd9Sstevel@tonic-gate if (argcount(argv) == 1) { 6307c478bd9Sstevel@tonic-gate printgroup(*argv); 6317c478bd9Sstevel@tonic-gate return(0); 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate gname = *argv; 6347c478bd9Sstevel@tonic-gate h = hash(gname); 6357c478bd9Sstevel@tonic-gate if ((gh = findgroup(gname)) == NOGRP) { 6367c478bd9Sstevel@tonic-gate if ((gh = (struct grouphead *) 6377c478bd9Sstevel@tonic-gate calloc(sizeof (*gh), 1)) == NULL) { 6387c478bd9Sstevel@tonic-gate panic("Failed to allocate memory for group"); 6397c478bd9Sstevel@tonic-gate } 6407c478bd9Sstevel@tonic-gate gh->g_name = vcopy(gname); 6417c478bd9Sstevel@tonic-gate gh->g_list = NOGE; 6427c478bd9Sstevel@tonic-gate gh->g_link = groups[h]; 6437c478bd9Sstevel@tonic-gate groups[h] = gh; 6447c478bd9Sstevel@tonic-gate } 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate /* 6477c478bd9Sstevel@tonic-gate * Insert names from the command list into the group. 6487c478bd9Sstevel@tonic-gate * Who cares if there are duplicates? They get tossed 6497c478bd9Sstevel@tonic-gate * later anyway. 6507c478bd9Sstevel@tonic-gate */ 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate for (ap = argv+1; *ap != NOSTR; ap++) { 6537c478bd9Sstevel@tonic-gate if ((gp = (struct mgroup *) 6547c478bd9Sstevel@tonic-gate calloc(sizeof (*gp), 1)) == NULL) { 6557c478bd9Sstevel@tonic-gate panic("Failed to allocate memory for group"); 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate gp->ge_name = vcopy(*ap); 6587c478bd9Sstevel@tonic-gate gp->ge_link = gh->g_list; 6597c478bd9Sstevel@tonic-gate gh->g_list = gp; 6607c478bd9Sstevel@tonic-gate } 6617c478bd9Sstevel@tonic-gate return(0); 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate /* 6657c478bd9Sstevel@tonic-gate * Remove users from a group. 6667c478bd9Sstevel@tonic-gate */ 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate int 6697c478bd9Sstevel@tonic-gate ungroup(char **argv) 6707c478bd9Sstevel@tonic-gate { 6717c478bd9Sstevel@tonic-gate register struct grouphead *gh, **ghp; 6727c478bd9Sstevel@tonic-gate register struct mgroup *gp, *gpnext; 6737c478bd9Sstevel@tonic-gate register int h; 6747c478bd9Sstevel@tonic-gate char **ap, *gname; 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate if (argcount(argv) == 0) { 6777c478bd9Sstevel@tonic-gate printf("Must specify alias or group to remove\n"); 6787c478bd9Sstevel@tonic-gate return(1); 6797c478bd9Sstevel@tonic-gate } 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate /* 6827c478bd9Sstevel@tonic-gate * Remove names on the command list from the group list. 6837c478bd9Sstevel@tonic-gate */ 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate for (ap = argv; *ap != NOSTR; ap++) { 6867c478bd9Sstevel@tonic-gate gname = *ap; 6877c478bd9Sstevel@tonic-gate h = hash(gname); 6887c478bd9Sstevel@tonic-gate for (ghp = &groups[h]; *ghp != NOGRP; ghp = &((*ghp)->g_link)) { 6897c478bd9Sstevel@tonic-gate gh = *ghp; 6907c478bd9Sstevel@tonic-gate if (equal(gh->g_name, gname)) { 6917c478bd9Sstevel@tonic-gate /* remove from list */ 6927c478bd9Sstevel@tonic-gate *ghp = gh->g_link; 6937c478bd9Sstevel@tonic-gate /* free each member of gorup */ 6947c478bd9Sstevel@tonic-gate for (gp = gh->g_list; gp != NOGE; gp = gpnext) { 6957c478bd9Sstevel@tonic-gate gpnext = gp->ge_link; 6967c478bd9Sstevel@tonic-gate vfree(gp->ge_name); 6977c478bd9Sstevel@tonic-gate free(gp); 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate vfree(gh->g_name); 7007c478bd9Sstevel@tonic-gate free(gh); 7017c478bd9Sstevel@tonic-gate break; 7027c478bd9Sstevel@tonic-gate } 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate return(0); 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate /* 7097c478bd9Sstevel@tonic-gate * Sort the passed string vecotor into ascending dictionary 7107c478bd9Sstevel@tonic-gate * order. 7117c478bd9Sstevel@tonic-gate */ 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate static void 7147c478bd9Sstevel@tonic-gate sort(char **list) 7157c478bd9Sstevel@tonic-gate { 7167c478bd9Sstevel@tonic-gate register char **ap; 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate for (ap = list; *ap != NOSTR; ap++) 7197c478bd9Sstevel@tonic-gate ; 7207c478bd9Sstevel@tonic-gate if (ap-list < 2) 7217c478bd9Sstevel@tonic-gate return; 7227c478bd9Sstevel@tonic-gate qsort((char *) list, (unsigned) (ap-list), sizeof *list, diction); 7237c478bd9Sstevel@tonic-gate } 7247c478bd9Sstevel@tonic-gate 7257c478bd9Sstevel@tonic-gate /* 7267c478bd9Sstevel@tonic-gate * Do a dictionary order comparison of the arguments from 7277c478bd9Sstevel@tonic-gate * qsort. 7287c478bd9Sstevel@tonic-gate */ 7297c478bd9Sstevel@tonic-gate static int 7307c478bd9Sstevel@tonic-gate diction(const void *a, const void *b) 7317c478bd9Sstevel@tonic-gate { 7327c478bd9Sstevel@tonic-gate return(strcmp(*(char **)a, *(char **)b)); 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate /* 7367c478bd9Sstevel@tonic-gate * The do nothing command for comments. 7377c478bd9Sstevel@tonic-gate */ 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate int 7407c478bd9Sstevel@tonic-gate #ifdef __cplusplus 7417c478bd9Sstevel@tonic-gate null(char *) 7427c478bd9Sstevel@tonic-gate #else 7437c478bd9Sstevel@tonic-gate /* ARGSUSED */ 7447c478bd9Sstevel@tonic-gate null(char *s) 7457c478bd9Sstevel@tonic-gate #endif 7467c478bd9Sstevel@tonic-gate { 7477c478bd9Sstevel@tonic-gate return(0); 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate 7507c478bd9Sstevel@tonic-gate /* 7517c478bd9Sstevel@tonic-gate * Print out the current edit file, if we are editing. 7527c478bd9Sstevel@tonic-gate * Otherwise, print the name of the person who's mail 7537c478bd9Sstevel@tonic-gate * we are reading. 7547c478bd9Sstevel@tonic-gate */ 7557c478bd9Sstevel@tonic-gate int 7567c478bd9Sstevel@tonic-gate file(char **argv) 7577c478bd9Sstevel@tonic-gate { 7587c478bd9Sstevel@tonic-gate register char *cp; 7597c478bd9Sstevel@tonic-gate int editing, mdot; 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate if (argv[0] == NOSTR) { 7627c478bd9Sstevel@tonic-gate mdot = newfileinfo(1); 7637c478bd9Sstevel@tonic-gate dot = &message[mdot - 1]; 7647c478bd9Sstevel@tonic-gate return(0); 7657c478bd9Sstevel@tonic-gate } 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate /* 7687c478bd9Sstevel@tonic-gate * Acker's! Must switch to the new file. 7697c478bd9Sstevel@tonic-gate * We use a funny interpretation -- 7707c478bd9Sstevel@tonic-gate * # -- gets the previous file 7717c478bd9Sstevel@tonic-gate * % -- gets the invoker's post office box 7727c478bd9Sstevel@tonic-gate * %user -- gets someone else's post office box 7737c478bd9Sstevel@tonic-gate * & -- gets invoker's mbox file 7747c478bd9Sstevel@tonic-gate * string -- reads the given file 7757c478bd9Sstevel@tonic-gate */ 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate cp = getfilename(argv[0], &editing); 7787c478bd9Sstevel@tonic-gate if (cp == NOSTR) 7797c478bd9Sstevel@tonic-gate return(-1); 7807c478bd9Sstevel@tonic-gate if (setfile(cp, editing)) { 7817c478bd9Sstevel@tonic-gate nstrcpy(origname, PATHSIZE, origprevfile); 7827c478bd9Sstevel@tonic-gate return(-1); 7837c478bd9Sstevel@tonic-gate } 7847c478bd9Sstevel@tonic-gate mdot = newfileinfo(1); 7857c478bd9Sstevel@tonic-gate dot = &message[mdot - 1]; 7867c478bd9Sstevel@tonic-gate return(0); 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate /* 7907c478bd9Sstevel@tonic-gate * Evaluate the string given as a new mailbox name. 7917c478bd9Sstevel@tonic-gate * Ultimately, we want this to support a number of meta characters. 7927c478bd9Sstevel@tonic-gate * Possibly: 7937c478bd9Sstevel@tonic-gate * % -- for my system mail box 7947c478bd9Sstevel@tonic-gate * %user -- for user's system mail box 7957c478bd9Sstevel@tonic-gate * # -- for previous file 7967c478bd9Sstevel@tonic-gate * & -- get's invoker's mbox file 7977c478bd9Sstevel@tonic-gate * file name -- for any other file 7987c478bd9Sstevel@tonic-gate */ 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate static char * 8017c478bd9Sstevel@tonic-gate getfilename(char *name, int *aedit) 8027c478bd9Sstevel@tonic-gate { 8037c478bd9Sstevel@tonic-gate register char *cp; 8047c478bd9Sstevel@tonic-gate char savename[BUFSIZ]; 8057c478bd9Sstevel@tonic-gate char oldmailname[BUFSIZ]; 8067c478bd9Sstevel@tonic-gate char tmp[BUFSIZ]; 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate /* 8097c478bd9Sstevel@tonic-gate * Assume we will be in "edit file" mode, until 8107c478bd9Sstevel@tonic-gate * proven wrong. 8117c478bd9Sstevel@tonic-gate */ 8127c478bd9Sstevel@tonic-gate *aedit = 1; 8137c478bd9Sstevel@tonic-gate switch (*name) { 8147c478bd9Sstevel@tonic-gate case '%': 8157c478bd9Sstevel@tonic-gate *aedit = 0; 8167c478bd9Sstevel@tonic-gate nstrcpy(prevfile, sizeof (prevfile), editfile); 8177c478bd9Sstevel@tonic-gate nstrcpy(origprevfile, sizeof (origprevfile), origname); 8187c478bd9Sstevel@tonic-gate if (name[1] != 0) { 8197c478bd9Sstevel@tonic-gate nstrcpy(oldmailname, sizeof (oldmailname), mailname); 8207c478bd9Sstevel@tonic-gate findmail(name+1); 8217c478bd9Sstevel@tonic-gate cp = savestr(mailname); 8227c478bd9Sstevel@tonic-gate nstrcpy(origname, PATHSIZE, cp); 8237c478bd9Sstevel@tonic-gate nstrcpy(mailname, PATHSIZE, oldmailname); 8247c478bd9Sstevel@tonic-gate return(cp); 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate nstrcpy(oldmailname, sizeof (oldmailname), mailname); 8277c478bd9Sstevel@tonic-gate findmail(NULL); 8287c478bd9Sstevel@tonic-gate cp = savestr(mailname); 8297c478bd9Sstevel@tonic-gate nstrcpy(mailname, PATHSIZE, oldmailname); 8307c478bd9Sstevel@tonic-gate nstrcpy(origname, PATHSIZE, cp); 8317c478bd9Sstevel@tonic-gate return(cp); 8327c478bd9Sstevel@tonic-gate 8337c478bd9Sstevel@tonic-gate case '#': 8347c478bd9Sstevel@tonic-gate if (name[1] != 0) 8357c478bd9Sstevel@tonic-gate goto regular; 8367c478bd9Sstevel@tonic-gate if (prevfile[0] == 0) { 8377c478bd9Sstevel@tonic-gate printf(gettext("No previous file\n")); 8387c478bd9Sstevel@tonic-gate return(NOSTR); 8397c478bd9Sstevel@tonic-gate } 8407c478bd9Sstevel@tonic-gate cp = savestr(prevfile); 8417c478bd9Sstevel@tonic-gate nstrcpy(prevfile, sizeof (prevfile), editfile); 8427c478bd9Sstevel@tonic-gate nstrcpy(tmp, sizeof (tmp), origname); 8437c478bd9Sstevel@tonic-gate nstrcpy(origname, PATHSIZE, origprevfile); 8447c478bd9Sstevel@tonic-gate nstrcpy(origprevfile, sizeof (origprevfile), tmp); 8457c478bd9Sstevel@tonic-gate return(cp); 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate case '&': 8487c478bd9Sstevel@tonic-gate nstrcpy(prevfile, sizeof (prevfile), editfile); 8497c478bd9Sstevel@tonic-gate nstrcpy(origprevfile, sizeof (origprevfile), origname); 8507c478bd9Sstevel@tonic-gate if (name[1] == 0) { 8517c478bd9Sstevel@tonic-gate cp=Getf("MBOX"); 8527c478bd9Sstevel@tonic-gate nstrcpy(origname, PATHSIZE, cp); 8537c478bd9Sstevel@tonic-gate return(cp); 8547c478bd9Sstevel@tonic-gate } 8557c478bd9Sstevel@tonic-gate /* Fall into . . . */ 8567c478bd9Sstevel@tonic-gate 8577c478bd9Sstevel@tonic-gate default: 8587c478bd9Sstevel@tonic-gate regular: 8597c478bd9Sstevel@tonic-gate nstrcpy(prevfile, sizeof (prevfile), editfile); 8607c478bd9Sstevel@tonic-gate nstrcpy(origprevfile, sizeof (origprevfile), origname); 8617c478bd9Sstevel@tonic-gate cp = safeexpand(name); 8627c478bd9Sstevel@tonic-gate nstrcpy(origname, PATHSIZE, cp); 8637c478bd9Sstevel@tonic-gate if (cp[0] != '/') { 8647c478bd9Sstevel@tonic-gate name = getcwd(NOSTR, PATHSIZE); 8657c478bd9Sstevel@tonic-gate nstrcat(name, PATHSIZE, "/"); 8667c478bd9Sstevel@tonic-gate nstrcat(name, PATHSIZE, cp); 8677c478bd9Sstevel@tonic-gate cp = name; 8687c478bd9Sstevel@tonic-gate } 8697c478bd9Sstevel@tonic-gate return(cp); 8707c478bd9Sstevel@tonic-gate } 8717c478bd9Sstevel@tonic-gate } 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate /* 8747c478bd9Sstevel@tonic-gate * Expand file names like echo 8757c478bd9Sstevel@tonic-gate */ 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate int 8787c478bd9Sstevel@tonic-gate echo(register char **argv) 8797c478bd9Sstevel@tonic-gate { 8807c478bd9Sstevel@tonic-gate register char *cp; 8817c478bd9Sstevel@tonic-gate int neednl = 0; 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate while (*argv != NOSTR) { 8847c478bd9Sstevel@tonic-gate cp = *argv++; 8857c478bd9Sstevel@tonic-gate if ((cp = expand(cp)) != NOSTR) { 8867c478bd9Sstevel@tonic-gate neednl++; 8877c478bd9Sstevel@tonic-gate printf("%s", cp); 8887c478bd9Sstevel@tonic-gate if (*argv!=NOSTR) 8897c478bd9Sstevel@tonic-gate putchar(' '); 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate } 8927c478bd9Sstevel@tonic-gate if (neednl) 8937c478bd9Sstevel@tonic-gate putchar('\n'); 8947c478bd9Sstevel@tonic-gate return(0); 8957c478bd9Sstevel@tonic-gate } 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate /* 8987c478bd9Sstevel@tonic-gate * Reply to a series of messages by simply mailing to the senders 8997c478bd9Sstevel@tonic-gate * and not messing around with the To: and Cc: lists as in normal 9007c478bd9Sstevel@tonic-gate * reply. 9017c478bd9Sstevel@tonic-gate */ 9027c478bd9Sstevel@tonic-gate 9037c478bd9Sstevel@tonic-gate int 9047c478bd9Sstevel@tonic-gate Respond(int *msgvec) 9057c478bd9Sstevel@tonic-gate { 9067c478bd9Sstevel@tonic-gate if (reply2sender()) 9077c478bd9Sstevel@tonic-gate return(Resp1(msgvec, 0)); 9087c478bd9Sstevel@tonic-gate else 9097c478bd9Sstevel@tonic-gate return(resp1(msgvec, 0)); 9107c478bd9Sstevel@tonic-gate } 9117c478bd9Sstevel@tonic-gate 9127c478bd9Sstevel@tonic-gate int 9137c478bd9Sstevel@tonic-gate Followup(int *msgvec) 9147c478bd9Sstevel@tonic-gate { 9157c478bd9Sstevel@tonic-gate if (reply2sender()) 9167c478bd9Sstevel@tonic-gate return(Resp1(msgvec, 1)); 9177c478bd9Sstevel@tonic-gate else 9187c478bd9Sstevel@tonic-gate return(resp1(msgvec, 1)); 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate int 9227c478bd9Sstevel@tonic-gate replysender(int *msgvec) 9237c478bd9Sstevel@tonic-gate { 9247c478bd9Sstevel@tonic-gate return(Resp1(msgvec, 0)); 9257c478bd9Sstevel@tonic-gate } 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate static int 9287c478bd9Sstevel@tonic-gate Resp1(int *msgvec, int useauthor) 9297c478bd9Sstevel@tonic-gate { 9307c478bd9Sstevel@tonic-gate struct header head; 9317c478bd9Sstevel@tonic-gate struct message *mp; 9327c478bd9Sstevel@tonic-gate register int s, *ap; 9337c478bd9Sstevel@tonic-gate register char *cp, *cp2, *subject; 9347c478bd9Sstevel@tonic-gate 9357c478bd9Sstevel@tonic-gate for (s = 0, ap = msgvec; *ap != 0; ap++) { 9367c478bd9Sstevel@tonic-gate mp = &message[*ap - 1]; 9377c478bd9Sstevel@tonic-gate dot = mp; 9387c478bd9Sstevel@tonic-gate cp = replyto(mp, NOSTRPTR); 9397c478bd9Sstevel@tonic-gate s += strlen(cp) + 1; 9407c478bd9Sstevel@tonic-gate } 9417c478bd9Sstevel@tonic-gate if (s == 0) 9427c478bd9Sstevel@tonic-gate return(0); 9437c478bd9Sstevel@tonic-gate cp = (char *)salloc(s + 2); 9447c478bd9Sstevel@tonic-gate head.h_to = cp; 9457c478bd9Sstevel@tonic-gate for (ap = msgvec; *ap != 0; ap++) { 9467c478bd9Sstevel@tonic-gate mp = &message[*ap - 1]; 9477c478bd9Sstevel@tonic-gate cp2 = replyto(mp, NOSTRPTR); 9487c478bd9Sstevel@tonic-gate cp = copy(cp2, cp); 9497c478bd9Sstevel@tonic-gate *cp++ = ' '; 9507c478bd9Sstevel@tonic-gate } 9517c478bd9Sstevel@tonic-gate *--cp = 0; 9527c478bd9Sstevel@tonic-gate mp = &message[msgvec[0] - 1]; 9537c478bd9Sstevel@tonic-gate subject = hfield("subject", mp, addone); 9547c478bd9Sstevel@tonic-gate head.h_seq = 1; 9557c478bd9Sstevel@tonic-gate if (subject == NOSTR) 9567c478bd9Sstevel@tonic-gate subject = hfield("subj", mp, addone); 9577c478bd9Sstevel@tonic-gate head.h_subject = reedit(subject); 9587c478bd9Sstevel@tonic-gate if (subject != NOSTR) 9597c478bd9Sstevel@tonic-gate head.h_seq++; 9607c478bd9Sstevel@tonic-gate head.h_cc = NOSTR; 9617c478bd9Sstevel@tonic-gate head.h_bcc = NOSTR; 9627c478bd9Sstevel@tonic-gate head.h_defopt = NOSTR; 9637c478bd9Sstevel@tonic-gate head.h_others = NOSTRPTR; 9647c478bd9Sstevel@tonic-gate mail1(&head, useauthor, NOSTR); 9657c478bd9Sstevel@tonic-gate return(0); 9667c478bd9Sstevel@tonic-gate } 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate /* 9697c478bd9Sstevel@tonic-gate * Conditional commands. These allow one to parameterize one's 9707c478bd9Sstevel@tonic-gate * .mailrc and do some things if sending, others if receiving. 9717c478bd9Sstevel@tonic-gate */ 9727c478bd9Sstevel@tonic-gate 9737c478bd9Sstevel@tonic-gate int 9747c478bd9Sstevel@tonic-gate ifcmd(char **argv) 9757c478bd9Sstevel@tonic-gate { 9767c478bd9Sstevel@tonic-gate register char *cp; 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate if (cond != CANY) { 9797c478bd9Sstevel@tonic-gate printf(gettext("Illegal nested \"if\"\n")); 9807c478bd9Sstevel@tonic-gate return(1); 9817c478bd9Sstevel@tonic-gate } 9827c478bd9Sstevel@tonic-gate cond = CANY; 9837c478bd9Sstevel@tonic-gate cp = argv[0]; 9847c478bd9Sstevel@tonic-gate switch (*cp) { 9857c478bd9Sstevel@tonic-gate case 'r': case 'R': 9867c478bd9Sstevel@tonic-gate cond = CRCV; 9877c478bd9Sstevel@tonic-gate break; 9887c478bd9Sstevel@tonic-gate 9897c478bd9Sstevel@tonic-gate case 's': case 'S': 9907c478bd9Sstevel@tonic-gate cond = CSEND; 9917c478bd9Sstevel@tonic-gate break; 9927c478bd9Sstevel@tonic-gate 9937c478bd9Sstevel@tonic-gate case 't': case 'T': 9947c478bd9Sstevel@tonic-gate cond = CTTY; 9957c478bd9Sstevel@tonic-gate break; 9967c478bd9Sstevel@tonic-gate 9977c478bd9Sstevel@tonic-gate default: 9987c478bd9Sstevel@tonic-gate printf(gettext("Unrecognized if-keyword: \"%s\"\n"), cp); 9997c478bd9Sstevel@tonic-gate return(1); 10007c478bd9Sstevel@tonic-gate } 10017c478bd9Sstevel@tonic-gate return(0); 10027c478bd9Sstevel@tonic-gate } 10037c478bd9Sstevel@tonic-gate 10047c478bd9Sstevel@tonic-gate /* 10057c478bd9Sstevel@tonic-gate * Implement 'else'. This is pretty simple -- we just 10067c478bd9Sstevel@tonic-gate * flip over the conditional flag. 10077c478bd9Sstevel@tonic-gate */ 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate int 10107c478bd9Sstevel@tonic-gate elsecmd(void) 10117c478bd9Sstevel@tonic-gate { 10127c478bd9Sstevel@tonic-gate 10137c478bd9Sstevel@tonic-gate switch (cond) { 10147c478bd9Sstevel@tonic-gate case CANY: 10157c478bd9Sstevel@tonic-gate printf(gettext("\"Else\" without matching \"if\"\n")); 10167c478bd9Sstevel@tonic-gate return(1); 10177c478bd9Sstevel@tonic-gate 10187c478bd9Sstevel@tonic-gate case CSEND: 10197c478bd9Sstevel@tonic-gate cond = CRCV; 10207c478bd9Sstevel@tonic-gate break; 10217c478bd9Sstevel@tonic-gate 10227c478bd9Sstevel@tonic-gate case CRCV: 10237c478bd9Sstevel@tonic-gate cond = CSEND; 10247c478bd9Sstevel@tonic-gate break; 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate case CTTY: 10277c478bd9Sstevel@tonic-gate cond = CNOTTY; 10287c478bd9Sstevel@tonic-gate break; 10297c478bd9Sstevel@tonic-gate 10307c478bd9Sstevel@tonic-gate case CNOTTY: 10317c478bd9Sstevel@tonic-gate cond = CTTY; 10327c478bd9Sstevel@tonic-gate break; 10337c478bd9Sstevel@tonic-gate 10347c478bd9Sstevel@tonic-gate default: 10357c478bd9Sstevel@tonic-gate printf(gettext("invalid condition encountered\n")); 10367c478bd9Sstevel@tonic-gate cond = CANY; 10377c478bd9Sstevel@tonic-gate break; 10387c478bd9Sstevel@tonic-gate } 10397c478bd9Sstevel@tonic-gate return(0); 10407c478bd9Sstevel@tonic-gate } 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate /* 10437c478bd9Sstevel@tonic-gate * End of if statement. Just set cond back to anything. 10447c478bd9Sstevel@tonic-gate */ 10457c478bd9Sstevel@tonic-gate 10467c478bd9Sstevel@tonic-gate int 10477c478bd9Sstevel@tonic-gate endifcmd(void) 10487c478bd9Sstevel@tonic-gate { 10497c478bd9Sstevel@tonic-gate 10507c478bd9Sstevel@tonic-gate if (cond == CANY) { 10517c478bd9Sstevel@tonic-gate printf(gettext("\"Endif\" without matching \"if\"\n")); 10527c478bd9Sstevel@tonic-gate return(1); 10537c478bd9Sstevel@tonic-gate } 10547c478bd9Sstevel@tonic-gate cond = CANY; 10557c478bd9Sstevel@tonic-gate return(0); 10567c478bd9Sstevel@tonic-gate } 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate /* 10597c478bd9Sstevel@tonic-gate * Set the list of alternate names. 10607c478bd9Sstevel@tonic-gate */ 10617c478bd9Sstevel@tonic-gate int 10627c478bd9Sstevel@tonic-gate alternates(char **namelist) 10637c478bd9Sstevel@tonic-gate { 10647c478bd9Sstevel@tonic-gate register int c; 10657c478bd9Sstevel@tonic-gate register char **ap, **ap2, *cp; 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate c = argcount(namelist) + 1; 10687c478bd9Sstevel@tonic-gate if (c == 1) { 10697c478bd9Sstevel@tonic-gate if (altnames == 0) 10707c478bd9Sstevel@tonic-gate return(0); 10717c478bd9Sstevel@tonic-gate for (ap = altnames; *ap; ap++) 10727c478bd9Sstevel@tonic-gate printf("%s ", *ap); 10737c478bd9Sstevel@tonic-gate printf("\n"); 10747c478bd9Sstevel@tonic-gate return (0); 10757c478bd9Sstevel@tonic-gate } 10767c478bd9Sstevel@tonic-gate if (altnames != 0) 10777c478bd9Sstevel@tonic-gate free((char *)altnames); 10787c478bd9Sstevel@tonic-gate if ((altnames = (char **) 10797c478bd9Sstevel@tonic-gate calloc((unsigned)c, sizeof (char *))) == NULL) 10807c478bd9Sstevel@tonic-gate panic("Failed to allocate memory"); 10817c478bd9Sstevel@tonic-gate for (ap = namelist, ap2 = altnames; *ap; ap++, ap2++) { 10827c478bd9Sstevel@tonic-gate if ((cp = (char *) 10837c478bd9Sstevel@tonic-gate calloc((unsigned)strlen(*ap) + 1, sizeof (char))) == NULL) 10847c478bd9Sstevel@tonic-gate panic("Failed to allocate memory"); 10857c478bd9Sstevel@tonic-gate strcpy(cp, *ap); 10867c478bd9Sstevel@tonic-gate *ap2 = cp; 10877c478bd9Sstevel@tonic-gate } 10887c478bd9Sstevel@tonic-gate *ap2 = 0; 10897c478bd9Sstevel@tonic-gate return(0); 10907c478bd9Sstevel@tonic-gate } 10917c478bd9Sstevel@tonic-gate 10927c478bd9Sstevel@tonic-gate /* 10937c478bd9Sstevel@tonic-gate * Figure out who to reply to. 10947c478bd9Sstevel@tonic-gate * Return the real sender in *f. 10957c478bd9Sstevel@tonic-gate */ 10967c478bd9Sstevel@tonic-gate static char * 10977c478bd9Sstevel@tonic-gate replyto(struct message *mp, char **f) 10987c478bd9Sstevel@tonic-gate { 10997c478bd9Sstevel@tonic-gate char *r, *rf; 11007c478bd9Sstevel@tonic-gate 11017c478bd9Sstevel@tonic-gate if ((rf = skin(hfield("from", mp, addto)))==NOSTR) 11027c478bd9Sstevel@tonic-gate rf = skin(addto(NOSTR, nameof(mp))); 11037c478bd9Sstevel@tonic-gate if ((r = skin(hfield("reply-to", mp, addto)))==NOSTR) 11047c478bd9Sstevel@tonic-gate r = rf; 11057c478bd9Sstevel@tonic-gate if (f) 11067c478bd9Sstevel@tonic-gate *f = rf; 11077c478bd9Sstevel@tonic-gate return (r); 11087c478bd9Sstevel@tonic-gate } 11097c478bd9Sstevel@tonic-gate 11107c478bd9Sstevel@tonic-gate /* 11117c478bd9Sstevel@tonic-gate * reply2sender - determine whether a "reply" command should reply to the 11127c478bd9Sstevel@tonic-gate * sender of the messages, or to all the recipients of the 11137c478bd9Sstevel@tonic-gate * message. 11147c478bd9Sstevel@tonic-gate * 11157c478bd9Sstevel@tonic-gate * With the advent of POSIX.2 compliance, this has become 11167c478bd9Sstevel@tonic-gate * a bit more complicated, and so should be done in one 11177c478bd9Sstevel@tonic-gate * place, for all to use. 11187c478bd9Sstevel@tonic-gate */ 11197c478bd9Sstevel@tonic-gate 11207c478bd9Sstevel@tonic-gate static int 11217c478bd9Sstevel@tonic-gate reply2sender (void) 11227c478bd9Sstevel@tonic-gate { 11237c478bd9Sstevel@tonic-gate register int rep = (value("replyall") != NOSTR); 11247c478bd9Sstevel@tonic-gate register int flp = (value("flipr") != NOSTR); 11257c478bd9Sstevel@tonic-gate 11267c478bd9Sstevel@tonic-gate return((rep && !flp)|| (!rep && flp)); 11277c478bd9Sstevel@tonic-gate } 1128