Working with Draft Messages

If you use the quit command at a What now? prompt, it leaves the draft message for you to work on later.

MH also has a very useful feature called draft folders that lets you keep many draft messages, work on them, and send them "in the background" while you do something else. This section explains how to work with draft messages in MH. (If you have nmh, your mh-draft(1) manual page has a summary.)

Single Draft Messages

If you started using MH from scratch, your account probably uses just a single draft message. (It has to be set up especially to use an MH draft folder instead of the draft message.) A "single draft message" means that whenever you start to send a message with comp, repl, forw, or dist, the draft is always written to a file named draft in your MH directory. If you start one of those programs and the draft file already exists, you'll see this message:

    Draft '/yourMHdir/draft' exists; disposition?
    
Press RETURN for a list of what you can do. Here are the choices:
list (or l)
Shows you the existing draft.
quit (or q)
Exits from MH and leaves the draft alone.
refile +folder
Moves the draft message into the folder you name. The draft won't be sent. Instead, the draft is moved and replaced with a new, empty form; you start over with a new draft. There's more about folders in Section Folders.
replace (or rep)
Deletes the draft and replaces it with a new, empty form. You start fresh, as if the old draft were never there.
use (or u)
Starts up your draft editor (by default, prompter) to keep working on the existing draft. You only have this choice if you're running comp. Note that if you start repl, forw, or dist before you get the disposition? prompt, they won't let you use an existing draft -- you'll need to quit and run comp.

You can also get here directly and skip the disposition? prompt by starting with the command:

      % comp -use
      
That's the normal way to re-edit an existing draft message.
NOTE: If you're re-editing a draft that you started with repl, forw, or dist and its -annotate switch, the original message won't be annotated. That's because there's no way for MH to find the original message number just by looking at the leftover draft. You can annotate the message yourself with anno.

Draft Folder

Instead of using a single draft file, you can set up an MH folder that holds many drafts. This has some great advantages:

One disadvantage of a draft folder is that it can be easier for you to forget about an old draft message.

To set up a draft folder, you may want to skip ahead and read about folders. Once you've set up a draft folder, though, you don't need to think about folders much. Here's how you do it:

  1. Pick a name for the draft folder (xmh uses the name drafts; that might be a good choice even if you don't use xmh).
  2. Create the folder from a shell prompt, like this:
          % folder -push +drafts
          Folder /yourMHdir/drafts doesn't exist; create? y
                    drafts+ has no messages.
          % folder -pop
          [previousfolder+ now current.]
          
  3. Add this entry to your MH profile:
          Draft-folder: drafts
          
Try using your draft folder. Type comp (or repl or...). When you get to the What now? prompt, type quit. You'll get a message that tells you where the draft message was left:
    What now? q
    whatnow: draft left on /yourMHdir/drafts/1
    
That shows that the draft message is number 1. Then start another draft (with comp or repl or...). Instead of the old prompt:
    Draft '/yourMHdir/draft' exists; disposition?
    
MH will give you a fresh draft. Then, if you type quit again, you'll see that this new draft has the next higher message number in the draft folder:
    What now? q
    whatnow: draft left on /yourMHdir/drafts/2
    
How do you finish a draft that you've left in the draft folder? An easy way is with the following command:
    % comp -use n
    
where n is the draft message number that you want to resume. Easier: if you want to re-edit the draft you started most recently, that draft should still be the current message in the draft folder... in which case you can omit the message number n.

If you're not sure which message you want, you can scan the draft folder to get a summary of your draft messages:

    % scan +drafts
    
Or, the recomp shell script is probably the easiest way of all.

As explained in the Section Single Draft Messages, if you're re-editing a draft that you started with repl, forw, or dist and its -annotate switch, the original message won't be annotated.

Deleted Draft Messages

After you send a draft, MH renames it with a leading comma (,) or hash mark (#). For instance, without a draft folder, your draft file could be renamed ,draft. In a draft folder, draft number 3 would be "deleted" by changing its name to ,3. If you need to recover a draft message, just rename it without the comma or hash mark. The techniques are in the Section Removing and Recovering Messages.

If you type quit -delete at a What now? prompt -- or, if your editor program returns a nonzero exit status to whatnow (see the Section Aborted Draft Messages) -- whatnow will delete your draft as explained above. When that happened, versions of MH before 6.7.2 just said that the draft was "deleted." MH 6.7.2 changed the message to a user-friendly:

    whatnow: problems with edit -- draft left in /yourMHdir/drafts/,2
    

Aborted Draft Messages

Here's one editing feature that isn't user-friendly. Some editors return a nonzero exit status when the file they were editing is perfectly fine. (Versions of vi from AT&T and Sun have this "feature.") whatnow will think that the editor failed -- and delete your draft.

If you use an editor like that, find out whether your version of MH was built with the [ATTVIBUG] configuration option. If you can't use [ATTVIBUG], you can make a shell script like the one below, myvi, that edits the draft and always returns a zero exit status. (You can also get the script from this book's online archive. It's at examples/mh/bin/myvi.)

Example: Workaround for vi editor problem: myvi

    #! /bin/sh
    # myvi - workaround for "vi" that returns non-zero exit status
    # and makes MH "whatnow" delete draft message.
    # Usage (in MH profile)    Editor: myvi
    vi $*
    exit 0
    
To install myvi, see the Section Writing Shell Scripts for MH and the Section Changing Default Editors. The Section Writing Your Own Draft Message Editor(s) explains more about writing draft editors.

Finish Draft Messages: recomp

When you type q at a What now? prompt, it leaves the draft message without sending it. If you have a draft folder, the command line you'd type to recompose the draft is long. Also, it can be hard to remember the draft number -- so you have to scan the draft folder, then remember to change your folder back.

The recomp script helps with that. If you give it a message number in the draft folder, it starts comp -use on that message with your favorite editor program. Without a message number, recomp scans the draft folder, then lets you enter the number of the message you want to recompose, and then starts comp -use. When you exit your editor, you get the usual What now? prompt.

Another section shows how to set up recomp.

Work on Draft Folder: scandrafts

The scandrafts script is nice when you're wondering what's in your draft folder or you need to work in it.

Here's a demonstration using -stay (without -stay, there wouldn't be a scandrafts prompt):
    $ scandrafts -stay
    Draft message(s) you've already sent:

    ,1:Subject: Re: SC or GA islands
    ,5:Subject: Re: our previous message about banners dialups
    ,6:Subject: Re: Can you help?
    ,7:Subject: Out this morning

    To get them back, use 'mv'.
    ===========================================================
    Draft message(s) you haven't sent:

       1  03/07*To:alison@mvus.cs  Project status<<Alison, the 
    scan: message 2: empty
       3+ 03/07*To:kx9cq@cornell.  Scientific Visualization Dem

            You'll be in a /bin/ksh shell in the +drafts folder
            To quit, type control-d.
    scandrafts> rmm 2
    scandrafts> mv ,6 6
    scandrafts> scan
       1  03/07*To:alison@mvus.cs  Project status<<Alison, the p
       3+ 03/07*To:kx9cq@cornell.  Scientific Visualization Demo
       6  03/04*To:"Warren Z. Von  Re: Can you help?<<Warren, yo
    scandrafts> refile 6 +outbox

    scandrafts> CTRL-D

    [folder +inbox now current]
    $
    
First, you see four messages that have already been sent. The send program put commas at the beginnings of their names. Next come the messages that haven't been sent. One draft is empty (this can happen if you have trouble composing a message).

Then, because the -stay switch was used, scandrafts starts the default shell (this person uses the Korn shell). The shell prompt is set to scandrafts>. The current folder and current directory are the draft folder, so rmm removes the empty draft and mv takes the comma off message 6. A scan shows the cleaned-up folder. CTRL-D ends the shell and the scandrafts script.

Another section explains how to set up scandrafts.

Building MIME Drafts

mhn (in MH, and nmh before version 0.21) and mhbuild (nmh-0.21+) edits drafts that contain directives. (There are examples in the Sections Sending MIME Mail, MIME Draft Directives, and many others.) It replaces the draft with an encoded MIME message, ready to send. You can run mhn by hand, before you send the draft:

    What now? edit mhn
    
(or just e mhn). Or, if you use nmh, you can type mime instead.

It can be easy to forget to do MIME processing by hand. If you forget, the recipient will get a message full of your directives -- instead of the encoded MIME message you meant to send. If you want all the messages you send to be MIME messages, you can do MIME processing automatically by adding an MH profile automhnproc: entry -- or, for nmh, automimeproc: and maybe buildmimeproc:. There are advantages and disadvantages; the section Building MIME Drafts Automatically has the story.

Running mhn or mhbuild automatically has another advantage if you use 8-bit (non-ASCII) characters: the minimum required character set (for example, us-ascii for English-only text) will be used. This makes it more likely that people with lousy mail-reading setups can still read what you send.

Whether you run mhn/mhbuild automatically or by hand, though -- after you have some MIME experience, you may not always agree with the automatically-chosen encoding. If you don't use automatic processing, you can edit the encoded draft and change the encoding.

In cases like those, you have a few choices. One is to remember to run mhn or mhbuild by hand when you need it. Another is to add this header field to your draft:

    MIME-Version: 1.0
    
When send sees that field, it won't invoke the automatic MIME draft processing. But if you add that field, be sure that your message really is in legal MIME format! (There are too many bogus MIME messages already.)

Recovering MIME Drafts

When mhn or mhbuild reads the directives in your draft message and encodes it, the original draft message file is also preserved for a while. Recovering the original draft takes a little work, but it can be easier than trying to undo what mhn did. For instance, you might have given the wrong filename at the end of a directive, and you don't want to re-enter the whole draft just to fix that one mistake. This section explains how to recover the draft with the original directives. The end of this section describes a shell script that makes the job easier.

Let's start this example by sending a message:

    What now? edit mhn           (...on nmh, mime)

    What now? list
        ...message appears; you see mistake...
    
Use these steps to recover the original directives:
  1. Quit and leave the encoded draft there:
          What now? quit
          whatnow: draft left on /mh/jerry/drafts/3
          
  2. Change your current directory to the directory where your draft message was. whatnow will print the pathname of the draft (see above).

    Here are examples with a draft folder and without. Use backquotes (`), not single quotes ('), in the commands below. The command ls -lt lists the most recently modified files first.

    With a draft folder:

          % cd `mhpath +drafts`
          % ls -lt
          total 357
              ...
          -rw-------  1 jerry       86340 Oct 16 10:46 3
          -rw-------  1 jerry        1419 Oct 16 10:43 ,3.orig
              ...
          
    No draft folder:
          % cd `mhpath +`
          % ls -lt
          total 289
              ...
          -rw-------  1 jerry       86340 Oct 16 10:46 draft
          -rw-------  1 jerry        1419 Oct 16 10:43 ,draft.orig
              ...
          
  3. You should see your original draft in a file named ,n.orig (if you use a draft folder) or ,draft.orig (if you don't). The filename without the comma (,) and the .orig is the encoded draft. (Note: your MH may have been configured to use a character other than a comma -- for example, #.) If you want to read the drafts, you can use a pager like more(1) or less(1). If you need to save the encoded draft for some reason, do it now. Otherwise, replace the encoded draft with the original draft:
          % mv ,3.orig 3
          
  4. Re-edit the recovered draft with the comp -use command (if you have a draft folder, see the Section Draft Folder; otherwise, see the Section Single Draft Messages).
You're done. Now, think about installing the shell script named original from this book's online archive. It replaces all those steps with the simple command edit original. For example, if you run mhn and then see you've made a mistake, here's how you can replace the encoded draft with the original:
    What now? edit mhn

    What now? list
        ...oops...
    What now? edit original

    What now? edit vi
    
The original draft, with directives, will open inside your editor. You can fix the problem, save the file, quit the editor, and then type edit mhn again. Here's how to install original.