]>
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.
12 #include <h/signals.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
)
61 int i
, status
, isdf
= 0;
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 /* Don't need to feed fileproc or mhlproc to post because
78 it doesn't use them when used for whom. */
80 while ((cp
= *argp
++)) {
82 switch (smatch (++cp
, switches
)) {
84 ambigsw (cp
, switches
);
87 adios (NULL
, "-%s unknown", cp
);
90 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
91 print_help (buf
, switches
, 1);
94 print_version(invo_name
);
113 adios (NULL
, "only one draft folder at a time!");
114 if (!(cp
= *argp
++) || *cp
== '-')
115 adios (NULL
, "missing argument to %s", argp
[-2]);
116 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
117 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
121 adios (NULL
, "only one draft message at a time!");
122 if (!(dmsg
= *argp
++) || *dmsg
== '-')
123 adios (NULL
, "missing argument to %s", argp
[-2]);
138 if (!(cp
= *argp
++) || *cp
== '-')
139 adios (NULL
, "missing argument to %s", argp
[-2]);
145 adios (NULL
, "only one draft at a time!");
147 vec
[vecp
++] = msg
= cp
;
150 /* allow Aliasfile: profile entry */
151 if ((cp
= context_find ("Aliasfile"))) {
154 for (ap
= brkstring(dp
= mh_xstrdup(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
155 vec
[vecp
++] = "-alias";
161 cp
= getcpy (m_draft (dfolder
, dmsg
, 1, &isdf
));
162 msg
= vec
[vecp
++] = cp
;
164 if ((cp
= getenv ("mhdist"))
166 && (distsw
= atoi (cp
))
167 && (cp
= getenv ("mhaltmsg"))
169 if (distout (msg
, cp
, backup
) == NOTOK
)
171 vec
[vecp
++] = "-dist";
179 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
183 switch (distsw
? child_id
: OK
) {
185 advise (NULL
, "unable to fork, so checking directly...");
188 execvp (postproc
, vec
);
189 fprintf (stderr
, "unable to exec ");
194 SIGNAL (SIGHUP
, SIG_IGN
);
195 SIGNAL (SIGINT
, SIG_IGN
);
196 SIGNAL (SIGQUIT
, SIG_IGN
);
197 SIGNAL (SIGTERM
, SIG_IGN
);
199 status
= pidwait(child_id
, OK
);
201 (void) m_unlink (msg
);
202 if (rename (backup
, msg
) == NOTOK
)
203 adios (msg
, "unable to rename %s to", backup
);
207 return 0; /* dead code to satisfy the compiler */