- cwd = getcpy (pwd ());
-
- if (!context_find ("path"))
- free (path ("./", TFOLDER));
- if (file && (msg || folder))
- adios (NULL, "can't mix files and folders/msgs");
-
- in = open_form(&form, distcomps);
-
- strncpy (drft, m_draft("new"), sizeof(drft));
-
- if ((out = creat (drft, m_gmprot ())) == NOTOK)
- adios (drft, "unable to create");
-
- cpydata (in, out, form, drft);
- close (in);
- close (out);
-
- if (file) {
- /*
- * Dist a file
- */
- anot = 0; /* don't want to annotate a file */
- } else {
- /*
- * Dist a message
- */
- if (!msg)
- msg = "cur";
- if (!folder)
- folder = getfolder (1);
- maildir = m_maildir (folder);
-
- if (chdir (maildir) == NOTOK)
- adios (maildir, "unable to change directory to");
-
- /* read folder and create message structure */
- if (!(mp = folder_read (folder)))
- adios (NULL, "unable to read folder %s", folder);
-
- /* check for empty folder */
- if (mp->nummsg == 0)
- adios (NULL, "no messages in %s", folder);
-
- /* parse the message range/sequence/name and set SELECTED */
- if (!m_convert (mp, msg))
- done (1);
- seq_setprev (mp); /* set the previous-sequence */
-
- if (mp->numsel > 1)
- adios (NULL, "only one message at a time!");
+ cwd = getcpy(pwd());
+
+ strncpy(drft, m_draft(seq_beyond), sizeof(drft));
+ if ((out = creat(drft, m_gmprot())) == NOTOK) {
+ adios(EX_CANTCREAT, drft, "unable to create");
+ }
+
+ fmtstr = new_fs(form, distcomps);
+ if (write(out, fmtstr, strlen(fmtstr)) != (int)strlen(fmtstr)) {
+ adios(EX_IOERR, drft, "error writing");
+ }
+ close(out);
+
+ if (!msg) {
+ msg = seq_cur;
+ }
+ if (!folder) {
+ folder = getcurfol();
+ }
+ maildir = toabsdir(folder);
+
+ if (chdir(maildir) == NOTOK) {
+ adios(EX_OSERR, maildir, "unable to change directory to");