LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-19-2006, 02:21 AM   #1
Sleen
Member
 
Registered: Sep 2005
Location: Kampala,Uganda
Distribution: RHEL,FC,SUSE,UBUNTU
Posts: 41

Rep: Reputation: 15
How to keep only mails that are 0 to 2 months old with QMAIL!


Hi all,
I wish to keep mails that are 0 to 2 months old on my server,then let my server auto delete them when they get older than two months,with Qmail.
Any ideas?
 
Old 10-19-2006, 04:53 AM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Do you use Maildir or mailbox format?

Although I don't do what you are tryinng to do, I run a cron job that goes and "reads" all the messages in my spam folder, cleans a backup folder (created with maildrop), etc.

I'm sure you could do the same, running find, or similar to delete based on age.


Will only work with Maildir thoug I would think
 
Old 10-19-2006, 05:06 AM   #3
Sleen
Member
 
Registered: Sep 2005
Location: Kampala,Uganda
Distribution: RHEL,FC,SUSE,UBUNTU
Posts: 41

Original Poster
Rep: Reputation: 15
Hi Billymayday,
I use maildir.Can you give me the sample cronjob you use?
 
Old 10-19-2006, 05:16 AM   #4
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
#!/bin/bash
shopt -s nullglob

cd ~/Maildir/.Backup/new

# move files in new to cur - this happens when you view folder

if [ $( ls | wc -l ) -gt 0 ]
then cp * ../cur; rm *;
fi

cd ~/Maildir/.Backup/cur

# Clean down to 25 messages

if [ $( ls | wc -l ) -gt 25 ];
then rm $(ls -t | sed -e 1,25d);
fi

# It also seems that filesnames of messages have ":2," added when folder viewed

for filename in *[0-9] ;do

newfile=$(echo $filename ":2," | tr -d " ")
mv $filename $newfile

done

# Read messages have a capital S on the end (I guess for Seen)

for filename in *"," ;do

newfile=$(echo $filename "S" | tr -d " ")
mv $filename $newfile

done

This is my backup cleaner.

Rgds
 
Old 10-20-2006, 12:35 AM   #5
Sleen
Member
 
Registered: Sep 2005
Location: Kampala,Uganda
Distribution: RHEL,FC,SUSE,UBUNTU
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks.Though i'm not good with shell scripting i'll see what i can do.
 
Old 10-20-2006, 04:39 AM   #6
Sleen
Member
 
Registered: Sep 2005
Location: Kampala,Uganda
Distribution: RHEL,FC,SUSE,UBUNTU
Posts: 41

Original Poster
Rep: Reputation: 15
Hi,
I wrote a simple script like this

#!/bin/sh
#find will look for mails last accessed two months and 5 days ago and delete them.

find /var/maildir -atime 65 -execdir rm -f {} /;

#end of script

But I was thinking,what if some guy after haven accessed the mail,checks it again say two days before the cronjob is executed,that mail will not be deleted.
Does anyone know of a way to help with this problem?
 
Old 10-20-2006, 05:07 AM   #7
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Run the cron job every day (or did I totally miss the poit)?
 
Old 10-20-2006, 05:35 AM   #8
Sleen
Member
 
Registered: Sep 2005
Location: Kampala,Uganda
Distribution: RHEL,FC,SUSE,UBUNTU
Posts: 41

Original Poster
Rep: Reputation: 15
run the cron say every 2weeks!
 
Old 10-20-2006, 05:42 AM   #9
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Sorry, I did miss the point. Can you restate the problem please?
 
Old 10-20-2006, 07:20 AM   #10
Sleen
Member
 
Registered: Sep 2005
Location: Kampala,Uganda
Distribution: RHEL,FC,SUSE,UBUNTU
Posts: 41

Original Poster
Rep: Reputation: 15
The problem is,the "-atime n" option to find looks for files last accessed n*24hrs.Now what if someone goes back to a mail that is already 2months old,say two days from the cronjob,it means the mail will not be deleted.Though it is two months old.
Hope you understand now?
 
Old 10-20-2006, 10:36 PM   #11
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Try

find /var/maildir -atime +65 -execdir rm -f {} /;

have a look at man find regarding use of "+"

btw - take a copy first in case you stuff it up (I know I would)
 
Old 10-21-2006, 12:56 AM   #12
Sleen
Member
 
Registered: Sep 2005
Location: Kampala,Uganda
Distribution: RHEL,FC,SUSE,UBUNTU
Posts: 41

Original Poster
Rep: Reputation: 15
Hi Billy,
Thanks for that idea.But my problem still remain unsolved.Remember "atime n" is looking for last accessed files.We're assuming that when a mail is read,that is the last accessed time,and so our little script will find it and delete it.What if,that mail is re-read after say a month from the day it was first read?Wouldn't the time counter be reset for that mail?Instead for the mail to be a month old,it will be just a day old!
I don't know if you get me?
 
Old 10-21-2006, 12:59 AM   #13
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Try mtime instead - I don't imagine reading the file modifies it
 
Old 10-21-2006, 01:24 AM   #14
Sleen
Member
 
Registered: Sep 2005
Location: Kampala,Uganda
Distribution: RHEL,FC,SUSE,UBUNTU
Posts: 41

Original Poster
Rep: Reputation: 15
That may be it.I understand an unread mail has a tag which is changed when the mail is read.That should be the modify time.Even if the mail is re-read,the tag still remains as read.
Thanx.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Qmail Scanner - releasing quarantined mails Twistedlizzard Linux - Software 1 02-06-2006 08:23 AM
wrong date on sent mails using qmail NuLLiFiEd Slackware 3 11-23-2004 04:50 PM
Logging mails sent through Qmail ramnath Programming 1 07-23-2004 07:04 AM
qmail not sending mails spank Linux - Software 0 05-21-2004 12:08 PM
qmail behind nat - can get mails but can't send * i googled ehpserver Linux - Networking 1 10-22-2003 08:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration