The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Empty all Junk and Trash

Discussion in 'E-mail Discussions' started by Astral God, Feb 24, 2012.

  1. Astral God

    Astral God Well-Known Member

    Joined:
    Sep 27, 2010
    Messages:
    180
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    127.0.0.1
    cPanel Access Level:
    Root Administrator
    Hi.

    I would like to know if we can, trough command line, empty all Trash and Junk on all mailboxes.
    Thanks.
     
  2. minosjl

    minosjl Well-Known Member

    Joined:
    Jun 4, 2011
    Messages:
    168
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Hi,

    In order to do that you need to write a script:)
     
  3. Silent Ninja

    Silent Ninja Well-Known Member

    Joined:
    Apr 18, 2006
    Messages:
    198
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Buenos Aires, Argentina
    Code:
    #!/bin/sh
    
    for domainhash in `cat /etc/userdomains | grep "\." | sed 's/ //'`
    do
            read domain user <<<$(echo $domainhash | sed 's/:/ /');
            find /home/${user}/mail/${domain}/*/.Trash/{cur,new,tmp}/ -type f | xargs -ifile rm -f file
            find /home/${user}/mail/${domain}/*/.Junk/{cur,new,tmp}/ -type f | xargs -ifile rm -f file
    done
     
  4. Astral God

    Astral God Well-Known Member

    Joined:
    Sep 27, 2010
    Messages:
    180
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    127.0.0.1
    cPanel Access Level:
    Root Administrator
    Hi Silent Ninja.
    Many thanks for this script.

    Any chances to detect only messages with more than 30days before delete ?
     
  5. Silent Ninja

    Silent Ninja Well-Known Member

    Joined:
    Apr 18, 2006
    Messages:
    198
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Buenos Aires, Argentina
    Sure, just before the pipe ( | ) add this to each find: -ctime +30
     
  6. lbeachmike

    lbeachmike Well-Known Member

    Joined:
    Dec 27, 2001
    Messages:
    313
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Long Beach, NY
    cPanel Access Level:
    Root Administrator
    Has anybody tried this script and confirmed it works well and causes no issues?
     
  7. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    I wouldn't suggest using a script to remove data in this manner any way. It would be better to move the data somewhere to archive it, then remove the archive files periodically based on date stamp.

    While I realize this is trash/junk, but if the user wanted it cleared, they would have normally cleared it. There are even purge options in some of the webmail clients and they aren't choosing to use them. As such, it seems possible you might have someone ask later for the data and you could at least explain it initially archived for them and you removed it after 30 days upon archiving, which indicates they had quite some time to ask about the content.
     
  8. rahularora

    rahularora Registered

    Joined:
    Aug 15, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Agree with cPanelTristan. I suggest not to use a command line script since one can clear trash/junk using options in the Webmail itself.
     
  9. lbeachmike

    lbeachmike Well-Known Member

    Joined:
    Dec 27, 2001
    Messages:
    313
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Long Beach, NY
    cPanel Access Level:
    Root Administrator
    A lot of users definitely do not do this. It is probably about half of my users. I find user mailboxes that have something like 200 meg of email in the trash over many years time. This is generally true of my webmail users.
     
  10. lukapaunovic

    lukapaunovic Active Member

    Joined:
    Jul 29, 2012
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Užice, Serbia
    cPanel Access Level:
    Root Administrator
    Can you help me, I have same issue...
    How to empty trash for all users.
     
Loading...

Share This Page