]>
diplodocus.org Git - nmh/blob - uip/whom.c
3 * whom.c -- report to whom a message would be sent
12 static struct swit switches
[] = {
14 { "alias aliasfile", 0 },
22 { "draftfolder +folder", 6 },
24 { "draftmessage msg", 6 },
26 { "nodraftfolder", 0 },
32 { "client host", -6 },
34 { "server host", -6 },
42 main (int argc
, char **argv
)
45 int i
, status
, isdf
= 0;
46 int distsw
= 0, vecp
= 0;
47 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
48 char *msg
= NULL
, **ap
, **argp
, backup
[BUFSIZ
];
49 char buf
[BUFSIZ
], **arguments
, *vec
[MAXARGS
];
52 setlocale(LC_ALL
, "");
54 invo_name
= r1bindex (argv
[0], '/');
56 /* read user profile/context */
59 arguments
= getarguments (invo_name
, argc
, argv
, 1);
62 vec
[vecp
++] = invo_name
;
63 vec
[vecp
++] = "-whom";
64 vec
[vecp
++] = "-library";
65 vec
[vecp
++] = getcpy (m_maildir (""));
67 while ((cp
= *argp
++)) {
69 switch (smatch (++cp
, switches
)) {
71 ambigsw (cp
, switches
);
74 adios (NULL
, "-%s unknown", cp
);
77 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
78 print_help (buf
, switches
, 1);
81 print_version(invo_name
);
96 adios (NULL
, "only one draft folder at a time!");
97 if (!(cp
= *argp
++) || *cp
== '-')
98 adios (NULL
, "missing argument to %s", argp
[-2]);
99 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
100 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
104 adios (NULL
, "only one draft message at a time!");
105 if (!(dmsg
= *argp
++) || *dmsg
== '-')
106 adios (NULL
, "missing argument to %s", argp
[-2]);
117 if (!(cp
= *argp
++) || *cp
== '-')
118 adios (NULL
, "missing argument to %s", argp
[-2]);
124 adios (NULL
, "only one draft at a time!");
126 vec
[vecp
++] = msg
= cp
;
129 /* allow Aliasfile: profile entry */
130 if ((cp
= context_find ("Aliasfile"))) {
133 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
134 vec
[vecp
++] = "-alias";
141 if (dfolder
|| (cp
= getenv ("mhdraft")) == NULL
|| *cp
== '\0')
143 cp
= getcpy (m_draft (dfolder
, dmsg
, 1, &isdf
));
144 msg
= vec
[vecp
++] = cp
;
146 if ((cp
= getenv ("mhdist"))
148 && (distsw
= atoi (cp
))
149 && (cp
= getenv ("mhaltmsg"))
151 if (distout (msg
, cp
, backup
) == NOTOK
)
153 vec
[vecp
++] = "-dist";
161 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
165 switch (distsw
? child_id
: OK
) {
167 advise (NULL
, "unable to fork, so checking directly...");
169 execvp (postproc
, vec
);
170 fprintf (stderr
, "unable to exec ");
175 SIGNAL (SIGHUP
, SIG_IGN
);
176 SIGNAL (SIGINT
, SIG_IGN
);
177 SIGNAL (SIGQUIT
, SIG_IGN
);
178 SIGNAL (SIGTERM
, SIG_IGN
);
180 status
= pidwait(child_id
, OK
);
183 if (rename (backup
, msg
) == NOTOK
)
184 adios (msg
, "unable to rename %s to", backup
);
188 return 0; /* dead code to satisfy the compiler */