in reply to Re: Re: Re: accessing mailbox files
in thread accessing mailbox files

Cees,

Sending raw email messages to another mbox is exactly what I want to do. However, I want each message in the original mbox to be a separate email in the destination mboxl and not one big file.Will formail allow this?

thanks

jc

  • Comment on Re: Re: Re: Re: accessing mailbox files

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: accessing mailbox files
by cees (Curate) on Jul 30, 2003 at 05:09 UTC

    Yes it will allow this. With the command I gave you above, formail will parse the mbox file, split out the separate email messages, and pipe each message to sendmail. Sendmail gets the parameters -oem <dest-address> which will send the mails to that email address. So if you had 5 messages in your mbox file, sendmail will send 5 separate messages.

    Here is what the switches do:

    • +1 skip the first message in the file (usually a POP3 header)
    • -d the file does not have to be in strict mbox format
    • -s execute the following command for each message. in this case execute 'sendmail -oem <dest-address>'

    A quick search on google found many man pages on formail. They might give some more insight into what it can do. The best way to learn is just to try it out and see.

    By the way, I initially said that formail came with sendmail. That was incorrect. It comes as part of the procmail package.

    - Cees

      Hey Cees, Excellent command. I ran the

      cat msg | formail +1 -ds /usr/lib/sendmail  -oem <dest addy> and it works great when msg is one big mbox file with multiple messages inside. I was wondering can I run that command if msg contains just one email file? I want to do something like  cat msg | /usr/lib/sendmail -m <dest> in a loop for a directory of files, but that command doesnt work at all.

      thanks

      jc

        Well, since an mbox file could have just one message, I assume that it will work. Just remove the '+1' from the formail command, as that would just skip the only message in the file.

        cat singlemsg | formail -ds sendmail -oem <dest addy>

        I haven't tested that, but since I don't have a copy of one of your messages, it would do no good for me to test it anyway...

        Cheers,

        Cees