Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Empty all Junk and Trash

Discussion in 'E-mail Discussion' 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:
    66
    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:
    66
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Hi,

    In order to do that you need to write a script:)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Silent Ninja

    Silent Ninja Well-Known Member

    Joined:
    Apr 18, 2006
    Messages:
    196
    Likes Received:
    0
    Trophy Points:
    166
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Astral God

    Astral God Well-Known Member

    Joined:
    Sep 27, 2010
    Messages:
    180
    Likes Received:
    0
    Trophy Points:
    66
    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:
    196
    Likes Received:
    0
    Trophy Points:
    166
    Location:
    Buenos Aires, Argentina
    Sure, just before the pipe ( | ) add this to each find: -ctime +30
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. lbeachmike

    lbeachmike Well-Known Member

    Joined:
    Dec 27, 2001
    Messages:
    306
    Likes Received:
    1
    Trophy Points:
    316
    Location:
    Long Beach, NY
    cPanel Access Level:
    Root Administrator
    Has anybody tried this script and confirmed it works well and causes no issues?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,608
    Likes Received:
    32
    Trophy Points:
    238
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  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:
    306
    Likes Received:
    1
    Trophy Points:
    316
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    Kent Brockman likes this.
  10. lukapaunovic

    lukapaunovic Active Member

    Joined:
    Jul 29, 2012
    Messages:
    38
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice