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.

Any script can clear spam box automatically ?

Discussion in 'General Discussion' started by jameshsi, Dec 21, 2005.

  1. jameshsi

    jameshsi Well-Known Member

    Joined:
    Oct 22, 2001
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    HI! Pal:
    Is there any script can do this for me ?
    Set a crontab job and it can clear the users who had actived the spam box for us, if you have made a script like this for yourself can you let me have it ?

    Thanks and Merry X'mas.
     
  2. jameshsi

    jameshsi Well-Known Member

    Joined:
    Oct 22, 2001
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    ANybody can help ?
     
  3. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    The very nature of the spambox is to have it set to delete after a certain peiod of time, making any cron or such not needed as it is handled on a per mail account basis.
     
  4. WebScHoLaR

    WebScHoLaR Well-Known Member

    Joined:
    Dec 14, 2005
    Messages:
    511
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Planet Earth
    You can setup a cron job as mentioned below to clear the spam box for the email accounts.

    > /home/username/mail/domain.com/emailaccount/spam
     
  5. pphillips

    pphillips Well-Known Member

    Joined:
    Nov 14, 2003
    Messages:
    71
    Likes Received:
    0
    Trophy Points:
    6
    To dump spam automatically domain wide you can run a script I wrote via cron. You can download the latest copy of it at http://www.phillipsdata.com/phpscripts/dumpspam.txt

    Here is the code as of this writing:

    PHP:
    #!/usr/bin/php -q
    <?

    /*
    *  Written by Paul Phillips, phillipsdata.com
    *  Distribute or modify freely, but please give me credit for this code in any 
    *  derivative works. Please do not remove these comments.
    */

    function dumpallspam() {
        $domain = "yourdomain.com";
        $cpaneluser = "yourcpaneluser";
        $cpanelpass = "yourcpanelpass";
        $cpaneltheme= "x"; // The cpanel theme used. in the url it appears after :2082/frontend/ <-- here

        // First do a check if curl_init exists:
        if (function_exists("curl_init")) {
            $authstr = "$cpaneluser:$cpanelpass";

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $domain . ":2082/frontend/" . $cpaneltheme . "/mail/clearspambox.html?");
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_USERPWD, $authstr);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

            $cbsreturn = curl_exec($ch);
            //echo "Result: " . $cbsreturn; // Returns all the html from cpanel, uncomment to view
            //die;
            if (strpos($cbsreturn, "spambox has been cleared")) {
                return true;
            } else {
                return false;
            }

            // debug echo curl_error($ch);
            curl_close($ch);
        }
    }

    if (dumpallspam()) {
        // dont echo anything if via cron cause we dont want emails! echo "Dumped spam ok";
    } else {
        echo "problem dumping spam, check the settings!";
    }

    ?>
    Enjoy!
     
  6. mahinder

    mahinder Well-Known Member

    Joined:
    Jun 12, 2003
    Messages:
    68
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    matrix
    is there any script which can do this server wide ?
     
  7. pphillips

    pphillips Well-Known Member

    Joined:
    Nov 14, 2003
    Messages:
    71
    Likes Received:
    0
    Trophy Points:
    6
    That's a good question. I think it can be done with each domains username and the root password. We would just need to loop through what we do now in the script I posted with an array of every username on the server. We could probably read the quotas file on the server to get this list of usernames. The script would need to be run from cron via root user.

    I don't have the time to code something like this for free at the moment, but I would be willing to do this for money.
     
  8. bmcgrail

    bmcgrail Well-Known Member

    Joined:
    Dec 8, 2003
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    6
    Below is a simple script I made to find all spam folders on my server and remove any messages 7 days or older. You can easily change it to 30 days if you wish.

    This script is for Maildir. If you are running mbox this will not work.

    create a file called /root/del_spam (or whatever you like)
    Add the following to the file

    Code:
    #/bin/sh
    /usr/bin/find /home/*/mail/*/*/.spam/*/ -type f -ctime +6 | xargs /bin/rm -v
    
    The -v will output a list of all files removed. Good for testing. You can take out at a later time. run without | xargs /bin/rm to see what files are found without removing them.

    How it works: The find command looks for Maildir Spam as stored in:
    /home/account/mail/domainname/username/.spam/(cur | new)/file
    /home/*......../mail/*.............../*.........../.spam/*

    Run nightly from cron

    # crontab -e
    10 0 * * * /root/del_spam
     
  9. jameshsi

    jameshsi Well-Known Member

    Joined:
    Oct 22, 2001
    Messages:
    347
    Likes Received:
    0
    Trophy Points:
    16
    Thanks a lot, but my problem is, most people forget to delete and their quota been used up, so, I do it below:

    Code:
    
    #/bin/sh
    /usr/bin/find /home/*/mail/*/*/spam -type f  -size +12000k | xargs /bin/rm -v
    
    
     
Loading...

Share This Page