]>
diplodocus.org Git - nmh/blob - uip/whom.c
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 SASLminc(a) (a)
16 #else /* CYRUS_SASL */
17 # define SASLminc(a) 0
18 #endif /* CYRUS_SASL */
21 # define TLSminc(a) (a)
22 #else /* TLS_SUPPORT */
24 #endif /* TLS_SUPPORT */
26 static struct swit switches
[] = {
28 { "alias aliasfile", 0 },
36 { "draftfolder +folder", 6 },
38 { "draftmessage msg", 6 },
40 { "nodraftfolder", 0 },
46 { "client host", -6 },
48 { "server host", -6 },
52 { "sasl", SASLminc(4) },
54 { "saslmech mechanism", SASLminc(-5) },
56 { "user username", SASLminc(-4) },
58 { "port server port name/number", 4 },
60 { "tls", TLSminc(-3) },
66 main (int argc
, char **argv
)
69 int i
, status
, isdf
= 0;
70 int distsw
= 0, vecp
= 0;
71 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
72 char *msg
= NULL
, **ap
, **argp
, backup
[BUFSIZ
];
73 char buf
[BUFSIZ
], **arguments
, *vec
[MAXARGS
];
76 setlocale(LC_ALL
, "");
78 invo_name
= r1bindex (argv
[0], '/');
80 /* read user profile/context */
83 arguments
= getarguments (invo_name
, argc
, argv
, 1);
86 vec
[vecp
++] = invo_name
;
87 vec
[vecp
++] = "-whom";
88 vec
[vecp
++] = "-library";
89 vec
[vecp
++] = getcpy (m_maildir (""));
91 /* Don't need to feed fileproc or mhlproc to post because
92 it doesn't use them when used for whom. */
94 while ((cp
= *argp
++)) {
96 switch (smatch (++cp
, switches
)) {
98 ambigsw (cp
, switches
);
101 adios (NULL
, "-%s unknown", cp
);
104 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
105 print_help (buf
, switches
, 1);
108 print_version(invo_name
);
125 adios (NULL
, "only one draft folder at a time!");
126 if (!(cp
= *argp
++) || *cp
== '-')
127 adios (NULL
, "missing argument to %s", argp
[-2]);
128 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
129 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
133 adios (NULL
, "only one draft message at a time!");
134 if (!(dmsg
= *argp
++) || *dmsg
== '-')
135 adios (NULL
, "missing argument to %s", argp
[-2]);
149 if (!(cp
= *argp
++) || *cp
== '-')
150 adios (NULL
, "missing argument to %s", argp
[-2]);
156 adios (NULL
, "only one draft at a time!");
158 vec
[vecp
++] = msg
= cp
;
161 /* allow Aliasfile: profile entry */
162 if ((cp
= context_find ("Aliasfile"))) {
165 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
166 vec
[vecp
++] = "-alias";
173 if (dfolder
|| (cp
= getenv ("mhdraft")) == NULL
|| *cp
== '\0')
175 cp
= getcpy (m_draft (dfolder
, dmsg
, 1, &isdf
));
176 msg
= vec
[vecp
++] = cp
;
178 if ((cp
= getenv ("mhdist"))
180 && (distsw
= atoi (cp
))
181 && (cp
= getenv ("mhaltmsg"))
183 if (distout (msg
, cp
, backup
) == NOTOK
)
185 vec
[vecp
++] = "-dist";
193 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
197 switch (distsw
? child_id
: OK
) {
199 advise (NULL
, "unable to fork, so checking directly...");
201 execvp (postproc
, vec
);
202 fprintf (stderr
, "unable to exec ");
207 SIGNAL (SIGHUP
, SIG_IGN
);
208 SIGNAL (SIGINT
, SIG_IGN
);
209 SIGNAL (SIGQUIT
, SIG_IGN
);
210 SIGNAL (SIGTERM
, SIG_IGN
);
212 status
= pidwait(child_id
, OK
);
215 if (rename (backup
, msg
) == NOTOK
)
216 adios (msg
, "unable to rename %s to", backup
);
220 return 0; /* dead code to satisfy the compiler */