]>
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>
13 # define SASLminc(a) (a)
14 #else /* CYRUS_SASL */
15 # define SASLminc(a) 0
16 #endif /* CYRUS_SASL */
19 # define TLSminc(a) (a)
20 #else /* TLS_SUPPORT */
22 #endif /* TLS_SUPPORT */
24 #define WHOM_SWITCHES \
25 X("alias aliasfile", 0, ALIASW) \
26 X("check", 0, CHKSW) \
27 X("nocheck", 0, NOCHKSW) \
28 X("draft", 0, DRAFTSW) \
29 X("draftfolder +folder", 6, DFOLDSW) \
30 X("draftmessage msg", 6, DMSGSW) \
31 X("nodraftfolder", 0, NDFLDSW) \
32 X("version", 0, VERSIONSW) \
33 X("help", 0, HELPSW) \
34 X("client host", -6, CLIESW) \
35 X("server host", 0, SERVSW) \
36 X("snoop", 0, SNOOPSW) \
37 X("sasl", SASLminc(4), SASLSW) \
38 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
39 X("user username", SASLminc(-4), USERSW) \
40 X("port server port name/number", 4, PORTSW) \
41 X("tls", TLSminc(-3), TLSSW) \
42 X("initialtls", TLSminc(-10), INITTLSSW) \
43 X("notls", TLSminc(-5), NTLSSW) \
44 X("mts smtp|sendmail/smtp|sendmail/pipe", 0, MTSSW) \
46 #define X(sw, minchars, id) id,
47 DEFINE_SWITCH_ENUM(WHOM
);
50 #define X(sw, minchars, id) { sw, minchars, id },
51 DEFINE_SWITCH_ARRAY(WHOM
, switches
);
56 main (int argc
, char **argv
)
59 int i
, status
, isdf
= 0;
60 int distsw
= 0, vecp
= 0;
61 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
62 char *msg
= NULL
, **ap
, **argp
, backup
[BUFSIZ
];
63 char buf
[BUFSIZ
], **arguments
, *vec
[MAXARGS
];
65 if (nmh_init(argv
[0], 2)) { return 1; }
67 arguments
= getarguments (invo_name
, argc
, argv
, 1);
70 vec
[vecp
++] = invo_name
;
71 vec
[vecp
++] = "-whom";
72 vec
[vecp
++] = "-library";
73 vec
[vecp
++] = getcpy (m_maildir (""));
75 /* Don't need to feed fileproc or mhlproc to post because
76 it doesn't use them when used for whom. */
78 while ((cp
= *argp
++)) {
80 switch (smatch (++cp
, switches
)) {
82 ambigsw (cp
, switches
);
85 adios (NULL
, "-%s unknown", cp
);
88 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
89 print_help (buf
, switches
, 1);
92 print_version(invo_name
);
111 adios (NULL
, "only one draft folder at a time!");
112 if (!(cp
= *argp
++) || *cp
== '-')
113 adios (NULL
, "missing argument to %s", argp
[-2]);
114 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
115 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
119 adios (NULL
, "only one draft message at a time!");
120 if (!(dmsg
= *argp
++) || *dmsg
== '-')
121 adios (NULL
, "missing argument to %s", argp
[-2]);
136 if (!(cp
= *argp
++) || *cp
== '-')
137 adios (NULL
, "missing argument to %s", argp
[-2]);
143 adios (NULL
, "only one draft at a time!");
145 vec
[vecp
++] = msg
= cp
;
148 /* allow Aliasfile: profile entry */
149 if ((cp
= context_find ("Aliasfile"))) {
152 for (ap
= brkstring(dp
= mh_xstrdup(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
153 vec
[vecp
++] = "-alias";
159 cp
= getcpy (m_draft (dfolder
, dmsg
, 1, &isdf
));
160 msg
= vec
[vecp
++] = cp
;
162 if ((cp
= getenv ("mhdist"))
164 && (distsw
= atoi (cp
))
165 && (cp
= getenv ("mhaltmsg"))
167 if (distout (msg
, cp
, backup
) == NOTOK
)
169 vec
[vecp
++] = "-dist";
177 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
181 switch (distsw
? child_id
: OK
) {
183 inform("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 */