]>
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.
17 # define SASLminc(a) (a)
18 #else /* CYRUS_SASL */
19 # define SASLminc(a) 0
20 #endif /* CYRUS_SASL */
23 # define TLSminc(a) (a)
24 #else /* TLS_SUPPORT */
26 #endif /* TLS_SUPPORT */
28 #define SEND_SWITCHES \
29 X("alias aliasfile", 0, ALIASW) \
30 X("debug", -5, DEBUGSW) \
31 X("draft", 0, DRAFTSW) \
32 X("draftfolder +folder", 6, DFOLDSW) \
33 X("draftmessage msg", 6, DMSGSW) \
34 X("nodraftfolder", 0, NDFLDSW) \
35 X("filter filterfile", 0, FILTSW) \
36 X("nofilter", 0, NFILTSW) \
37 X("format", 0, FRMTSW) \
38 X("noformat", 0, NFRMTSW) \
39 X("forward", 0, FORWSW) \
40 X("noforward", 0, NFORWSW) \
41 X("mime", 0, MIMESW) \
42 X("nomime", 0, NMIMESW) \
43 X("msgid", 0, MSGDSW) \
44 X("nomsgid", 0, NMSGDSW) \
45 X("push", 0, PUSHSW) \
46 X("nopush", 0, NPUSHSW) \
47 X("split seconds", 0, SPLITSW) \
48 X("unique", -6, UNIQSW) \
49 X("nounique", -8, NUNIQSW) \
50 X("verbose", 0, VERBSW) \
51 X("noverbose", 0, NVERBSW) \
52 X("watch", 0, WATCSW) \
53 X("nowatch", 0, NWATCSW) \
54 X("width columns", 0, WIDTHSW) \
55 X("version", 0, VERSIONSW) \
56 X("help", 0, HELPSW) \
57 X("dashstuffing", -12, BITSTUFFSW) \
58 X("nodashstuffing", -14, NBITSTUFFSW) \
59 X("mail", -4, MAILSW) \
60 X("saml", -4, SAMLSW) \
61 X("send", -4, SENDSW) \
62 X("soml", -4, SOMLSW) \
63 X("client host", -6, CLIESW) \
64 X("server host", 6, SERVSW) \
65 X("snoop", 5, SNOOPSW) \
66 X("sasl", SASLminc(4), SASLSW) \
67 X("nosasl", SASLminc(-6), NOSASLSW) \
68 X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
69 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
70 X("user username", SASLminc(-4), USERSW) \
71 X("attach", 6, ATTACHSW) \
72 X("noattach", 0, NOATTACHSW) \
73 X("attachformat", 7, ATTACHFORMATSW) \
74 X("port server-port-name/number", 4, PORTSW) \
75 X("tls", TLSminc(-3), TLSSW) \
76 X("notls", TLSminc(-5), NTLSSW) \
77 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
78 X("messageid localname|random", 2, MESSAGEIDSW) \
80 #define X(sw, minchars, id) id,
81 DEFINE_SWITCH_ENUM(SEND
);
84 #define X(sw, minchars, id) { sw, minchars, id },
85 DEFINE_SWITCH_ARRAY(SEND
, switches
);
88 #define USE_SWITCHES \
91 X("list", 0, LISTDSW) \
93 #define X(sw, minchars, id) id,
94 DEFINE_SWITCH_ENUM(USE
);
97 #define X(sw, minchars, id) { sw, minchars, id },
98 DEFINE_SWITCH_ARRAY(USE
, anyl
);
101 extern int debugsw
; /* from sendsbr.c */
109 extern char *altmsg
; /* .. */
110 extern char *annotext
;
111 extern char *distfile
;
115 main (int argc
, char **argv
)
117 int msgp
= 0, distsw
= 0, vecp
;
118 int isdf
= 0, mime
= 0;
120 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
121 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
, *program
;
122 char *msgs
[MAXARGS
], **vec
;
125 char *attach
= NMH_ATTACH_HEADER
; /* header field name for attachments */
126 int attachformat
= 1; /* mhbuild format specifier for attachments */
129 setlocale(LC_ALL
, "");
131 invo_name
= r1bindex (argv
[0], '/');
133 /* read user profile/context */
136 arguments
= getarguments (invo_name
, argc
, argv
, 1);
139 vec
= argsplit(postproc
, &program
, &vecp
);
141 vec
[vecp
++] = "-library";
142 vec
[vecp
++] = getcpy (m_maildir (""));
144 if ((cp
= context_find ("fileproc"))) {
145 vec
[vecp
++] = "-fileproc";
149 if ((cp
= context_find ("mhlproc"))) {
150 vec
[vecp
++] = "-mhlproc";
154 while ((cp
= *argp
++)) {
156 switch (smatch (++cp
, switches
)) {
158 ambigsw (cp
, switches
);
161 adios (NULL
, "-%s unknown\n", cp
);
164 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
165 print_help (buf
, switches
, 1);
168 print_version(invo_name
);
172 msgs
[msgp
++] = draft
;
177 adios (NULL
, "only one draft folder at a time!");
178 if (!(cp
= *argp
++) || *cp
== '-')
179 adios (NULL
, "missing argument to %s", argp
[-2]);
180 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
181 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
184 if (!(cp
= *argp
++) || *cp
== '-')
185 adios (NULL
, "missing argument to %s", argp
[-2]);
201 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
202 adios (NULL
, "missing argument to %s", argp
[-2]);
238 debugsw
++; /* fall */
272 if (!(cp
= *argp
++) || *cp
== '-')
273 adios (NULL
, "missing argument to %s", argp
[-2]);
278 if (!(attach
= *argp
++) || *attach
== '-')
279 adios (NULL
, "missing argument to %s", argp
[-2]);
286 if (! *argp
|| **argp
== '-')
287 adios (NULL
, "missing argument to %s", argp
[-1]);
289 attachformat
= atoi (*argp
);
290 if (attachformat
< 0 ||
291 attachformat
> ATTACHFORMATS
- 1) {
292 advise (NULL
, "unsupported attachformat %d",
306 * check for "Aliasfile:" profile entry
308 if ((cp
= context_find ("Aliasfile"))) {
311 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
312 vec
[vecp
++] = "-alias";
317 if (dfolder
== NULL
) {
320 if ((cp
= getenv ("mhdraft")) && *cp
) {
325 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
326 if (stat (msgs
[0], &st
) == NOTOK
)
327 adios (msgs
[0], "unable to stat draft file");
328 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
329 for (status
= LISTDSW
; status
!= YESW
;) {
330 if (!(argp
= getans (cp
, anyl
)))
332 switch (status
= smatch (*argp
, anyl
)) {
338 showfile (++argp
, msgs
[0]);
341 advise (NULL
, "say what?");
346 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
347 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
350 if (!context_find ("path"))
351 free (path ("./", TFOLDER
));
354 msgs
[msgp
++] = "cur";
355 maildir
= m_maildir (dfolder
);
357 if (chdir (maildir
) == NOTOK
)
358 adios (maildir
, "unable to change directory to");
360 /* read folder and create message structure */
361 if (!(mp
= folder_read (dfolder
)))
362 adios (NULL
, "unable to read folder %s", dfolder
);
364 /* check for empty folder */
366 adios (NULL
, "no messages in %s", dfolder
);
368 /* parse all the message ranges/sequences and set SELECTED */
369 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
370 if (!m_convert (mp
, msgs
[msgnum
]))
372 seq_setprev (mp
); /* set the previous-sequence */
374 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
375 if (is_selected (mp
, msgnum
)) {
376 msgs
[msgp
++] = getcpy (m_name (msgnum
));
377 unset_exists (mp
, msgnum
);
381 mp
->msgflags
|= SEQMOD
;
389 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
390 if ((cp
= context_find ("signature")) && *cp
)
391 m_putenv ("SIGNATURE", cp
);
393 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
394 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
395 adios (msgs
[msgnum
], "unable to stat draft file");
397 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
399 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
401 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
402 altmsg
= NULL
; /* used by dist interface - see below */
404 if ((cp
= getenv ("mhdist"))
406 && (distsw
= atoi (cp
))
408 vec
[vecp
++] = "-dist";
409 distfile
= getcpy (m_mktemp2 (altmsg
, invo_name
, NULL
, NULL
));
411 if (link (altmsg
, distfile
) == NOTOK
) {
412 /* Cygwin with FAT32 filesystem produces EPERM. */
413 if (errno
!= EXDEV
&& errno
!= EPERM
415 && errno
!= EISREMOTE
416 #endif /* EISREMOTE */
418 adios (distfile
, "unable to link %s to", altmsg
);
420 distfile
= getcpy (m_mktemp2(NULL
, invo_name
, NULL
, NULL
));
425 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
426 adios (altmsg
, "unable to open");
428 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
429 adios (distfile
, "unable to write");
430 cpydata (in
, out
, altmsg
, distfile
);
439 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
450 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
451 switch (sendsbr (vec
, vecp
, program
, msgs
[msgnum
], &st
, 1, attach
,
462 context_save (); /* save the context file */