]>
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 static struct swit switches
[] = {
30 { "alias aliasfile", 0 },
36 { "draftfolder +folder", 6 },
38 { "draftmessage msg", 6 },
40 { "nodraftfolder", 0 },
42 { "filter filterfile", 0 },
66 { "split seconds", 0 },
80 { "width columns", 0 },
86 { "dashstuffing", -12 },
87 #define NBITSTUFFSW 29
88 { "nodashstuffing", -14 },
98 { "client host", -6 },
100 { "server host", 6 },
104 { "sasl", SASLminc(4) },
106 { "nosasl", SASLminc(-6) },
107 #define SASLMXSSFSW 39
108 { "saslmaxssf", SASLminc(-10) },
109 #define SASLMECHSW 40
110 { "saslmech mechanism", SASLminc(-5) },
112 { "user username", SASLminc(-4) },
115 #define NOATTACHSW 43
117 #define ATTACHFORMATSW 44
118 { "attachformat", 7 },
120 { "port server-port-name/number" , 4 },
122 { "tls", TLSminc(-3) },
124 { "notls", TLSminc(-5) },
126 { "mts smtp|sendmail/smtp|sendmail/pipe", 2 },
127 #define MESSAGEIDSW 49
128 { "messageid localname|random", 2 },
132 static struct swit anyl
[] = {
142 extern int debugsw
; /* from sendsbr.c */
150 extern char *altmsg
; /* .. */
151 extern char *annotext
;
152 extern char *distfile
;
156 main (int argc
, char **argv
)
158 int msgp
= 0, distsw
= 0, vecp
= 1;
159 int isdf
= 0, mime
= 0;
161 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
162 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
;
163 char *msgs
[MAXARGS
], *vec
[MAXARGS
];
166 char *attach
= NMH_ATTACH_HEADER
; /* header field name for attachments */
167 int attachformat
= 1; /* mhbuild format specifier for attachments */
170 setlocale(LC_ALL
, "");
172 invo_name
= r1bindex (argv
[0], '/');
174 /* read user profile/context */
177 arguments
= getarguments (invo_name
, argc
, argv
, 1);
180 vec
[vecp
++] = "-library";
181 vec
[vecp
++] = getcpy (m_maildir (""));
183 if ((cp
= context_find ("fileproc"))) {
184 vec
[vecp
++] = "-fileproc";
188 if ((cp
= context_find ("mhlproc"))) {
189 vec
[vecp
++] = "-mhlproc";
193 while ((cp
= *argp
++)) {
195 switch (smatch (++cp
, switches
)) {
197 ambigsw (cp
, switches
);
200 adios (NULL
, "-%s unknown\n", cp
);
203 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
204 print_help (buf
, switches
, 1);
207 print_version(invo_name
);
211 msgs
[msgp
++] = draft
;
216 adios (NULL
, "only one draft folder at a time!");
217 if (!(cp
= *argp
++) || *cp
== '-')
218 adios (NULL
, "missing argument to %s", argp
[-2]);
219 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
220 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
223 if (!(cp
= *argp
++) || *cp
== '-')
224 adios (NULL
, "missing argument to %s", argp
[-2]);
240 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
241 adios (NULL
, "missing argument to %s", argp
[-2]);
277 debugsw
++; /* fall */
311 if (!(cp
= *argp
++) || *cp
== '-')
312 adios (NULL
, "missing argument to %s", argp
[-2]);
317 if (!(attach
= *argp
++) || *attach
== '-')
318 adios (NULL
, "missing argument to %s", argp
[-2]);
325 if (! *argp
|| **argp
== '-')
326 adios (NULL
, "missing argument to %s", argp
[-1]);
328 attachformat
= atoi (*argp
);
329 if (attachformat
< 0 ||
330 attachformat
> ATTACHFORMATS
- 1) {
331 advise (NULL
, "unsupported attachformat %d",
345 * check for "Aliasfile:" profile entry
347 if ((cp
= context_find ("Aliasfile"))) {
350 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
351 vec
[vecp
++] = "-alias";
356 if (dfolder
== NULL
) {
359 if ((cp
= getenv ("mhdraft")) && *cp
) {
364 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
365 if (stat (msgs
[0], &st
) == NOTOK
)
366 adios (msgs
[0], "unable to stat draft file");
367 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
368 for (status
= LISTDSW
; status
!= YESW
;) {
369 if (!(argp
= getans (cp
, anyl
)))
371 switch (status
= smatch (*argp
, anyl
)) {
377 showfile (++argp
, msgs
[0]);
380 advise (NULL
, "say what?");
385 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
386 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
389 if (!context_find ("path"))
390 free (path ("./", TFOLDER
));
393 msgs
[msgp
++] = "cur";
394 maildir
= m_maildir (dfolder
);
396 if (chdir (maildir
) == NOTOK
)
397 adios (maildir
, "unable to change directory to");
399 /* read folder and create message structure */
400 if (!(mp
= folder_read (dfolder
)))
401 adios (NULL
, "unable to read folder %s", dfolder
);
403 /* check for empty folder */
405 adios (NULL
, "no messages in %s", dfolder
);
407 /* parse all the message ranges/sequences and set SELECTED */
408 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
409 if (!m_convert (mp
, msgs
[msgnum
]))
411 seq_setprev (mp
); /* set the previous-sequence */
413 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
414 if (is_selected (mp
, msgnum
)) {
415 msgs
[msgp
++] = getcpy (m_name (msgnum
));
416 unset_exists (mp
, msgnum
);
420 mp
->msgflags
|= SEQMOD
;
428 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
429 if ((cp
= context_find ("signature")) && *cp
)
430 m_putenv ("SIGNATURE", cp
);
432 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
433 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
434 adios (msgs
[msgnum
], "unable to stat draft file");
436 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
438 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
440 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
441 altmsg
= NULL
; /* used by dist interface - see below */
443 if ((cp
= getenv ("mhdist"))
445 && (distsw
= atoi (cp
))
447 vec
[vecp
++] = "-dist";
448 distfile
= getcpy (m_mktemp2 (altmsg
, invo_name
, NULL
, NULL
));
450 if (link (altmsg
, distfile
) == NOTOK
) {
451 /* Cygwin with FAT32 filesystem produces EPERM. */
452 if (errno
!= EXDEV
&& errno
!= EPERM
454 && errno
!= EISREMOTE
455 #endif /* EISREMOTE */
457 adios (distfile
, "unable to link %s to", altmsg
);
459 distfile
= getcpy (m_mktemp2(NULL
, invo_name
, NULL
, NULL
));
464 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
465 adios (altmsg
, "unable to open");
467 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
468 adios (distfile
, "unable to write");
469 cpydata (in
, out
, altmsg
, distfile
);
478 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
487 vec
[0] = r1bindex (postproc
, '/');
490 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
491 switch (sendsbr (vec
, vecp
, msgs
[msgnum
], &st
, 1, attach
,
502 context_save (); /* save the context file */