]>
diplodocus.org Git - nmh/blob - uip/whom.c
6264298c764af6e7bf0deb36694d1e87f375df72
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.
9 #include "sbr/ambigsw.h"
11 #include "sbr/print_version.h"
12 #include "sbr/print_help.h"
13 #include "sbr/error.h"
16 #include "h/signals.h"
17 #include "sbr/m_maildir.h"
18 #include "sbr/m_mktemp.h"
21 # define SASLminc(a) (a)
22 #else /* CYRUS_SASL */
23 # define SASLminc(a) 0
24 #endif /* CYRUS_SASL */
27 # define TLSminc(a) (a)
28 #else /* TLS_SUPPORT */
30 #endif /* TLS_SUPPORT */
32 #define WHOM_SWITCHES \
33 X("alias aliasfile", 0, ALIASW) \
34 X("check", 0, CHKSW) \
35 X("nocheck", 0, NOCHKSW) \
36 X("draft", 0, DRAFTSW) \
37 X("draftfolder +folder", 6, DFOLDSW) \
38 X("draftmessage msg", 6, DMSGSW) \
39 X("nodraftfolder", 0, NDFLDSW) \
40 X("version", 0, VERSIONSW) \
41 X("help", 0, HELPSW) \
42 X("client host", -6, CLIESW) \
43 X("server host", 0, SERVSW) \
44 X("snoop", 0, SNOOPSW) \
45 X("sasl", SASLminc(4), SASLSW) \
46 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
47 X("user username", SASLminc(-4), USERSW) \
48 X("port server port name/number", 4, PORTSW) \
49 X("tls", TLSminc(-3), TLSSW) \
50 X("initialtls", TLSminc(-10), INITTLSSW) \
51 X("notls", TLSminc(-5), NTLSSW) \
52 X("mts smtp|sendmail/smtp|sendmail/pipe", 0, MTSSW) \
54 #define X(sw, minchars, id) id,
55 DEFINE_SWITCH_ENUM(WHOM
);
58 #define X(sw, minchars, id) { sw, minchars, id },
59 DEFINE_SWITCH_ARRAY(WHOM
, switches
);
64 main (int argc
, char **argv
)
70 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
71 char *msg
= NULL
, **ap
, **argp
, backup
[BUFSIZ
];
72 char buf
[BUFSIZ
], **arguments
, *vec
[MAXARGS
];
74 if (nmh_init(argv
[0], true, false)) { return 1; }
76 arguments
= getarguments (invo_name
, argc
, argv
, 1);
79 vec
[vecp
++] = invo_name
;
80 vec
[vecp
++] = "-whom";
81 vec
[vecp
++] = "-library";
82 vec
[vecp
++] = mh_xstrdup(m_maildir(""));
84 if ((cp
= context_find ("credentials"))) {
85 /* post doesn't read context so need to pass credentials. */
86 vec
[vecp
++] = "-credentials";
90 /* Don't need to feed fileproc or mhlproc to post because
91 it doesn't use them when used for whom. */
93 while ((cp
= *argp
++)) {
95 switch (smatch (++cp
, switches
)) {
97 ambigsw (cp
, switches
);
100 die("-%s unknown", cp
);
103 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
104 print_help (buf
, switches
, 1);
107 print_version(invo_name
);
126 die("only one draft folder at a time!");
127 if (!(cp
= *argp
++) || *cp
== '-')
128 die("missing argument to %s", argp
[-2]);
129 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
130 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
134 die("only one draft message at a time!");
135 if (!(dmsg
= *argp
++) || *dmsg
== '-')
136 die("missing argument to %s", argp
[-2]);
151 if (!(cp
= *argp
++) || *cp
== '-')
152 die("missing argument to %s", argp
[-2]);
158 die("only one draft at a time!");
159 vec
[vecp
++] = msg
= cp
;
162 /* allow Aliasfile: profile entry */
163 if ((cp
= context_find ("Aliasfile"))) {
166 for (ap
= brkstring(dp
= mh_xstrdup(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
167 vec
[vecp
++] = "-alias";
173 cp
= mh_xstrdup(m_draft(dfolder
, dmsg
, 1, &isdf
));
174 msg
= vec
[vecp
++] = cp
;
177 distsw
= (cp
= getenv("mhdist")) && *cp
&& atoi(cp
) &&
178 (cp
= getenv("mhaltmsg")) && *cp
;
180 if (distout (msg
, cp
, backup
) == NOTOK
)
182 vec
[vecp
++] = "-dist";
189 if ((child_id
= fork()) == -1)
190 adios("fork", "failed:");
193 SIGNAL (SIGHUP
, SIG_IGN
);
194 SIGNAL (SIGINT
, SIG_IGN
);
195 SIGNAL (SIGQUIT
, SIG_IGN
);
196 SIGNAL (SIGTERM
, SIG_IGN
);
198 status
= pidwait(child_id
, OK
);
200 (void) m_unlink (msg
);
201 if (rename (backup
, msg
) == NOTOK
)
202 adios (msg
, "unable to rename %s to", backup
);
207 /* Either the child, or no fork occurred. */
208 execvp (postproc
, vec
);
209 fprintf (stderr
, "unable to exec ");