I am using mutt (another newbie) as a sub-set of another process, i.e unattended. The mutt section is intended to go into a mailbox and save mail that matches a subject pattern, delete that mail and then quit automatically. This is relatively easy using push, tag pattern, tag prefix, save message; it all works great unless there is no mail that matches the pattern and then it saves the first message, deletes it, then quits - obviously a problem. I tried "limit" but if there are no matches then it doesn't show nothing, it shows everything, i.e. a user approach rather than a system approach.
The only approach that I can think of is to do it in two steps. On the first run, match only the first occurance of the match, then copy this to a local box; check the subject of that mail using perl, and if valid, proceed and do the full mutt push etc to save/delete, otherwise we know there are no mails we need to save. Any ideas?