Is it possible to forward mail out of a mailbox to another mailbox? I know about .forward, that's not what I want to do(seems like that's 100% of the answers out there). I already have mail in a mailbox I can see. I want to forward all of it to another mailbox that has a .forward that pipes into a script that files the emails into folders for records.

So you see I already have forwarding setup, I want to now forward mail out of one mailbox into another so it can forward its incoming emails to the script.

I'll confess, the reason being that the script broke for a while and now I have those mails queued up. I've fixed the script, I just need to re-forward the mail through the .forward.

Hopefully I've explained well enough. There doesn't seem to be a forward-mail option in the mail application.


Solution 1:

You may use formail program to feed "one by one" messages in mailbox-file to program/script of your choice.

Below please find elaborate example of using formail -s ... to process user system mailboxfile. It is provided in man procmail and makes procmail process every message in the system mailbox.

#!/bin/sh

ORGMAIL=/var/mail/$LOGNAME

if cd $HOME &&
  test -s $ORGMAIL &&
  lockfile -r0 -l1024 .newmail.lock 2>/dev/null
then
  trap "rm -f .newmail.lock" 1 2 3 13 15
  umask 077
  lockfile -l1024 -ml
  cat $ORGMAIL >>.newmail &&
  cat /dev/null >$ORGMAIL
  lockfile -mu
  formail -s procmail <.newmail &&
  rm -f .newmail
  rm -f .newmail.lock
fi
exit 0

Solution 2:

Use Mutt for that. Open Mutt, select all Mails using Shift+T . Enter (just press these keys). Then forward them using ; b and entering the email to forward the mails.

This was the easiest solution I found.