]>
diplodocus.org Git - nmh/blob - uip/send.c
3 * send.c -- send a composed message
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.
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 SEND_SWITCHES \
27 X("alias aliasfile", 0, ALIASW) \
28 X("debug", -5, DEBUGSW) \
29 X("draft", 0, DRAFTSW) \
30 X("draftfolder +folder", 6, DFOLDSW) \
31 X("draftmessage msg", 6, DMSGSW) \
32 X("nodraftfolder", 0, NDFLDSW) \
33 X("filter filterfile", 0, FILTSW) \
34 X("nofilter", 0, NFILTSW) \
35 X("format", 0, FRMTSW) \
36 X("noformat", 0, NFRMTSW) \
37 X("forward", 0, FORWSW) \
38 X("noforward", 0, NFORWSW) \
39 X("mime", 0, MIMESW) \
40 X("nomime", 0, NMIMESW) \
41 X("msgid", 0, MSGDSW) \
42 X("nomsgid", 0, NMSGDSW) \
43 X("push", 0, PUSHSW) \
44 X("nopush", 0, NPUSHSW) \
45 X("split seconds", 0, SPLITSW) \
46 X("unique", -6, UNIQSW) \
47 X("nounique", -8, NUNIQSW) \
48 X("verbose", 0, VERBSW) \
49 X("noverbose", 0, NVERBSW) \
50 X("watch", 0, WATCSW) \
51 X("nowatch", 0, NWATCSW) \
52 X("width columns", 0, WIDTHSW) \
53 X("version", 0, VERSIONSW) \
54 X("help", 0, HELPSW) \
55 X("dashstuffing", -12, BITSTUFFSW) \
56 X("nodashstuffing", -14, NBITSTUFFSW) \
57 X("client host", -6, CLIESW) \
58 X("server host", 6, SERVSW) \
59 X("snoop", 5, SNOOPSW) \
60 X("sasl", SASLminc(4), SASLSW) \
61 X("nosasl", SASLminc(-6), NOSASLSW) \
62 X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
63 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
64 X("user username", SASLminc(-4), USERSW) \
65 X("attach", 6, ATTACHSW) \
66 X("noattach", 0, NOATTACHSW) \
67 X("attachformat", 7, ATTACHFORMATSW) \
68 X("port server-port-name/number", 4, PORTSW) \
69 X("tls", TLSminc(-3), TLSSW) \
70 X("initialtls", TLSminc(-10), INITTLSSW) \
71 X("notls", TLSminc(-5), NTLSSW) \
72 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
73 X("messageid localname|random", 2, MESSAGEIDSW) \
75 #define X(sw, minchars, id) id,
76 DEFINE_SWITCH_ENUM(SEND
);
79 #define X(sw, minchars, id) { sw, minchars, id },
80 DEFINE_SWITCH_ARRAY(SEND
, switches
);
83 #define USE_SWITCHES \
86 X("list", 0, LISTDSW) \
88 #define X(sw, minchars, id) id,
89 DEFINE_SWITCH_ENUM(USE
);
92 #define X(sw, minchars, id) { sw, minchars, id },
93 DEFINE_SWITCH_ARRAY(USE
, anyl
);
96 extern int debugsw
; /* from sendsbr.c */
104 extern char *altmsg
; /* .. */
105 extern char *annotext
;
106 extern char *distfile
;
110 main (int argc
, char **argv
)
112 int msgp
= 0, distsw
= 0, vecp
;
113 int isdf
= 0, mime
= 0;
115 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
116 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
, *program
;
117 char *msgs
[MAXARGS
], **vec
;
122 setlocale(LC_ALL
, "");
124 invo_name
= r1bindex (argv
[0], '/');
126 /* read user profile/context */
129 arguments
= getarguments (invo_name
, argc
, argv
, 1);
132 vec
= argsplit(postproc
, &program
, &vecp
);
134 vec
[vecp
++] = "-library";
135 vec
[vecp
++] = getcpy (m_maildir (""));
137 if ((cp
= context_find ("fileproc"))) {
138 vec
[vecp
++] = "-fileproc";
142 if ((cp
= context_find ("mhlproc"))) {
143 vec
[vecp
++] = "-mhlproc";
147 if ((cp
= context_find ("credentials"))) {
148 /* post doesn't read context so need to pass credentials. */
149 vec
[vecp
++] = "-credentials";
153 while ((cp
= *argp
++)) {
155 switch (smatch (++cp
, switches
)) {
157 ambigsw (cp
, switches
);
160 adios (NULL
, "-%s unknown\n", cp
);
163 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
164 print_help (buf
, switches
, 1);
167 print_version(invo_name
);
171 msgs
[msgp
++] = draft
;
176 adios (NULL
, "only one draft folder at a time!");
177 if (!(cp
= *argp
++) || *cp
== '-')
178 adios (NULL
, "missing argument to %s", argp
[-2]);
179 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
180 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
183 if (!(cp
= *argp
++) || *cp
== '-')
184 adios (NULL
, "missing argument to %s", argp
[-2]);
200 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
201 adios (NULL
, "missing argument to %s", argp
[-2]);
237 debugsw
++; /* fall */
268 if (!(cp
= *argp
++) || *cp
== '-')
269 adios (NULL
, "missing argument to %s", argp
[-2]);
274 advise(NULL
, "The -attach switch is deprecated");
277 advise(NULL
, "The -noattach switch is deprecated");
281 advise(NULL
, "The -attachformat switch is deprecated");
290 * check for "Aliasfile:" profile entry
292 if ((cp
= context_find ("Aliasfile"))) {
295 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
296 vec
[vecp
++] = "-alias";
301 if (dfolder
== NULL
) {
303 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
304 if (stat (msgs
[0], &st
) == NOTOK
)
305 adios (msgs
[0], "unable to stat draft file");
306 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
307 for (status
= LISTDSW
; status
!= YESW
;) {
308 if (!(argp
= getans (cp
, anyl
)))
310 switch (status
= smatch (*argp
, anyl
)) {
316 showfile (++argp
, msgs
[0]);
319 advise (NULL
, "say what?");
324 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
325 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
328 if (!context_find ("path"))
329 free (path ("./", TFOLDER
));
332 msgs
[msgp
++] = "cur";
333 maildir
= m_maildir (dfolder
);
335 if (chdir (maildir
) == NOTOK
)
336 adios (maildir
, "unable to change directory to");
338 /* read folder and create message structure */
339 if (!(mp
= folder_read (dfolder
, 1)))
340 adios (NULL
, "unable to read folder %s", dfolder
);
342 /* check for empty folder */
344 adios (NULL
, "no messages in %s", dfolder
);
346 /* parse all the message ranges/sequences and set SELECTED */
347 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
348 if (!m_convert (mp
, msgs
[msgnum
]))
350 seq_setprev (mp
); /* set the previous-sequence */
352 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
353 if (is_selected (mp
, msgnum
)) {
354 msgs
[msgp
++] = getcpy (m_name (msgnum
));
355 unset_exists (mp
, msgnum
);
359 mp
->msgflags
|= SEQMOD
;
367 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
368 if ((cp
= context_find ("signature")) && *cp
)
369 m_putenv ("SIGNATURE", cp
);
371 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
372 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
373 adios (msgs
[msgnum
], "unable to stat draft file");
375 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
377 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
379 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
380 altmsg
= NULL
; /* used by dist interface - see below */
382 if ((cp
= getenv ("mhdist"))
384 && (distsw
= atoi (cp
))
386 vec
[vecp
++] = "-dist";
387 distfile
= getcpy (m_mktemp2 (altmsg
, invo_name
, NULL
, NULL
));
389 if (link (altmsg
, distfile
) == NOTOK
) {
390 /* Cygwin with FAT32 filesystem produces EPERM. */
391 if (errno
!= EXDEV
&& errno
!= EPERM
393 && errno
!= EISREMOTE
394 #endif /* EISREMOTE */
396 adios (distfile
, "unable to link %s to", altmsg
);
398 distfile
= getcpy (m_mktemp2(NULL
, invo_name
, NULL
, NULL
));
403 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
404 adios (altmsg
, "unable to open");
406 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
407 adios (distfile
, "unable to write");
408 cpydata (in
, out
, altmsg
, distfile
);
417 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
428 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
429 switch (sendsbr (vec
, vecp
, program
, msgs
[msgnum
], &st
, 1)) {
439 context_save (); /* save the context file */