]>
diplodocus.org Git - nmh/blob - uip/send.c
58a926d54fbb4ee8ef78edfa4edd5d3573bf7ad4
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.
16 # define SASLminc(a) (a)
17 #else /* CYRUS_SASL */
18 # define SASLminc(a) 0
19 #endif /* CYRUS_SASL */
22 # define TLSminc(a) (a)
23 #else /* TLS_SUPPORT */
25 #endif /* TLS_SUPPORT */
27 #define SEND_SWITCHES \
28 X("alias aliasfile", 0, ALIASW) \
29 X("debug", -5, DEBUGSW) \
30 X("draft", 0, DRAFTSW) \
31 X("draftfolder +folder", 6, DFOLDSW) \
32 X("draftmessage msg", 6, DMSGSW) \
33 X("nodraftfolder", 0, NDFLDSW) \
34 X("filter filterfile", 0, FILTSW) \
35 X("nofilter", 0, NFILTSW) \
36 X("format", 0, FRMTSW) \
37 X("noformat", 0, NFRMTSW) \
38 X("forward", 0, FORWSW) \
39 X("noforward", 0, NFORWSW) \
40 X("mime", 0, MIMESW) \
41 X("nomime", 0, NMIMESW) \
42 X("msgid", 0, MSGDSW) \
43 X("nomsgid", 0, NMSGDSW) \
44 X("push", 0, PUSHSW) \
45 X("nopush", 0, NPUSHSW) \
46 X("split seconds", 0, SPLITSW) \
47 X("unique", -6, UNIQSW) \
48 X("nounique", -8, NUNIQSW) \
49 X("verbose", 0, VERBSW) \
50 X("noverbose", 0, NVERBSW) \
51 X("watch", 0, WATCSW) \
52 X("nowatch", 0, NWATCSW) \
53 X("width columns", 0, WIDTHSW) \
54 X("version", 0, VERSIONSW) \
55 X("help", 0, HELPSW) \
56 X("dashstuffing", -12, BITSTUFFSW) \
57 X("nodashstuffing", -14, NBITSTUFFSW) \
58 X("client host", -6, CLIESW) \
59 X("server host", 6, SERVSW) \
60 X("snoop", 5, SNOOPSW) \
61 X("sasl", SASLminc(4), SASLSW) \
62 X("nosasl", SASLminc(-6), NOSASLSW) \
63 X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
64 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
65 X("user username", SASLminc(-4), USERSW) \
66 X("attach", 6, ATTACHSW) \
67 X("noattach", 0, NOATTACHSW) \
68 X("attachformat", 7, ATTACHFORMATSW) \
69 X("port server-port-name/number", 4, PORTSW) \
70 X("tls", TLSminc(-3), TLSSW) \
71 X("initialtls", TLSminc(-10), INITTLSSW) \
72 X("notls", TLSminc(-5), NTLSSW) \
73 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
74 X("messageid localname|random", 2, MESSAGEIDSW) \
76 #define X(sw, minchars, id) id,
77 DEFINE_SWITCH_ENUM(SEND
);
80 #define X(sw, minchars, id) { sw, minchars, id },
81 DEFINE_SWITCH_ARRAY(SEND
, switches
);
84 #define USE_SWITCHES \
87 X("list", 0, LISTDSW) \
89 #define X(sw, minchars, id) id,
90 DEFINE_SWITCH_ENUM(USE
);
93 #define X(sw, minchars, id) { sw, minchars, id },
94 DEFINE_SWITCH_ARRAY(USE
, anyl
);
97 extern int debugsw
; /* from sendsbr.c */
105 extern char *altmsg
; /* .. */
106 extern char *annotext
;
107 extern char *distfile
;
111 main (int argc
, char **argv
)
113 int msgp
= 0, distsw
= 0, vecp
;
114 int isdf
= 0, mime
= 0;
116 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
117 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
, *program
;
118 char *msgs
[MAXARGS
], **vec
;
121 char *attach
= NMH_ATTACH_HEADER
; /* header field name for attachments */
122 int attachformat
= 1; /* mhbuild format specifier for attachments */
125 setlocale(LC_ALL
, "");
127 invo_name
= r1bindex (argv
[0], '/');
129 /* read user profile/context */
132 arguments
= getarguments (invo_name
, argc
, argv
, 1);
135 vec
= argsplit(postproc
, &program
, &vecp
);
137 vec
[vecp
++] = "-library";
138 vec
[vecp
++] = getcpy (m_maildir (""));
140 if ((cp
= context_find ("fileproc"))) {
141 vec
[vecp
++] = "-fileproc";
145 if ((cp
= context_find ("mhlproc"))) {
146 vec
[vecp
++] = "-mhlproc";
150 while ((cp
= *argp
++)) {
152 switch (smatch (++cp
, switches
)) {
154 ambigsw (cp
, switches
);
157 adios (NULL
, "-%s unknown\n", cp
);
160 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
161 print_help (buf
, switches
, 1);
164 print_version(invo_name
);
168 msgs
[msgp
++] = draft
;
173 adios (NULL
, "only one draft folder at a time!");
174 if (!(cp
= *argp
++) || *cp
== '-')
175 adios (NULL
, "missing argument to %s", argp
[-2]);
176 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
177 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
180 if (!(cp
= *argp
++) || *cp
== '-')
181 adios (NULL
, "missing argument to %s", argp
[-2]);
197 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
198 adios (NULL
, "missing argument to %s", argp
[-2]);
234 debugsw
++; /* fall */
265 if (!(cp
= *argp
++) || *cp
== '-')
266 adios (NULL
, "missing argument to %s", argp
[-2]);
271 if (!(attach
= *argp
++) || *attach
== '-')
272 adios (NULL
, "missing argument to %s", argp
[-2]);
279 if (! *argp
|| **argp
== '-')
280 adios (NULL
, "missing argument to %s", argp
[-1]);
282 attachformat
= atoi (*argp
);
283 if (attachformat
< 0 ||
284 attachformat
> ATTACHFORMATS
- 1) {
285 advise (NULL
, "unsupported attachformat %d",
299 * check for "Aliasfile:" profile entry
301 if ((cp
= context_find ("Aliasfile"))) {
304 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
305 vec
[vecp
++] = "-alias";
310 if (dfolder
== NULL
) {
313 if ((cp
= getenv ("mhdraft")) && *cp
) {
318 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
319 if (stat (msgs
[0], &st
) == NOTOK
)
320 adios (msgs
[0], "unable to stat draft file");
321 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
322 for (status
= LISTDSW
; status
!= YESW
;) {
323 if (!(argp
= getans (cp
, anyl
)))
325 switch (status
= smatch (*argp
, anyl
)) {
331 showfile (++argp
, msgs
[0]);
334 advise (NULL
, "say what?");
339 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
340 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
343 if (!context_find ("path"))
344 free (path ("./", TFOLDER
));
347 msgs
[msgp
++] = "cur";
348 maildir
= m_maildir (dfolder
);
350 if (chdir (maildir
) == NOTOK
)
351 adios (maildir
, "unable to change directory to");
353 /* read folder and create message structure */
354 if (!(mp
= folder_read (dfolder
, 1)))
355 adios (NULL
, "unable to read folder %s", dfolder
);
357 /* check for empty folder */
359 adios (NULL
, "no messages in %s", dfolder
);
361 /* parse all the message ranges/sequences and set SELECTED */
362 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
363 if (!m_convert (mp
, msgs
[msgnum
]))
365 seq_setprev (mp
); /* set the previous-sequence */
367 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
368 if (is_selected (mp
, msgnum
)) {
369 msgs
[msgp
++] = getcpy (m_name (msgnum
));
370 unset_exists (mp
, msgnum
);
374 mp
->msgflags
|= SEQMOD
;
382 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
383 if ((cp
= context_find ("signature")) && *cp
)
384 m_putenv ("SIGNATURE", cp
);
386 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
387 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
388 adios (msgs
[msgnum
], "unable to stat draft file");
390 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
392 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
394 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
395 altmsg
= NULL
; /* used by dist interface - see below */
397 if ((cp
= getenv ("mhdist"))
399 && (distsw
= atoi (cp
))
401 vec
[vecp
++] = "-dist";
402 distfile
= getcpy (m_mktemp2 (altmsg
, invo_name
, NULL
, NULL
));
404 if (link (altmsg
, distfile
) == NOTOK
) {
405 /* Cygwin with FAT32 filesystem produces EPERM. */
406 if (errno
!= EXDEV
&& errno
!= EPERM
408 && errno
!= EISREMOTE
409 #endif /* EISREMOTE */
411 adios (distfile
, "unable to link %s to", altmsg
);
413 distfile
= getcpy (m_mktemp2(NULL
, invo_name
, NULL
, NULL
));
418 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
419 adios (altmsg
, "unable to open");
421 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
422 adios (distfile
, "unable to write");
423 cpydata (in
, out
, altmsg
, distfile
);
432 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
443 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
444 switch (sendsbr (vec
, vecp
, program
, msgs
[msgnum
], &st
, 1, attach
,
455 context_save (); /* save the context file */