Skip to navigation

Adding an “X-label” header to lots of messages at once using mutt

I’m using this method to add labels to individual messages in mutt. (You can use the X-label header in a similar way that you label e-mail in Gmail. You can search for messages with a certain label using the ~y pattern in mutt). But what if you suddenly want to apply a label to lots of messages in a mailbox?

If your original messages are in an “mbox” format mailbox, you can pipe the messages to formail, which adds the header, and append the messages to the current mailbox (let’s assume it’s called “mycurrentmbox”:

formail -I "X-label: yourlabel" >> mycurrentmbox

Note that this will remove any other “X-label” headers, if present. Alternatively, you might want to check out the -a or -i options (man formail).

I have my mail in “maildir” format, where each mail is an individual file. I use a workaround: pipe all messages to formail, which adds the header, then append to a temporary “mbox” format, delete the original messages in the maildir, then move the messages from the temporary mbox to the original maildir.

In your original maildir, tag and pipe-message, then:

formail -I "X-label: yourlabel" >> mytempmbox

Optionally check that the labeled messages have arrived safely in your temporary mailbox, delete all the tagged (unlabeled) original messages, then go to your temporary mailbox with

mutt -f mytempmbox

tag all messages there, save tagged to the original mailbox. Delete the temporary mailbox.

Comments are closed.