+ if (*cp == '/') {
+ files[nfiles++] = cp;
+ } else {
+ msgs[nmsgs++] = cp;
+ }
+ }
+ }
+
+ if (!nmsgs && !nfiles) {
+ msgs[nmsgs++] = seq_cur;
+ }
+
+ if (nmsgs) {
+ maildir = toabsdir(draftfolder);
+ if (chdir(maildir) == NOTOK) {
+ adios(EX_OSERR, maildir, "unable to change directory to");
+ }
+ if (!(mp = folder_read(draftfolder))) {
+ adios(EX_IOERR, NULL, "unable to read draft folder %s",
+ draftfolder);
+ }
+ if (mp->nummsg == 0) {
+ adios(EX_DATAERR, NULL, "no messages in draft folder %s",
+ draftfolder);
+ }
+ /* parse all the msgranges/sequences and set SELECTED */
+ for (msgnum = 0; msgnum < nmsgs; msgnum++) {
+ if (!m_convert(mp, msgs[msgnum])) {
+ exit(EX_USAGE);
+ }
+ }
+ seq_setprev(mp);
+
+ for (nmsgs = 0, msgnum = mp->lowsel;
+ msgnum <= mp->hghsel; msgnum++) {
+ if (is_selected(mp, msgnum)) {
+ files[nfiles++] = getcpy(m_name(msgnum));
+ unset_exists(mp, msgnum);
+ }
+ }
+
+ mp->msgflags |= SEQMOD;
+ seq_save(mp);
+ }
+
+ if (!(cp = getenv("SIGNATURE")) || !*cp) {
+ if ((cp = context_find("signature")) && *cp) {
+ m_putenv("SIGNATURE", cp);
+ }
+ }
+
+ for (n = 0; n < nfiles; n++) {
+ if (stat(files[n], &st) == NOTOK) {
+ adios(EX_IOERR, files[n], "unable to stat draft file");
+ }
+ }
+
+ if (!(annotext = getenv("mhannotate")) || !*annotext) {
+ annotext = NULL;
+ }
+ if (!(altmsg = getenv("mhaltmsg")) || !*altmsg) {
+ altmsg = NULL; /* used by dist interface - see below */
+ }
+
+ if ((cp = getenv("mhdist")) && *cp && (distsw = atoi(cp)) && altmsg) {
+ vec[vecp++] = "-dist";
+ if ((in = open(altmsg, O_RDONLY)) == NOTOK) {
+ adios(EX_IOERR, altmsg, "unable to open for reading");
+ }
+ fstat(in, &st2);
+ distfile = getcpy(m_mktemp2(NULL, invo_name, NULL, NULL));
+ if ((out = creat(distfile, (int)st2.st_mode & 0777))==NOTOK) {
+ adios(EX_IOERR, distfile, "unable to open for writing");
+ }
+ cpydata(in, out, altmsg, distfile);
+ close(in);
+ close(out);
+ } else {
+ distfile = NULL;
+ }
+
+ if (!altmsg || stat(altmsg, &st) == NOTOK) {
+ st.st_mtime = 0;
+ st.st_dev = 0;
+ st.st_ino = 0;
+ }
+ status = 0;
+ vec[0] = "spost";
+ for (n=3; n<OPEN_MAX; n++) {
+ close(n);
+ }
+
+ for (n = 0; n < nfiles; n++) {
+ switch (sendsbr(vec, vecp, files[n], &st)) {
+ case DONE:
+ exit(++status);
+ case NOTOK:
+ status++; /* fall */
+ case OK:
+ break;