2 ** send.c -- send a composed message
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
15 static struct swit switches[] = {
17 { "alias aliasfile", 0 },
21 { "filter filterfile", 0 },
57 { "width columns", 0 },
63 { "dashstuffing", -12 },
64 #define NBITSTUFFSW 24
65 { "nodashstuffing", -14 },
75 { "client host", -6 },
82 #define ATTACHFORMATSW 33
83 { "attachformat", 7 },
85 { "port server-port-name/number" , 4 },
89 extern int debugsw; /* from sendsbr.c */
96 extern char *altmsg; /* .. */
97 extern char *annotext;
98 extern char *distfile;
102 main(int argc, char **argv)
104 int msgp = 0, distsw = 0, vecp = 1;
107 char *cp, *maildir = NULL;
108 char buf[BUFSIZ], **ap, **argp, **arguments;
109 char *msgs[MAXARGS], *vec[MAXARGS];
112 char *attach = NULL; /* header field name for attachments */
113 int attachformat = 0; /* mhbuild format specifier for attachments */
119 setlocale(LC_ALL, "");
121 invo_name = mhbasename(argv[0]);
123 /* read user profile/context */
126 arguments = getarguments(invo_name, argc, argv, 1);
129 vec[vecp++] = "-library";
130 vec[vecp++] = getcpy(toabsdir("+"));
132 while ((cp = *argp++)) {
134 switch (smatch(++cp, switches)) {
136 ambigsw(cp, switches);
139 adios(NULL, "-%s unknown\n", cp);
142 snprintf(buf, sizeof(buf),
143 "%s [file] [switches]",
145 print_help(buf, switches, 1);
148 print_version(invo_name);
191 debugsw++; /* fall */
216 if (!(cp = *argp++) || *cp == '-')
217 adios(NULL, "missing argument to %s",
223 if (!(attach = *argp++) || *attach == '-')
224 adios(NULL, "missing argument to %s",
229 if (! *argp || **argp == '-')
230 adios(NULL, "missing argument to %s",
233 attachformat = atoi(*argp);
234 if (attachformat < 0 || attachformat > ATTACHFORMATS - 1) {
235 advise(NULL, "unsupported attachformat %d", attachformat);
248 ** check for "Aliasfile:" profile entry
250 if ((cp = context_find("Aliasfile"))) {
253 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap;
255 vec[vecp++] = "-alias";
261 msgs[msgp++] = seq_cur;
262 maildir = toabsdir(draftfolder);
264 if (chdir(maildir) == NOTOK)
265 adios(maildir, "unable to change directory to");
267 /* read folder and create message structure */
268 if (!(mp = folder_read(draftfolder)))
269 adios(NULL, "unable to read draft folder %s", draftfolder);
271 /* check for empty folder */
273 adios(NULL, "no messages in draft folder %s", draftfolder);
275 /* parse all the message ranges/sequences and set SELECTED */
276 for (msgnum = 0; msgnum < msgp; msgnum++)
277 if (!m_convert(mp, msgs[msgnum]))
279 seq_setprev(mp); /* set the previous-sequence */
281 for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
282 if (is_selected(mp, msgnum)) {
283 msgs[msgp++] = getcpy(m_name(msgnum));
284 unset_exists(mp, msgnum);
288 mp->msgflags |= SEQMOD;
291 if ((cp = getenv("SIGNATURE")) == NULL || *cp == 0)
292 if ((cp = context_find("signature")) && *cp)
293 m_putenv("SIGNATURE", cp);
296 snprintf(buf, sizeof(buf), "%s/.signature", mypath);
297 if ((fp = fopen(buf, "r")) != NULL &&
298 fgets(buf, sizeof buf, fp) != NULL) {
300 if (cp = strchr(buf, '\n'))
302 m_putenv("SIGNATURE", buf);
307 for (msgnum = 0; msgnum < msgp; msgnum++)
308 if (stat(msgs[msgnum], &st) == NOTOK)
309 adios(msgs[msgnum], "unable to stat draft file");
311 if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
313 if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
315 if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
316 altmsg = NULL; /* used by dist interface - see below */
318 if ((cp = getenv("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) {
319 vec[vecp++] = "-dist";
320 distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
321 if (link(altmsg, distfile) == NOTOK) {
324 && errno != EISREMOTE
325 #endif /* EISREMOTE */
327 adios(distfile, "unable to link %s to",
330 distfile = getcpy(m_mktemp2(NULL, invo_name,
336 if ((in = open(altmsg, O_RDONLY)) == NOTOK)
337 adios(altmsg, "unable to open");
339 if ((out = creat(distfile,
340 (int) st.st_mode & 0777))
342 adios(distfile, "unable to write");
343 cpydata(in, out, altmsg, distfile);
352 if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
361 vec[0] = mhbasename(postproc);
364 for (msgnum = 0; msgnum < msgp; msgnum++) {
365 switch (sendsbr(vec, vecp, msgs[msgnum], &st, 1, attach,
376 context_save(); /* save the context file */