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];
110 setlocale(LC_ALL, "");
112 invo_name = mhbasename(argv[0]);
114 /* read user profile/context */
117 arguments = getarguments(invo_name, argc, argv, 1);
120 vec[vecp++] = "-library";
121 vec[vecp++] = getcpy(toabsdir("+"));
123 while ((cp = *argp++)) {
125 switch (smatch(++cp, switches)) {
127 ambigsw(cp, switches);
130 adios(NULL, "-%s unknown\n", cp);
133 snprintf(buf, sizeof(buf),
134 "%s [file] [switches]",
136 print_help(buf, switches, 1);
139 print_version(invo_name);
182 debugsw++; /* fall */
207 if (!(cp = *argp++) || *cp == '-')
208 adios(NULL, "missing argument to %s",
220 ** check for "Aliasfile:" profile entry
222 if ((cp = context_find("Aliasfile"))) {
225 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap;
227 vec[vecp++] = "-alias";
233 msgs[msgp++] = seq_cur;
234 maildir = toabsdir(draftfolder);
236 if (chdir(maildir) == NOTOK)
237 adios(maildir, "unable to change directory to");
239 /* read folder and create message structure */
240 if (!(mp = folder_read(draftfolder)))
241 adios(NULL, "unable to read draft folder %s", draftfolder);
243 /* check for empty folder */
245 adios(NULL, "no messages in draft folder %s", draftfolder);
247 /* parse all the message ranges/sequences and set SELECTED */
248 for (msgnum = 0; msgnum < msgp; msgnum++)
249 if (!m_convert(mp, msgs[msgnum]))
251 seq_setprev(mp); /* set the previous-sequence */
253 for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
254 if (is_selected(mp, msgnum)) {
255 msgs[msgp++] = getcpy(m_name(msgnum));
256 unset_exists(mp, msgnum);
260 mp->msgflags |= SEQMOD;
263 if (!(cp = getenv("SIGNATURE")) || !*cp)
264 if ((cp = context_find("signature")) && *cp)
265 m_putenv("SIGNATURE", cp);
267 for (msgnum = 0; msgnum < msgp; msgnum++)
268 if (stat(msgs[msgnum], &st) == NOTOK)
269 adios(msgs[msgnum], "unable to stat draft file");
271 if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
273 if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
275 if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
276 altmsg = NULL; /* used by dist interface - see below */
278 if ((cp = getenv("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) {
279 vec[vecp++] = "-dist";
280 distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
281 if (link(altmsg, distfile) == NOTOK) {
284 && errno != EISREMOTE
285 #endif /* EISREMOTE */
287 adios(distfile, "unable to link %s to",
290 distfile = getcpy(m_mktemp2(NULL, invo_name,
296 if ((in = open(altmsg, O_RDONLY)) == NOTOK)
297 adios(altmsg, "unable to open");
299 if ((out = creat(distfile,
300 (int) st.st_mode & 0777))
302 adios(distfile, "unable to write");
303 cpydata(in, out, altmsg, distfile);
312 if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
321 vec[0] = mhbasename(postproc);
324 for (msgnum = 0; msgnum < msgp; msgnum++) {
325 switch (sendsbr(vec, vecp, msgs[msgnum], &st, 1)) {
335 context_save(); /* save the context file */