1 /* whom.c - report who a message would go to */
3 static char ident[] = "@(#)$Id: whom.c,v 1.11 1992/12/15 00:20:22 jromine Exp $";
15 static struct swit switches[] = {
28 "draftfolder +folder", 6,
30 "draftmessage msg", 6,
73 setlocale(LC_ALL, "");
75 invo_name = r1bindex (argv[0], '/');
76 if ((cp = m_find (invo_name)) != NULL) {
77 ap = brkstring (cp = getcpy (cp), " ", "\n");
78 ap = copyip (ap, arguments);
82 (void) copyip (argv + 1, ap);
85 vec[vecp++] = invo_name;
86 vec[vecp++] = "-whom";
87 vec[vecp++] = "-library";
88 vec[vecp++] = getcpy (m_maildir (""));
92 while (cp = *argp++) {
94 switch (smatch (++cp, switches)) {
96 ambigsw (cp, switches);
99 adios (NULLCP, "-%s unknown", cp);
101 (void) sprintf (buf, "%s [switches] [file]", invo_name);
102 help (buf, switches);
117 adios (NULLCP, "only one draft folder at a time!");
118 if (!(cp = *argp++) || *cp == '-')
119 adios (NULLCP, "missing argument to %s", argp[-2]);
120 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
121 *cp != '@' ? TFOLDER : TSUBCWF);
125 adios (NULLCP, "only one draft message at a time!");
126 if (!(dmsg = *argp++) || *dmsg == '-')
127 adios (NULLCP, "missing argument to %s", argp[-2]);
138 if (!(cp = *argp++) || *cp == '-')
139 adios (NULLCP, "missing argument to %s", argp[-2]);
144 adios (NULLCP, "only one draft at a time!");
146 vec[vecp++] = msg = cp;
148 if (cp = m_find ("Aliasfile")) { /* allow Aliasfile: profile entry */
151 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
152 vec[vecp++] = "-alias";
161 if (dfolder || (cp = getenv ("mhdraft")) == NULL || *cp == '\0')
163 cp = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
164 msg = vec[vecp++] = cp;
166 if ((cp = getenv ("mhdist"))
168 && (distsw = atoi (cp))
169 && (cp = getenv ("mhaltmsg"))
171 if (distout (msg, cp, backup) == NOTOK)
173 vec[vecp++] = "-dist";
181 for (i = 0; (child_id = fork ()) == NOTOK && i < 5; i++)
183 switch (distsw ? child_id : OK) {
185 advise (NULLCP, "unable to fork, so checking directly...");
187 execvp (postproc, vec);
188 fprintf (stderr, "unable to exec ");
193 (void) signal (SIGHUP, SIG_IGN);
194 (void) signal (SIGINT, SIG_IGN);
195 (void) signal (SIGQUIT, SIG_IGN);
196 (void) signal (SIGTERM, SIG_IGN);
198 status = pidwait (child_id, OK);
201 if (rename (backup, msg) == NOTOK)
202 adios (msg, "unable to rename %s to", backup);