]>
diplodocus.org Git - nmh/blob - uip/whom.c
f1f38fe1e458e1e0f4556ad0502331dba3d6065e
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/print_help.h"
10 #include "sbr/error.h"
13 #include "h/signals.h"
14 #include "sbr/m_maildir.h"
15 #include "sbr/m_mktemp.h"
18 # define SASLminc(a) (a)
19 #else /* CYRUS_SASL */
20 # define SASLminc(a) 0
21 #endif /* CYRUS_SASL */
24 # define TLSminc(a) (a)
25 #else /* TLS_SUPPORT */
27 #endif /* TLS_SUPPORT */
29 #define WHOM_SWITCHES \
30 X("alias aliasfile", 0, ALIASW) \
31 X("check", 0, CHKSW) \
32 X("nocheck", 0, NOCHKSW) \
33 X("draft", 0, DRAFTSW) \
34 X("draftfolder +folder", 6, DFOLDSW) \
35 X("draftmessage msg", 6, DMSGSW) \
36 X("nodraftfolder", 0, NDFLDSW) \
37 X("version", 0, VERSIONSW) \
38 X("help", 0, HELPSW) \
39 X("client host", -6, CLIESW) \
40 X("server host", 0, SERVSW) \
41 X("snoop", 0, SNOOPSW) \
42 X("sasl", SASLminc(4), SASLSW) \
43 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
44 X("user username", SASLminc(-4), USERSW) \
45 X("port server port name/number", 4, PORTSW) \
46 X("tls", TLSminc(-3), TLSSW) \
47 X("initialtls", TLSminc(-10), INITTLSSW) \
48 X("notls", TLSminc(-5), NTLSSW) \
49 X("mts smtp|sendmail/smtp|sendmail/pipe", 0, MTSSW) \
51 #define X(sw, minchars, id) id,
52 DEFINE_SWITCH_ENUM(WHOM
);
55 #define X(sw, minchars, id) { sw, minchars, id },
56 DEFINE_SWITCH_ARRAY(WHOM
, switches
);
61 main (int argc
, char **argv
)
67 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
68 char *msg
= NULL
, **ap
, **argp
, backup
[BUFSIZ
];
69 char buf
[BUFSIZ
], **arguments
, *vec
[MAXARGS
];
71 if (nmh_init(argv
[0], true, false)) { return 1; }
73 arguments
= getarguments (invo_name
, argc
, argv
, 1);
76 vec
[vecp
++] = invo_name
;
77 vec
[vecp
++] = "-whom";
78 vec
[vecp
++] = "-library";
79 vec
[vecp
++] = mh_xstrdup(m_maildir(""));
81 if ((cp
= context_find ("credentials"))) {
82 /* post doesn't read context so need to pass credentials. */
83 vec
[vecp
++] = "-credentials";
87 /* Don't need to feed fileproc or mhlproc to post because
88 it doesn't use them when used for whom. */
90 while ((cp
= *argp
++)) {
92 switch (smatch (++cp
, switches
)) {
94 ambigsw (cp
, switches
);
97 die("-%s unknown", cp
);
100 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
101 print_help (buf
, switches
, 1);
104 print_version(invo_name
);
123 die("only one draft folder at a time!");
124 if (!(cp
= *argp
++) || *cp
== '-')
125 die("missing argument to %s", argp
[-2]);
126 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
127 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
131 die("only one draft message at a time!");
132 if (!(dmsg
= *argp
++) || *dmsg
== '-')
133 die("missing argument to %s", argp
[-2]);
148 if (!(cp
= *argp
++) || *cp
== '-')
149 die("missing argument to %s", argp
[-2]);
155 die("only one draft at a time!");
156 vec
[vecp
++] = msg
= cp
;
159 /* allow Aliasfile: profile entry */
160 if ((cp
= context_find ("Aliasfile"))) {
163 for (ap
= brkstring(dp
= mh_xstrdup(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
164 vec
[vecp
++] = "-alias";
170 cp
= mh_xstrdup(m_draft(dfolder
, dmsg
, 1, &isdf
));
171 msg
= vec
[vecp
++] = cp
;
174 distsw
= (cp
= getenv("mhdist")) && *cp
&& atoi(cp
) &&
175 (cp
= getenv("mhaltmsg")) && *cp
;
177 if (distout (msg
, cp
, backup
) == NOTOK
)
179 vec
[vecp
++] = "-dist";
186 if ((child_id
= fork()) == -1)
187 adios("fork", "failed:");
190 SIGNAL (SIGHUP
, SIG_IGN
);
191 SIGNAL (SIGINT
, SIG_IGN
);
192 SIGNAL (SIGQUIT
, SIG_IGN
);
193 SIGNAL (SIGTERM
, SIG_IGN
);
195 status
= pidwait(child_id
, OK
);
197 (void) m_unlink (msg
);
198 if (rename (backup
, msg
) == NOTOK
)
199 adios (msg
, "unable to rename %s to", backup
);
204 /* Either the child, or no fork occurred. */
205 execvp (postproc
, vec
);
206 fprintf (stderr
, "unable to exec ");