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 },
81 { "port server-port-name/number" , 4 },
85 extern int debugsw; /* from sendsbr.c */
92 extern char *altmsg; /* .. */
93 extern char *annotext;
94 extern char *distfile;
98 main(int argc, char **argv)
100 int msgp = 0, distsw = 0, vecp = 1;
103 char *cp, *maildir = NULL;
104 char buf[BUFSIZ], **ap, **argp, **arguments;
105 char *msgs[MAXARGS], *vec[MAXARGS];
113 setlocale(LC_ALL, "");
115 invo_name = mhbasename(argv[0]);
117 /* read user profile/context */
120 arguments = getarguments(invo_name, argc, argv, 1);
123 vec[vecp++] = "-library";
124 vec[vecp++] = getcpy(toabsdir("+"));
126 while ((cp = *argp++)) {
128 switch (smatch(++cp, switches)) {
130 ambigsw(cp, switches);
133 adios(NULL, "-%s unknown\n", cp);
136 snprintf(buf, sizeof(buf),
137 "%s [file] [switches]",
139 print_help(buf, switches, 1);
142 print_version(invo_name);
185 debugsw++; /* fall */
210 if (!(cp = *argp++) || *cp == '-')
211 adios(NULL, "missing argument to %s",
223 ** check for "Aliasfile:" profile entry
225 if ((cp = context_find("Aliasfile"))) {
228 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap;
230 vec[vecp++] = "-alias";
236 msgs[msgp++] = seq_cur;
237 maildir = toabsdir(draftfolder);
239 if (chdir(maildir) == NOTOK)
240 adios(maildir, "unable to change directory to");
242 /* read folder and create message structure */
243 if (!(mp = folder_read(draftfolder)))
244 adios(NULL, "unable to read draft folder %s", draftfolder);
246 /* check for empty folder */
248 adios(NULL, "no messages in draft folder %s", draftfolder);
250 /* parse all the message ranges/sequences and set SELECTED */
251 for (msgnum = 0; msgnum < msgp; msgnum++)
252 if (!m_convert(mp, msgs[msgnum]))
254 seq_setprev(mp); /* set the previous-sequence */
256 for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
257 if (is_selected(mp, msgnum)) {
258 msgs[msgp++] = getcpy(m_name(msgnum));
259 unset_exists(mp, msgnum);
263 mp->msgflags |= SEQMOD;
266 if ((cp = getenv("SIGNATURE")) == NULL || *cp == 0)
267 if ((cp = context_find("signature")) && *cp)
268 m_putenv("SIGNATURE", cp);
271 snprintf(buf, sizeof(buf), "%s/.signature", mypath);
272 if ((fp = fopen(buf, "r")) != NULL &&
273 fgets(buf, sizeof buf, fp) != NULL) {
275 if (cp = strchr(buf, '\n'))
277 m_putenv("SIGNATURE", buf);
282 for (msgnum = 0; msgnum < msgp; msgnum++)
283 if (stat(msgs[msgnum], &st) == NOTOK)
284 adios(msgs[msgnum], "unable to stat draft file");
286 if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
288 if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
290 if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
291 altmsg = NULL; /* used by dist interface - see below */
293 if ((cp = getenv("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) {
294 vec[vecp++] = "-dist";
295 distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
296 if (link(altmsg, distfile) == NOTOK) {
299 && errno != EISREMOTE
300 #endif /* EISREMOTE */
302 adios(distfile, "unable to link %s to",
305 distfile = getcpy(m_mktemp2(NULL, invo_name,
311 if ((in = open(altmsg, O_RDONLY)) == NOTOK)
312 adios(altmsg, "unable to open");
314 if ((out = creat(distfile,
315 (int) st.st_mode & 0777))
317 adios(distfile, "unable to write");
318 cpydata(in, out, altmsg, distfile);
327 if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
336 vec[0] = mhbasename(postproc);
339 for (msgnum = 0; msgnum < msgp; msgnum++) {
340 switch (sendsbr(vec, vecp, msgs[msgnum], &st, 1)) {
350 context_save(); /* save the context file */