Auto prune old emails

Discussion in 'Installation/Configuration' started by sajo, Nov 10, 2006.

  1. sajo

    sajo New Member

    I look over the forum and I do search but didnt find what I was looking for.
    So I would like to do automatic monthly prune of old emails of my customers.
    For example.
    I would like to automaticaly delete mails that are older than 6 months and which are in junk, trash and inbox folders, not deleting mails in other folders.
    Is that possible and how.
    I am new to linux so I would need detailed how to.
    I am using ubuntu server 6.10 installed by this Falko how to http://www.howtoforge.com/perfect_setup_ubuntu_6.10

    Thanks in advance
     
  2. falko

    falko Super Moderator ISPConfig Developer

  3. sajo

    sajo New Member

    Thanks Falko
    So if I understand right then I make cron that will run once every month and the script should look like this

    Code:
    #!/bin/sh
    
    for file in "$( /usr/bin/find /.junk -type f -mtime +90 )"
    for file in "$( /usr/bin/find /.inbox -type f -mtime +90 )"
    for file in "$( /usr/bin/find /.trash -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    exit 0
    Am I right?
    This script will look over the whole system to find this folders (junk, inbox,trash)and in those folders that are found, will remove files that are older than 90 days?
     
  4. falko

    falko Super Moderator ISPConfig Developer

    The script should look like this:

    Code:
    #!/bin/sh
    
    for file in "$( /usr/bin/find /.junk -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /.inbox -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /.trash -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    exit 0
    Also, are you sure that /.junk, /.inbox, and /.trash are the correct folders?
     
  5. sajo

    sajo New Member

    Not shure...
    emails are in

    /var/www/webXX/user/XXX/Maildir/cur There are already read emails
    /var/www/webXX/user/XXX/Maildir/new There are unread emails
    /var/www/webXX/user/XXX/Maildir/.Junk/cur There are junk-spam emails
    /var/www/webXX/user/XXX/Maildir/.Trash/cur There are trash emails
    /var/www/webXX/user/XXX/Maildir/.Sent/cur There are sent emails

    So do yu think that kode shold look like this

    Code:
    #!/bin/sh
    
    
    for file in "$( /usr/bin/find /Maildir/cur -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /Maildir/new -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /Maildir/.Junk/cur -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /Maildir/.Trash/cur -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /Maildir/.Sent/cur -type f -mtime +90 )"
    do
      rm -f $file
    done
    
    exit 0
     
  6. falko

    falko Super Moderator ISPConfig Developer

    You must use /var/www/webXX/user/XXX/Maildir/cur then instead of /Maildir/cur, and so on.
     
  7. sajo

    sajo New Member

    That would be difficult, because I have about 27 domains and each domain has about 15 emails, so I cant write that for ever user, because there can be new email user any minut and I will not be notified about new user and I would like to automate that prune system.
    Isnt there a way that system will look for all subfolders by that name and search files in that folders that are older than XX days?
     
  8. falko

    falko Super Moderator ISPConfig Developer

    You can try to use wildcards, e.g. /var/www/web*/user/*/Maildir/cur, but I haven't tested this.
     
  9. sajo

    sajo New Member

    OK

    I try this tomorow. We will see then.
     
  10. sajo

    sajo New Member

    Okey

    I try the script and wildcarts works :D

    But there is other problem, I have luck that I tested on test box :eek:
    Wel this is what happens.
    When I run the scrip the script did search for folders and also the files but script delete all never files until date I put in in my case that was 28 of october so I have no new files but files older than 17days, stays in folders.

    and that is the script I use

    Code:
    #!/bin/sh
    
    
    for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/cur -type f -mtime +17 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/new -type f -mtime +17 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/.Junk/cur -type f -mtime +17 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/.Trash/cur -type f -mtime +17 )"
    do
      rm -f $file
    done
    
    for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/.Sent/cur -type f -mtime +17 )"
    do
      rm -f $file
    done
    
    exit 0
    I tested on debian sarge, I belive on Ubuntu 6.10 is the same thing. Because Ubuntu 6.10 is in my production box.
     
  11. falko

    falko Super Moderator ISPConfig Developer

    Sorry, I don't understand the problem... :confused:
     
  12. sajo

    sajo New Member

    To tell shortly

    Script delete new mails and not old, it work in reverse mode than I want to
     
  13. falko

    falko Super Moderator ISPConfig Developer

    Then try
    Code:
    /usr/bin/find /var/www/web*/user/*/Maildir/cur -type f -mtime [B][COLOR="Red"]-[/COLOR][/B]17
    instead of
    Code:
    /usr/bin/find /var/www/web*/user/*/Maildir/cur -type f -mtime [B][COLOR="Red"]+[/COLOR][/B]17
    Also have a look at
    Code:
    man find
     
  14. sajo

    sajo New Member

    I try - and + but, Its the same old files stays new were deleted. I did read man find, but dontknow how to help with that, I am not a programer so that is s little problem for me. But I saw there something about prune but didnt understand well. Could you help me.
     
  15. sajo

    sajo New Member

    OKey I did it :)

    I use this script

    Code:
    #!/bin/sh
    
    find /var/www/web*/user/*/Maildir/cur -type f -mtime +90 | xargs rm -f
    
    find /var/www/web*/user/*/Maildir/new -type f -mtime +90 | xargs rm -f
    
    find /var/www/web*/user/*/Maildir/.Junk/cur -type f -mtime +90 | xargs rm -f
    
    find /var/www/web*/user/*/Maildir/.Junk/new -type f -mtime +90 | xargs rm -f
    
    find /var/www/web*/user/*/Maildir/.Trash/cur -type f -mtime +90 | xargs rm -f
    
    find /var/www/web*/user/*/Maildir/.Sent/cur -type f -mtime +90 | xargs rm -f
    
     exit 0
    
    And dont forget to make executable file ;) I name it mailprune.sh, then I make crontab that run once a month
    Code:
    crontab -e
    Code:
     * * 1 * * /path/to/yourscript
    I wrote that if someone would need that also, and dont know how to do it.

    Thanks for your help Falko.
     
  16. xrstokes

    xrstokes New Member

    Is there a line I can put at the end of the script to recalculate the quota's, they don't appear to be refreshing?
     

Share This Page