3 * whom.c -- report to whom a message would be sent
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include <h/signals.h>
15 # define TLSminc(a) (a)
16 #else /* TLS_SUPPORT */
18 #endif /* TLS_SUPPORT */
20 static struct swit switches[] = {
22 { "alias aliasfile", 0 },
30 { "draftfolder +folder", 6 },
32 { "draftmessage msg", 6 },
34 { "nodraftfolder", 0 },
40 { "client host", -6 },
42 { "server host", -6 },
46 { "port server port name/number", 4 },
48 { "tls", TLSminc(-3) },
54 main (int argc, char **argv)
57 int i, status, isdf = 0;
58 int distsw = 0, vecp = 0;
59 char *cp, *dfolder = NULL, *dmsg = NULL;
60 char *msg = NULL, **ap, **argp, backup[BUFSIZ];
61 char buf[BUFSIZ], **arguments, *vec[MAXARGS];
64 setlocale(LC_ALL, "");
66 invo_name = r1bindex (argv[0], '/');
68 /* read user profile/context */
71 arguments = getarguments (invo_name, argc, argv, 1);
74 vec[vecp++] = invo_name;
75 vec[vecp++] = "-whom";
76 vec[vecp++] = "-library";
77 vec[vecp++] = getcpy (m_maildir (""));
79 while ((cp = *argp++)) {
81 switch (smatch (++cp, switches)) {
83 ambigsw (cp, switches);
86 adios (NULL, "-%s unknown", cp);
89 snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name);
90 print_help (buf, switches, 1);
93 print_version(invo_name);
108 adios (NULL, "only one draft folder at a time!");
109 if (!(cp = *argp++) || *cp == '-')
110 adios (NULL, "missing argument to %s", argp[-2]);
111 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
112 *cp != '@' ? TFOLDER : TSUBCWF);
116 adios (NULL, "only one draft message at a time!");
117 if (!(dmsg = *argp++) || *dmsg == '-')
118 adios (NULL, "missing argument to %s", argp[-2]);
130 if (!(cp = *argp++) || *cp == '-')
131 adios (NULL, "missing argument to %s", argp[-2]);
137 adios (NULL, "only one draft at a time!");
139 vec[vecp++] = msg = cp;
142 /* allow Aliasfile: profile entry */
143 if ((cp = context_find ("Aliasfile"))) {
146 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
147 vec[vecp++] = "-alias";
154 if (dfolder || (cp = getenv ("mhdraft")) == NULL || *cp == '\0')
156 cp = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
157 msg = vec[vecp++] = cp;
159 if ((cp = getenv ("mhdist"))
161 && (distsw = atoi (cp))
162 && (cp = getenv ("mhaltmsg"))
164 if (distout (msg, cp, backup) == NOTOK)
166 vec[vecp++] = "-dist";
174 for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
178 switch (distsw ? child_id : OK) {
180 advise (NULL, "unable to fork, so checking directly...");
182 execvp (postproc, vec);
183 fprintf (stderr, "unable to exec ");
188 SIGNAL (SIGHUP, SIG_IGN);
189 SIGNAL (SIGINT, SIG_IGN);
190 SIGNAL (SIGQUIT, SIG_IGN);
191 SIGNAL (SIGTERM, SIG_IGN);
193 status = pidwait(child_id, OK);
196 if (rename (backup, msg) == NOTOK)
197 adios (msg, "unable to rename %s to", backup);
201 return 0; /* dead code to satisfy the compiler */