Re: OT: Removal of old 14+ mail from mbox-based mail spool (not maildir)

From: Giorgos Keramidas (keramida_at_ceid.upatras.gr)
Date: 08/17/05

  • Next message: Kevin Kinsey: "Re: OT: Removal of old 14+ mail from mbox-based mail spool (not maildir)"
    Date: Wed, 17 Aug 2005 18:08:07 +0300
    To: Matt Juszczak <matt@atopia.net>
    
    

    On 2005-08-17 10:50, Matt Juszczak <matt@atopia.net> wrote:
    > Hi all,
    > Sorry this is off topic, just didn't really know where else to post
    > this other than to fellow sys-admins.
    >
    > I need a script that will analyze a mail spool file and remove email
    > from it that is more than 14 days old. I found a couple; however,
    > they require perl modules I couldn't seem to find. Does anyone have
    > any ideas? If not, I'll go ahead and write one.

    If you have procmail, you can roll your own with something like:

            $ formail -s procmail procmailrc-remove-old < mbox

    The ``procmailrc-remove-old'' ruleset can implement something like the
    logic of removing old messages, by piping the messages one by one
    through a shell script that uses date(1) on the envelope-from line.

    All messages in a Unix mbox file start with a line like this:

            From keramida@FreeBSD.ORG Fri Sep 3 18:19:29 2004

    You can extract the timestamp and convert it to seconds since the UNIX
    Epoch time, with date(1):

    % message_time=$( echo 'From keramida@FreeBSD.ORG Fri Sep 3 18:19:29 2004' | \
    % awk '{print $4,$5,$6,$7}' )
    % message_seconds=$( date -j -f '%b %e %H:%M:%S %Y' "$message_time" '+%s' )

    This should set $message_seconds to 1094224769. Then you can get the
    current time in seconds from the UNIX Epoch and perform ordinary numeric
    operations, i.e. subtract the number of seconds in a 14-day period.

    Messages with a $message_seconds value less than the current time minus
    the period of your choise, should be thrown away. The rest should be
    echoed back to procmail, which will deliver them as usual.

    This is just an idea of course, so you may want to look at existing
    mailers, like Mutt, before you start scripting. They usually include
    options to select message ranges based on the arrival date.

    - Giorgos

    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"


  • Next message: Kevin Kinsey: "Re: OT: Removal of old 14+ mail from mbox-based mail spool (not maildir)"

    Relevant Pages

    • this is not a specific linux question but more of just UNIX - tar, dump, restore command questions?
      ... I am new at a company that has a Unix server and they have no documentation ... They have a script I assume that runs a backup tape every night of just one ... assuming their either are using a tar or dump command / script. ... a restore from a tar file assuming they are using tar. ...
      (comp.os.linux.misc)
    • Summary - Date conversion script
      ... I want to say thanks to John F Wall, Kalyan Manchikanti, Aaron ... has a great function for dealing w/ UNIX Epoch time (seconds since Jan ... And here is an nawk script which processes the output of the "passwd ... It's probably easier to get the UNIX epoch time, ...
      (SunManagers)
    • Re: ksh script ! How can i do this
      ... > but korn shell and unix systems. ... > I am new to scripting and have a script that I would like to write to ... > I want to pull some information out of a txt file created from dos / I ... We have noticed that your lotus notes mailbox is exceeding the 100mb ...
      (comp.unix.shell)
    • Re: [ Attn: Randy ] Ad-hoc Parsing?
      ... > therefore you loose the primary advantage of writing a script and may ... > matching Unix. ... You use six external programs ('tidy', 'make-make', ... program and not by the shell, ...
      (alt.lang.asm)
    • postfix+spamassassin help
      ... I am having some trouble getting postfix and spamassassin working ... and I have written a script ... cleanup unix n - n - 0 cleanup ... spamfilter unix - n n - 10 pipe ...
      (comp.os.linux.misc)