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

2005-08-17 Thread Matt Juszczak

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.


Thanks!

-Matt
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


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

2005-08-17 Thread Giorgos Keramidas
On 2005-08-17 10:50, Matt Juszczak [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED]


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

2005-08-17 Thread Kevin Kinsey

Matt Juszczak 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.

Thanks!

-Matt




mail spool file being /var/mail/someuser?  Or do you
mean dead mail in the /var/spool/mqueue *directory*?
Technically the mail spool is a directory full of
individuals files, as I understand it

I'd think cleaning out a directory to be easier, but
it isn't clear to me what you want.

Also, a script in sh(1), or do you have some other
language available?  I have a short PHP script
that does something similar and could be modded,
perhaps.

OTOH, somebody around here could probably
give you a one-liner with sh, sed, grep, awk, date,
test, etc., but I was at the hospital last night until
2 a.m. and don't think I can pull it off ATM

Kevin Kinsey
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


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

2005-08-17 Thread Matt Juszczak

|  Also, a script in sh(1), or do you have some other


language available?  I have a short PHP script
that does something similar and could be modded,
perhaps.

OTOH, somebody around here could probably
give you a one-liner with sh, sed, grep, awk, date,
test, etc., but I was at the hospital last night until
2 a.m. and don't think I can pull it off ATM

Kevin Kinsey



I want to clean out an IMAP folder (actually file $HOME/mail/Spam).  
We have about 10,000 users and our users don't check their spam 
quarantine often, so our policy is to remove messages after 14 days.


I know how to:

1) recursively pull each Spam folder in existance (for x in `ls 
/home/*/mail/Spam`; do ; done)
2) Use grep and awk to pull each message and its relative data (grep the 
date, parse it)


What I'm not sure of is how to remove a message from the spool itself.  
Should I just use grep and/or sed to pull until new From header, then 
remove those lines from the spool manually?


This would be easier if I could use IMAP, because then I could use the 
built-in PHP functions for imap to check dates and remove messages.  
Problem is, we don't know the user's passwords (they are hashed).


Any other ideas?  Thanks!

-Matt
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


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

2005-08-17 Thread Giorgos Keramidas
On 2005-08-17 11:58, Matt Juszczak [EMAIL PROTECTED] wrote:
 I know how to:

 1) recursively pull each Spam folder in existance (for x in `ls
 /home/*/mail/Spam`; do ; done)
 2) Use grep and awk to pull each message and its relative data (grep the
 date, parse it)

 What I'm not sure of is how to remove a message from the spool itself.
 Should I just use grep and/or sed to pull until new From header, then
 remove those lines from the spool manually?

 This would be easier if I could use IMAP, because then I could use the
 built-in PHP functions for imap to check dates and remove messages.
 Problem is, we don't know the user's passwords (they are hashed).

 Any other ideas?  Thanks!

For a similar purpose (removing duplicates from a UNIX mailbox file), I
use a temporary procmailrc ruleset with the -D option of formail(1) and
save some of the messages of the original mailbox in a temporary file.

You can do something similar, but use a properly crafted procmailrc that
saves only new enough messages.  The script I use to remove duplicates
from mailboxes is:

% #!/bin/sh
%
% if [ $# -eq 0 ]; then
% echo usage: $(basename $0) file [...] 2
% exit 1
% fi
%
% TMPDIR=${TMPDIR:-/tmp}
% export TMPDIR
%
% for fname in $@ ;do
% mbox=$(mktemp ${TMPDIR}/$(basename ${fname})-XX)
% filter=$(mktemp ${TMPDIR}/procmailrc-XX)
% msgid=$(mktemp ${TMPDIR}/msgid-XX)
%
% if [ X${mbox} = X ] || [ X${filter} = X ] || \
%  [ X${msgid} = X ]; then
% echo $(basename $0): error: failed to create temp files. 2
% exit 1
% fi
%
% echo DEFAULT=${mbox}  ${filter}  \
% formail -D 32768 ${msgid} \
% -s procmail ${filter}  ${fname}
% if [ $? -eq 0 ]  [ -f ${mbox} ]; then
% mv ${mbox} ${fname}
% echo ok ${fname}
% fi
% /bin/rm -f ${filter} ${msgid}
% done

You can write a similar script to filter any mailbox through any
procmail ruleset, as long as you have tested the ruleset and found that
it works exactly like you want it to work.

- Giorgos

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


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

2005-08-17 Thread Matt Juszczak

procmail ruleset, as long as you have tested the ruleset and found that
it works exactly like you want it to work.

- Giorgos


I'm actually trying to write a script with formail, but its being 
annoying:


orion$ formail -s parse.pl  Spam
parse.pl: 3: Syntax error: ) unexpected
parse.pl: 3: Syntax error: ) unexpected
parse.pl: 3: Syntax error: ) unexpected
orion$


parse.pl is:

#!/usr/bin/perl

while (STDIN) {
print
}




and when I run parse.pl manually:

orion$ echo Yo | ./parse.pl
Yo
orion$



Weird eh?  Any ideas?
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


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

2005-08-17 Thread Giorgos Keramidas
On 2005-08-17 14:15, Matt Juszczak [EMAIL PROTECTED] wrote:
 procmail ruleset, as long as you have tested the ruleset and found that
 it works exactly like you want it to work.

 I'm actually trying to write a script with formail, but its being
 annoying:

 orion$ formail -s parse.pl  Spam
 parse.pl: 3: Syntax error: ) unexpected
 parse.pl: 3: Syntax error: ) unexpected
 parse.pl: 3: Syntax error: ) unexpected
 orion$

Is the current working directory in your PATH?

 parse.pl is:

 #!/usr/bin/perl

 while (STDIN) {
 print
 }

 and when I run parse.pl manually:

 orion$ echo Yo | ./parse.pl
 Yo
 orion$

 Weird eh?  Any ideas?

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]