]>
diplodocus.org Git - nmh/blob - uip/whom.c
1 /* whom.c -- report to whom a message would be sent
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
10 #include <h/signals.h>
11 #include "sbr/m_maildir.h"
12 #include "sbr/m_mktemp.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 #define WHOM_SWITCHES \
27 X("alias aliasfile", 0, ALIASW) \
28 X("check", 0, CHKSW) \
29 X("nocheck", 0, NOCHKSW) \
30 X("draft", 0, DRAFTSW) \
31 X("draftfolder +folder", 6, DFOLDSW) \
32 X("draftmessage msg", 6, DMSGSW) \
33 X("nodraftfolder", 0, NDFLDSW) \
34 X("version", 0, VERSIONSW) \
35 X("help", 0, HELPSW) \
36 X("client host", -6, CLIESW) \
37 X("server host", 0, SERVSW) \
38 X("snoop", 0, SNOOPSW) \
39 X("sasl", SASLminc(4), SASLSW) \
40 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
41 X("user username", SASLminc(-4), USERSW) \
42 X("port server port name/number", 4, PORTSW) \
43 X("tls", TLSminc(-3), TLSSW) \
44 X("initialtls", TLSminc(-10), INITTLSSW) \
45 X("notls", TLSminc(-5), NTLSSW) \
46 X("mts smtp|sendmail/smtp|sendmail/pipe", 0, MTSSW) \
48 #define X(sw, minchars, id) id,
49 DEFINE_SWITCH_ENUM(WHOM
);
52 #define X(sw, minchars, id) { sw, minchars, id },
53 DEFINE_SWITCH_ARRAY(WHOM
, switches
);
58 main (int argc
, char **argv
)
62 int distsw
= 0, vecp
= 0;
63 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
64 char *msg
= NULL
, **ap
, **argp
, backup
[BUFSIZ
];
65 char buf
[BUFSIZ
], **arguments
, *vec
[MAXARGS
];
67 if (nmh_init(argv
[0], 2)) { return 1; }
69 arguments
= getarguments (invo_name
, argc
, argv
, 1);
72 vec
[vecp
++] = invo_name
;
73 vec
[vecp
++] = "-whom";
74 vec
[vecp
++] = "-library";
75 vec
[vecp
++] = getcpy (m_maildir (""));
77 if ((cp
= context_find ("credentials"))) {
78 /* post doesn't read context so need to pass credentials. */
79 vec
[vecp
++] = "-credentials";
83 /* Don't need to feed fileproc or mhlproc to post because
84 it doesn't use them when used for whom. */
86 while ((cp
= *argp
++)) {
88 switch (smatch (++cp
, switches
)) {
90 ambigsw (cp
, switches
);
93 adios (NULL
, "-%s unknown", cp
);
96 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
97 print_help (buf
, switches
, 1);
100 print_version(invo_name
);
119 adios (NULL
, "only one draft folder at a time!");
120 if (!(cp
= *argp
++) || *cp
== '-')
121 adios (NULL
, "missing argument to %s", argp
[-2]);
122 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
123 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
127 adios (NULL
, "only one draft message at a time!");
128 if (!(dmsg
= *argp
++) || *dmsg
== '-')
129 adios (NULL
, "missing argument to %s", argp
[-2]);
144 if (!(cp
= *argp
++) || *cp
== '-')
145 adios (NULL
, "missing argument to %s", argp
[-2]);
151 adios (NULL
, "only one draft at a time!");
152 vec
[vecp
++] = msg
= cp
;
155 /* allow Aliasfile: profile entry */
156 if ((cp
= context_find ("Aliasfile"))) {
159 for (ap
= brkstring(dp
= mh_xstrdup(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
160 vec
[vecp
++] = "-alias";
166 cp
= getcpy (m_draft (dfolder
, dmsg
, 1, &isdf
));
167 msg
= vec
[vecp
++] = cp
;
169 if ((cp
= getenv ("mhdist"))
171 && (distsw
= atoi (cp
))
172 && (cp
= getenv ("mhaltmsg"))
174 if (distout (msg
, cp
, backup
) == NOTOK
)
176 vec
[vecp
++] = "-dist";
186 switch (distsw
? child_id
: OK
) {
188 inform("unable to fork, so checking directly...");
191 execvp (postproc
, vec
);
192 fprintf (stderr
, "unable to exec ");
197 SIGNAL (SIGHUP
, SIG_IGN
);
198 SIGNAL (SIGINT
, SIG_IGN
);
199 SIGNAL (SIGQUIT
, SIG_IGN
);
200 SIGNAL (SIGTERM
, SIG_IGN
);
202 status
= pidwait(child_id
, OK
);
204 (void) m_unlink (msg
);
205 if (rename (backup
, msg
) == NOTOK
)
206 adios (msg
, "unable to rename %s to", backup
);
210 return 0; /* dead code to satisfy the compiler */