]>
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) },
128 static struct swit anyl
[] = {
138 extern int debugsw
; /* from sendsbr.c */
146 extern char *altmsg
; /* .. */
147 extern char *annotext
;
148 extern char *distfile
;
152 main (int argc
, char **argv
)
154 int msgp
= 0, distsw
= 0, vecp
= 1;
155 int isdf
= 0, mime
= 0;
157 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
158 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
;
159 char *msgs
[MAXARGS
], *vec
[MAXARGS
];
162 char *attach
= NMH_ATTACH_HEADER
; /* header field name for attachments */
163 int attachformat
= 1; /* mhbuild format specifier for attachments */
166 setlocale(LC_ALL
, "");
168 invo_name
= r1bindex (argv
[0], '/');
170 /* read user profile/context */
173 arguments
= getarguments (invo_name
, argc
, argv
, 1);
176 vec
[vecp
++] = "-library";
177 vec
[vecp
++] = getcpy (m_maildir (""));
179 if ((cp
= context_find ("fileproc"))) {
180 vec
[vecp
++] = "-fileproc";
184 if ((cp
= context_find ("mhlproc"))) {
185 vec
[vecp
++] = "-mhlproc";
189 while ((cp
= *argp
++)) {
191 switch (smatch (++cp
, switches
)) {
193 ambigsw (cp
, switches
);
196 adios (NULL
, "-%s unknown\n", cp
);
199 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
200 print_help (buf
, switches
, 1);
203 print_version(invo_name
);
207 msgs
[msgp
++] = draft
;
212 adios (NULL
, "only one draft folder at a time!");
213 if (!(cp
= *argp
++) || *cp
== '-')
214 adios (NULL
, "missing argument to %s", argp
[-2]);
215 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
216 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
219 if (!(cp
= *argp
++) || *cp
== '-')
220 adios (NULL
, "missing argument to %s", argp
[-2]);
236 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
237 adios (NULL
, "missing argument to %s", argp
[-2]);
273 debugsw
++; /* fall */
305 if (!(cp
= *argp
++) || *cp
== '-')
306 adios (NULL
, "missing argument to %s", argp
[-2]);
311 if (!(attach
= *argp
++) || *attach
== '-')
312 adios (NULL
, "missing argument to %s", argp
[-2]);
319 if (! *argp
|| **argp
== '-')
320 adios (NULL
, "missing argument to %s", argp
[-1]);
322 attachformat
= atoi (*argp
);
323 if (attachformat
< 0 ||
324 attachformat
> ATTACHFORMATS
- 1) {
325 advise (NULL
, "unsupported attachformat %d",
339 * check for "Aliasfile:" profile entry
341 if ((cp
= context_find ("Aliasfile"))) {
344 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
345 vec
[vecp
++] = "-alias";
350 if (dfolder
== NULL
) {
353 if ((cp
= getenv ("mhdraft")) && *cp
) {
358 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
359 if (stat (msgs
[0], &st
) == NOTOK
)
360 adios (msgs
[0], "unable to stat draft file");
361 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
362 for (status
= LISTDSW
; status
!= YESW
;) {
363 if (!(argp
= getans (cp
, anyl
)))
365 switch (status
= smatch (*argp
, anyl
)) {
371 showfile (++argp
, msgs
[0]);
374 advise (NULL
, "say what?");
379 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
380 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
383 if (!context_find ("path"))
384 free (path ("./", TFOLDER
));
387 msgs
[msgp
++] = "cur";
388 maildir
= m_maildir (dfolder
);
390 if (chdir (maildir
) == NOTOK
)
391 adios (maildir
, "unable to change directory to");
393 /* read folder and create message structure */
394 if (!(mp
= folder_read (dfolder
)))
395 adios (NULL
, "unable to read folder %s", dfolder
);
397 /* check for empty folder */
399 adios (NULL
, "no messages in %s", dfolder
);
401 /* parse all the message ranges/sequences and set SELECTED */
402 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
403 if (!m_convert (mp
, msgs
[msgnum
]))
405 seq_setprev (mp
); /* set the previous-sequence */
407 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
408 if (is_selected (mp
, msgnum
)) {
409 msgs
[msgp
++] = getcpy (m_name (msgnum
));
410 unset_exists (mp
, msgnum
);
414 mp
->msgflags
|= SEQMOD
;
422 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
423 if ((cp
= context_find ("signature")) && *cp
)
424 m_putenv ("SIGNATURE", cp
);
426 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
427 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
428 adios (msgs
[msgnum
], "unable to stat draft file");
430 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
432 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
434 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
435 altmsg
= NULL
; /* used by dist interface - see below */
437 if ((cp
= getenv ("mhdist"))
439 && (distsw
= atoi (cp
))
441 vec
[vecp
++] = "-dist";
442 distfile
= getcpy (m_mktemp2 (altmsg
, invo_name
, NULL
, NULL
));
444 if (link (altmsg
, distfile
) == NOTOK
) {
447 && errno
!= EISREMOTE
448 #endif /* EISREMOTE */
450 adios (distfile
, "unable to link %s to", altmsg
);
452 distfile
= getcpy (m_mktemp2(NULL
, invo_name
, NULL
, NULL
));
457 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
458 adios (altmsg
, "unable to open");
460 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
461 adios (distfile
, "unable to write");
462 cpydata (in
, out
, altmsg
, distfile
);
471 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
480 vec
[0] = r1bindex (postproc
, '/');
483 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
484 switch (sendsbr (vec
, vecp
, msgs
[msgnum
], &st
, 1, attach
,
495 context_save (); /* save the context file */