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 },
51 extern int debugsw; /* from sendsbr.c */
57 extern char *altmsg; /* .. */
58 extern char *annotext;
59 extern char *distfile;
63 main(int argc, char **argv)
65 int msgp = 0, distsw = 0, vecp = 1;
67 char *cp, *maildir = NULL;
68 char buf[BUFSIZ], **ap, **argp, **arguments;
69 char *msgs[MAXARGS], *vec[MAXARGS];
74 setlocale(LC_ALL, "");
76 invo_name = mhbasename(argv[0]);
78 /* read user profile/context */
81 arguments = getarguments(invo_name, argc, argv, 1);
84 vec[vecp++] = "-library";
85 vec[vecp++] = getcpy(toabsdir("+"));
87 while ((cp = *argp++)) {
89 switch (smatch(++cp, switches)) {
91 ambigsw(cp, switches);
94 adios(NULL, "-%s unknown\n", cp);
97 snprintf(buf, sizeof(buf),
98 "%s [file] [switches]",
100 print_help(buf, switches, 1);
103 print_version(invo_name);
130 debugsw++; /* fall */
142 if (!(cp = *argp++) || *cp == '-')
143 adios(NULL, "missing argument to %s",
155 ** check for "Aliasfile:" profile entry
157 if ((cp = context_find("Aliasfile"))) {
160 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap;
162 vec[vecp++] = "-alias";
168 msgs[msgp++] = seq_cur;
169 maildir = toabsdir(draftfolder);
171 if (chdir(maildir) == NOTOK)
172 adios(maildir, "unable to change directory to");
174 /* read folder and create message structure */
175 if (!(mp = folder_read(draftfolder)))
176 adios(NULL, "unable to read draft folder %s", draftfolder);
178 /* check for empty folder */
180 adios(NULL, "no messages in draft folder %s", draftfolder);
182 /* parse all the message ranges/sequences and set SELECTED */
183 for (msgnum = 0; msgnum < msgp; msgnum++)
184 if (!m_convert(mp, msgs[msgnum]))
186 seq_setprev(mp); /* set the previous-sequence */
188 for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
189 if (is_selected(mp, msgnum)) {
190 msgs[msgp++] = getcpy(m_name(msgnum));
191 unset_exists(mp, msgnum);
195 mp->msgflags |= SEQMOD;
198 if (!(cp = getenv("SIGNATURE")) || !*cp)
199 if ((cp = context_find("signature")) && *cp)
200 m_putenv("SIGNATURE", cp);
202 for (msgnum = 0; msgnum < msgp; msgnum++)
203 if (stat(msgs[msgnum], &st) == NOTOK)
204 adios(msgs[msgnum], "unable to stat draft file");
206 if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
208 if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
210 if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
211 altmsg = NULL; /* used by dist interface - see below */
213 if ((cp = getenv("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) {
214 vec[vecp++] = "-dist";
215 distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
216 if (link(altmsg, distfile) == NOTOK) {
218 adios(distfile, "unable to link %s to",
221 distfile = getcpy(m_mktemp2(NULL, invo_name,
227 if ((in = open(altmsg, O_RDONLY)) == NOTOK)
228 adios(altmsg, "unable to open");
230 if ((out = creat(distfile,
231 (int) st.st_mode & 0777))
233 adios(distfile, "unable to write");
234 cpydata(in, out, altmsg, distfile);
243 if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
252 vec[0] = mhbasename(postproc);
255 for (msgnum = 0; msgnum < msgp; msgnum++) {
256 switch (sendsbr(vec, vecp, msgs[msgnum], &st, 1)) {
266 context_save(); /* save the context file */