]>
diplodocus.org Git - nmh/blob - uip/whom.c
3 * whom.c -- report to whom a message would be sent
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
13 #include <h/signals.h>
16 static struct swit switches
[] = {
18 { "alias aliasfile", 0 },
26 { "draftfolder +folder", 6 },
28 { "draftmessage msg", 6 },
30 { "nodraftfolder", 0 },
36 { "client host", -6 },
38 { "server host", -6 },
46 main (int argc
, char **argv
)
49 int i
, status
, isdf
= 0;
50 int distsw
= 0, vecp
= 0;
51 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
52 char *msg
= NULL
, **ap
, **argp
, backup
[BUFSIZ
];
53 char buf
[BUFSIZ
], **arguments
, *vec
[MAXARGS
];
56 setlocale(LC_ALL
, "");
58 invo_name
= r1bindex (argv
[0], '/');
60 /* read user profile/context */
63 arguments
= getarguments (invo_name
, argc
, argv
, 1);
66 vec
[vecp
++] = invo_name
;
67 vec
[vecp
++] = "-whom";
68 vec
[vecp
++] = "-library";
69 vec
[vecp
++] = getcpy (m_maildir (""));
71 while ((cp
= *argp
++)) {
73 switch (smatch (++cp
, switches
)) {
75 ambigsw (cp
, switches
);
78 adios (NULL
, "-%s unknown", cp
);
81 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
82 print_help (buf
, switches
, 1);
85 print_version(invo_name
);
100 adios (NULL
, "only one draft folder at a time!");
101 if (!(cp
= *argp
++) || *cp
== '-')
102 adios (NULL
, "missing argument to %s", argp
[-2]);
103 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
104 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
108 adios (NULL
, "only one draft message at a time!");
109 if (!(dmsg
= *argp
++) || *dmsg
== '-')
110 adios (NULL
, "missing argument to %s", argp
[-2]);
121 if (!(cp
= *argp
++) || *cp
== '-')
122 adios (NULL
, "missing argument to %s", argp
[-2]);
128 adios (NULL
, "only one draft at a time!");
130 vec
[vecp
++] = msg
= cp
;
133 /* allow Aliasfile: profile entry */
134 if ((cp
= context_find ("Aliasfile"))) {
137 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
138 vec
[vecp
++] = "-alias";
145 if (dfolder
|| (cp
= getenv ("mhdraft")) == NULL
|| *cp
== '\0')
147 cp
= getcpy (m_draft (dfolder
, dmsg
, 1, &isdf
));
148 msg
= vec
[vecp
++] = cp
;
150 if ((cp
= getenv ("mhdist"))
152 && (distsw
= atoi (cp
))
153 && (cp
= getenv ("mhaltmsg"))
155 if (distout (msg
, cp
, backup
) == NOTOK
)
157 vec
[vecp
++] = "-dist";
165 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
169 switch (distsw
? child_id
: OK
) {
171 advise (NULL
, "unable to fork, so checking directly...");
173 execvp (postproc
, vec
);
174 fprintf (stderr
, "unable to exec ");
179 SIGNAL (SIGHUP
, SIG_IGN
);
180 SIGNAL (SIGINT
, SIG_IGN
);
181 SIGNAL (SIGQUIT
, SIG_IGN
);
182 SIGNAL (SIGTERM
, SIG_IGN
);
184 status
= pidwait(child_id
, OK
);
187 if (rename (backup
, msg
) == NOTOK
)
188 adios (msg
, "unable to rename %s to", backup
);
192 return 0; /* dead code to satisfy the compiler */