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, nfiles = 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",
152 files[nfiles++] = cp;
160 ** check for "Aliasfile:" profile entry
162 if ((cp = context_find("Aliasfile"))) {
165 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap;
167 vec[vecp++] = "-alias";
168 vec[vecp++] = getcpy(etcpath(*ap));
172 if (!msgp && !nfiles)
173 msgs[msgp++] = seq_cur;
174 maildir = toabsdir(draftfolder);
176 if (chdir(maildir) == NOTOK)
177 adios(maildir, "unable to change directory to");
179 /* read folder and create message structure */
180 if (!(mp = folder_read(draftfolder)))
181 adios(NULL, "unable to read draft folder %s", draftfolder);
183 /* check for empty folder */
185 adios(NULL, "no messages in draft folder %s", draftfolder);
187 /* parse all the message ranges/sequences and set SELECTED */
188 for (msgnum = 0; msgnum < msgp; msgnum++) {
189 if (!m_convert(mp, msgs[msgnum])) {
193 seq_setprev(mp); /* set the previous-sequence */
195 for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
196 if (is_selected(mp, msgnum)) {
197 files[nfiles++] = getcpy(m_name(msgnum));
198 unset_exists(mp, msgnum);
202 mp->msgflags |= SEQMOD;
205 if (!(cp = getenv("SIGNATURE")) || !*cp)
206 if ((cp = context_find("signature")) && *cp)
207 m_putenv("SIGNATURE", cp);
209 for (msgnum = 0; msgnum < nfiles; msgnum++)
210 if (stat(files[msgnum], &st) == NOTOK)
211 adios(files[msgnum], "unable to stat draft file");
213 if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
215 if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
217 if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
218 altmsg = NULL; /* used by dist interface - see below */
220 if ((cp = getenv("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) {
221 vec[vecp++] = "-dist";
222 distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
223 if (link(altmsg, distfile) == NOTOK) {
225 adios(distfile, "unable to link %s to",
228 distfile = getcpy(m_mktemp2(NULL, invo_name,
234 if ((in = open(altmsg, O_RDONLY)) == NOTOK)
235 adios(altmsg, "unable to open");
237 if ((out = creat(distfile,
238 (int) st.st_mode & 0777))
240 adios(distfile, "unable to write");
241 cpydata(in, out, altmsg, distfile);
250 if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
259 vec[0] = mhbasename(postproc);
262 for (msgnum = 0; msgnum < nfiles; msgnum++) {
263 switch (sendsbr(vec, vecp, files[msgnum], &st, 1)) {
273 context_save(); /* save the context file */