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, msgp2 = 0, distsw = 0, vecp = 1;
67 char *cp, *maildir = NULL;
68 char buf[BUFSIZ], **ap, **argp, **arguments;
69 char *msgs[MAXARGS], *vec[MAXARGS];
75 setlocale(LC_ALL, "");
77 invo_name = mhbasename(argv[0]);
79 /* read user profile/context */
82 arguments = getarguments(invo_name, argc, argv, 1);
85 vec[vecp++] = "-library";
86 vec[vecp++] = getcpy(toabsdir("+"));
88 while ((cp = *argp++)) {
90 switch (smatch(++cp, switches)) {
92 ambigsw(cp, switches);
95 adios(NULL, "-%s unknown\n", cp);
98 snprintf(buf, sizeof(buf),
99 "%s [file] [switches]",
101 print_help(buf, switches, 1);
104 print_version(invo_name);
131 debugsw++; /* fall */
143 if (!(cp = *argp++) || *cp == '-')
144 adios(NULL, "missing argument to %s",
156 ** check for "Aliasfile:" profile entry
158 if ((cp = context_find("Aliasfile"))) {
161 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap;
163 vec[vecp++] = "-alias";
164 vec[vecp++] = getcpy(etcpath(*ap));
169 msgs[msgp++] = seq_cur;
170 maildir = toabsdir(draftfolder);
172 if (chdir(maildir) == NOTOK)
173 adios(maildir, "unable to change directory to");
175 /* read folder and create message structure */
176 if (!(mp = folder_read(draftfolder)))
177 adios(NULL, "unable to read draft folder %s", draftfolder);
179 /* check for empty folder */
181 adios(NULL, "no messages in draft folder %s", draftfolder);
183 /* parse all the message ranges/sequences and set SELECTED */
185 for (msgnum = 0; msgnum < msgp; msgnum++) {
186 if (*msgs[msgnum] == '/') {
188 msgs2[msgp2++] = msgs[msgnum];
191 if (!m_convert(mp, msgs[msgnum])) {
195 seq_setprev(mp); /* set the previous-sequence */
197 for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
198 if (is_selected(mp, msgnum)) {
199 msgs2[msgp2++] = getcpy(m_name(msgnum));
200 unset_exists(mp, msgnum);
204 mp->msgflags |= SEQMOD;
207 if (!(cp = getenv("SIGNATURE")) || !*cp)
208 if ((cp = context_find("signature")) && *cp)
209 m_putenv("SIGNATURE", cp);
211 for (msgnum = 0; msgnum < msgp2; msgnum++)
212 if (stat(msgs2[msgnum], &st) == NOTOK)
213 adios(msgs2[msgnum], "unable to stat draft file");
215 if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
217 if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
219 if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
220 altmsg = NULL; /* used by dist interface - see below */
222 if ((cp = getenv("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) {
223 vec[vecp++] = "-dist";
224 distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
225 if (link(altmsg, distfile) == NOTOK) {
227 adios(distfile, "unable to link %s to",
230 distfile = getcpy(m_mktemp2(NULL, invo_name,
236 if ((in = open(altmsg, O_RDONLY)) == NOTOK)
237 adios(altmsg, "unable to open");
239 if ((out = creat(distfile,
240 (int) st.st_mode & 0777))
242 adios(distfile, "unable to write");
243 cpydata(in, out, altmsg, distfile);
252 if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
261 vec[0] = mhbasename(postproc);
264 for (msgnum = 0; msgnum < msgp2; msgnum++) {
265 switch (sendsbr(vec, vecp, msgs2[msgnum], &st, 1)) {
275 context_save(); /* save the context file */