]>
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>
14 # define SASLminc(a) (a)
15 #else /* CYRUS_SASL */
16 # define SASLminc(a) 0
17 #endif /* CYRUS_SASL */
20 # define TLSminc(a) (a)
21 #else /* TLS_SUPPORT */
23 #endif /* TLS_SUPPORT */
25 #define WHOM_SWITCHES \
26 X("alias aliasfile", 0, ALIASW) \
27 X("check", 0, CHKSW) \
28 X("nocheck", 0, NOCHKSW) \
29 X("draft", 0, DRAFTSW) \
30 X("draftfolder +folder", 6, DFOLDSW) \
31 X("draftmessage msg", 6, DMSGSW) \
32 X("nodraftfolder", 0, NDFLDSW) \
33 X("version", 0, VERSIONSW) \
34 X("help", 0, HELPSW) \
35 X("client host", -6, CLIESW) \
36 X("server host", -6, SERVSW) \
37 X("snoop", -5, SNOOPSW) \
38 X("sasl", SASLminc(4), SASLSW) \
39 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
40 X("user username", SASLminc(-4), USERSW) \
41 X("port server port name/number", 4, PORTSW) \
42 X("tls", TLSminc(-3), TLSSW) \
43 X("initialtls", TLSminc(-10), INITTLSSW) \
44 X("notls", TLSminc(-5), NTLSSW) \
45 X("mts smtp|sendmail/smtp|sendmail/pipe", 0, MTSSW) \
47 #define X(sw, minchars, id) id,
48 DEFINE_SWITCH_ENUM(WHOM
);
51 #define X(sw, minchars, id) { sw, minchars, id },
52 DEFINE_SWITCH_ARRAY(WHOM
, switches
);
57 main (int argc
, char **argv
)
60 int i
, status
, isdf
= 0;
61 int distsw
= 0, vecp
= 0;
62 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
63 char *msg
= NULL
, **ap
, **argp
, backup
[BUFSIZ
];
64 char buf
[BUFSIZ
], **arguments
, *vec
[MAXARGS
];
66 if (nmh_init(argv
[0], 1)) { return 1; }
68 arguments
= getarguments (invo_name
, argc
, argv
, 1);
71 vec
[vecp
++] = invo_name
;
72 vec
[vecp
++] = "-whom";
73 vec
[vecp
++] = "-library";
74 vec
[vecp
++] = getcpy (m_maildir (""));
76 /* Don't need to feed fileproc or mhlproc to post because
77 it doesn't use them when used for whom. */
79 while ((cp
= *argp
++)) {
81 switch (smatch (++cp
, switches
)) {
83 ambigsw (cp
, switches
);
86 adios (NULL
, "-%s unknown", cp
);
89 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
90 print_help (buf
, switches
, 1);
93 print_version(invo_name
);
112 adios (NULL
, "only one draft folder at a time!");
113 if (!(cp
= *argp
++) || *cp
== '-')
114 adios (NULL
, "missing argument to %s", argp
[-2]);
115 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
116 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
120 adios (NULL
, "only one draft message at a time!");
121 if (!(dmsg
= *argp
++) || *dmsg
== '-')
122 adios (NULL
, "missing argument to %s", argp
[-2]);
137 if (!(cp
= *argp
++) || *cp
== '-')
138 adios (NULL
, "missing argument to %s", argp
[-2]);
144 adios (NULL
, "only one draft at a time!");
146 vec
[vecp
++] = msg
= cp
;
149 /* allow Aliasfile: profile entry */
150 if ((cp
= context_find ("Aliasfile"))) {
153 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
154 vec
[vecp
++] = "-alias";
160 cp
= getcpy (m_draft (dfolder
, dmsg
, 1, &isdf
));
161 msg
= vec
[vecp
++] = cp
;
163 if ((cp
= getenv ("mhdist"))
165 && (distsw
= atoi (cp
))
166 && (cp
= getenv ("mhaltmsg"))
168 if (distout (msg
, cp
, backup
) == NOTOK
)
170 vec
[vecp
++] = "-dist";
178 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
182 switch (distsw
? child_id
: OK
) {
184 advise (NULL
, "unable to fork, so checking directly...");
186 execvp (postproc
, vec
);
187 fprintf (stderr
, "unable to exec ");
192 SIGNAL (SIGHUP
, SIG_IGN
);
193 SIGNAL (SIGINT
, SIG_IGN
);
194 SIGNAL (SIGQUIT
, SIG_IGN
);
195 SIGNAL (SIGTERM
, SIG_IGN
);
197 status
= pidwait(child_id
, OK
);
199 (void) m_unlink (msg
);
200 if (rename (backup
, msg
) == NOTOK
)
201 adios (msg
, "unable to rename %s to", backup
);
205 return 0; /* dead code to satisfy the compiler */