]>
diplodocus.org Git - nmh/blob - uip/send.c
7eb75bdf5903f559f1202098866cda4e5d12d9f5
3 * send.c -- send a composed message
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
19 # define SASLminc(a) (a)
20 #else /* CYRUS_SASL */
21 # define SASLminc(a) 0
22 #endif /* CYRUS_SASL */
25 # define TLSminc(a) (a)
26 #else /* TLS_SUPPORT */
28 #endif /* TLS_SUPPORT */
30 static struct swit switches
[] = {
32 { "alias aliasfile", 0 },
38 { "draftfolder +folder", 6 },
40 { "draftmessage msg", 6 },
42 { "nodraftfolder", 0 },
44 { "filter filterfile", 0 },
68 { "split seconds", 0 },
82 { "width columns", 0 },
88 { "dashstuffing", -12 },
89 #define NBITSTUFFSW 29
90 { "nodashstuffing", -14 },
100 { "client host", -6 },
102 { "server host", 6 },
106 { "sasl", SASLminc(4) },
107 #define SASLMECHSW 38
108 { "saslmech mechanism", SASLminc(-5) },
110 { "user username", SASLminc(-4) },
113 #define ATTACHFORMATSW 41
114 { "attachformat", 7 },
116 { "port server-port-name/number" , 4 },
118 { "tls", TLSminc(-3) },
122 static struct swit anyl
[] = {
132 extern int debugsw
; /* from sendsbr.c */
140 extern char *altmsg
; /* .. */
141 extern char *annotext
;
142 extern char *distfile
;
146 main (int argc
, char **argv
)
148 int msgp
= 0, distsw
= 0, vecp
= 1;
149 int isdf
= 0, mime
= 0;
151 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
152 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
;
153 char *msgs
[MAXARGS
], *vec
[MAXARGS
];
156 char *attach
= (char *)0; /* header field name for attachments */
157 int attachformat
= 0; /* mhbuild format specifier for attachments */
163 setlocale(LC_ALL
, "");
165 invo_name
= r1bindex (argv
[0], '/');
167 /* read user profile/context */
170 arguments
= getarguments (invo_name
, argc
, argv
, 1);
173 vec
[vecp
++] = "-library";
174 vec
[vecp
++] = getcpy (m_maildir (""));
176 while ((cp
= *argp
++)) {
178 switch (smatch (++cp
, switches
)) {
180 ambigsw (cp
, switches
);
183 adios (NULL
, "-%s unknown\n", cp
);
186 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
187 print_help (buf
, switches
, 1);
190 print_version(invo_name
);
194 msgs
[msgp
++] = draft
;
199 adios (NULL
, "only one draft folder at a time!");
200 if (!(cp
= *argp
++) || *cp
== '-')
201 adios (NULL
, "missing argument to %s", argp
[-2]);
202 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
203 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
206 if (!(cp
= *argp
++) || *cp
== '-')
207 adios (NULL
, "missing argument to %s", argp
[-2]);
223 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
224 adios (NULL
, "missing argument to %s", argp
[-2]);
260 debugsw
++; /* fall */
289 if (!(cp
= *argp
++) || *cp
== '-')
290 adios (NULL
, "missing argument to %s", argp
[-2]);
295 if (!(attach
= *argp
++) || *attach
== '-')
296 adios (NULL
, "missing argument to %s", argp
[-2]);
300 if (! *argp
|| **argp
== '-')
301 adios (NULL
, "missing argument to %s", argp
[-1]);
303 attachformat
= atoi (*argp
);
304 if (attachformat
< 0 ||
305 attachformat
> ATTACHFORMATS
- 1) {
306 advise (NULL
, "unsupported attachformat %d",
320 * check for "Aliasfile:" profile entry
322 if ((cp
= context_find ("Aliasfile"))) {
325 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
326 vec
[vecp
++] = "-alias";
331 if (dfolder
== NULL
) {
334 if ((cp
= getenv ("mhdraft")) && *cp
) {
339 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
340 if (stat (msgs
[0], &st
) == NOTOK
)
341 adios (msgs
[0], "unable to stat draft file");
342 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
343 for (status
= LISTDSW
; status
!= YESW
;) {
344 if (!(argp
= getans (cp
, anyl
)))
346 switch (status
= smatch (*argp
, anyl
)) {
352 showfile (++argp
, msgs
[0]);
355 advise (NULL
, "say what?");
360 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
361 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
364 if (!context_find ("path"))
365 free (path ("./", TFOLDER
));
368 msgs
[msgp
++] = "cur";
369 maildir
= m_maildir (dfolder
);
371 if (chdir (maildir
) == NOTOK
)
372 adios (maildir
, "unable to change directory to");
374 /* read folder and create message structure */
375 if (!(mp
= folder_read (dfolder
)))
376 adios (NULL
, "unable to read folder %s", dfolder
);
378 /* check for empty folder */
380 adios (NULL
, "no messages in %s", dfolder
);
382 /* parse all the message ranges/sequences and set SELECTED */
383 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
384 if (!m_convert (mp
, msgs
[msgnum
]))
386 seq_setprev (mp
); /* set the previous-sequence */
388 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
389 if (is_selected (mp
, msgnum
)) {
390 msgs
[msgp
++] = getcpy (m_name (msgnum
));
391 unset_exists (mp
, msgnum
);
395 mp
->msgflags
|= SEQMOD
;
403 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
404 if ((cp
= context_find ("signature")) && *cp
)
405 m_putenv ("SIGNATURE", cp
);
408 snprintf (buf
, sizeof(buf
), "%s/.signature", mypath
);
409 if ((fp
= fopen (buf
, "r")) != NULL
410 && fgets (buf
, sizeof buf
, fp
) != NULL
) {
412 if (cp
= strchr (buf
, '\n'))
414 m_putenv ("SIGNATURE", buf
);
419 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
420 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
421 adios (msgs
[msgnum
], "unable to stat draft file");
423 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
425 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
427 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
428 altmsg
= NULL
; /* used by dist interface - see below */
430 if ((cp
= getenv ("mhdist"))
432 && (distsw
= atoi (cp
))
434 vec
[vecp
++] = "-dist";
435 distfile
= getcpy (m_mktemp2 (altmsg
, invo_name
, NULL
, NULL
));
436 if (link (altmsg
, distfile
) == NOTOK
) {
439 && errno
!= EISREMOTE
440 #endif /* EISREMOTE */
442 adios (distfile
, "unable to link %s to", altmsg
);
444 distfile
= getcpy (m_mktemp2(NULL
, invo_name
, NULL
, NULL
));
449 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
450 adios (altmsg
, "unable to open");
452 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
453 adios (distfile
, "unable to write");
454 cpydata (in
, out
, altmsg
, distfile
);
463 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
472 vec
[0] = r1bindex (postproc
, '/');
475 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
476 switch (sendsbr (vec
, vecp
, msgs
[msgnum
], &st
, 1, attach
,
487 context_save (); /* save the context file */