ISPConfig3 automate Sent, Junk, Drafts folders

Discussion in 'Tips/Tricks/Mods' started by ihamouda, Feb 13, 2009.

  1. ihamouda

    ihamouda New Member

    Could somebody put me on the right direction.
    I want to automate the creation of some IMAP folders with the creation of the email account.
    I'm using ISPConfig3
    I know some php, and I know maildirmake.
    I just need to know which file to modify and around which line number

    Thanks
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Take a look in the file /usr/local/ispconfig/server/plugins-enabled/mail_plugin.inc.php
     
  3. andypl

    andypl Member

    I do not know the way to PHP and so I wanted to find out
    what to add in this file to the newly created email account have directory
    .Spam
     
  4. rdv25772

    rdv25772 New Member

    Look and learn from excisting code

    I learn by looking at code already used and alternate it as I would like to use it. I tried also to find out how something is working.

    You might to look into the file /usr/local/ispconfig/server/plugins-enabled/mail_plugin.inc.php as Till stated and see how the Sent, Junk and Drafts folders are created. I will do the same.

    Good luck
     
  5. andypl

    andypl Member

    I added these two lines to function user_insert

    Code:
                            
    exec('mkdir -p '.escapeshellcmd($data['new']['maildir']).'/.Spam');
    exec('mkdir -p '.escapeshellcmd($data['new']['maildir']).'/.NoSpam');
    

    Code:
    //* Create the maildir, if it doesn not exist, set permissions, set quota.
                    if(!empty($maildomain_path) && !is_dir($maildomain_path)) {
                            exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
                            exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir']));
                            $app->log("Set ownership on ".escapeshellcmd($data['new']['maildir']),LOGLEVEL_DEBUG);
                            //* Create .Spam and .NoSpam folder
                            exec('mkdir -p '.escapeshellcmd($data['new']['maildir']).'/.Spam');
                            exec('mkdir -p '.escapeshellcmd($data['new']['maildir']).'/.NoSpam');
                            //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
                            exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota b$
                            $app->log('Created Maildir: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLE$
    but there does not create any directories.
     
  6. ihamouda

    ihamouda New Member

    you need to add the maildirmake command not the mkdir command like the follwoing:

    to add a .Spam folder use the -f option and don't forget the su -c surrounding the whole command


    exec("su -c 'maildirmake -f Spam ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
     
  7. andypl

    andypl Member

    Still not working.

    Code:
            function user_insert($event_name,$data) {
                    global $app, $conf;
    
                    //* get the config
                    $app->uses("getconf");
                    $mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail');
    
                    $maildomain_path = $data['new']['maildir'];
                    $tmp_basepath = $data['new']['maildir'];
                    $tmp_basepath_parts = explode('/',$tmp_basepath);
                    unset($tmp_basepath_parts[count($tmp_basepath_parts)-1]);
                    $base_path = implode('/',$tmp_basepath_parts);
    
                    //* Create the mail domain directory, if it does not exist
                    if(!empty($base_path) && !is_dir($base_path)) {
                            exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']);
                            $app->log('Created Directory: '.$base_path,LOGLEVEL_DEBUG);
                    }
    
                    //* Create the maildir, if it doesn not exist, set permissions, set quota.
                    if(!empty($maildomain_path) && !is_dir($maildomain_path)) {
                            exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
                    //* Create .Spam and .NoSpam folder
                            exec("su -c 'maildirmake -f Spam ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
                            exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir']));
                            $app->log("Set ownership on ".escapeshellcmd($data['new']['maildir']),LOGLEVEL_DEBUG);
                            //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
                            exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota b$
                            $app->log('Created Maildir: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLE$
                    }
    
                    //* Set the maildir quota
                    exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']);
                    $app->log('Set Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name'],LOGL$
            }
    
     
  8. ihamouda

    ihamouda New Member

    Re ; still not working

    here is it, cut and paste from my working file:
    Code:
    if(!empty($maildomain_path) && !is_dir($maildomain_path)) {
    			exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
    			exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
    			exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
    			exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
    			exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir']));
    			$app->log("Set ownership on ".escapeshellcmd($data['new']['maildir']),LOGLEVEL_DEBUG);
    			//* This is to fix the maildrop quota not being rebuilt after the quota is changed.
    			exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota bug, see debian bug #214911
    			$app->log('Created Maildir: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
    		}
    
     
  9. Ovidiu

    Ovidiu Active Member

    looks good, but how do you get ispcfg3 to deliver spam into the Junk folder? :)
     
  10. ihamouda

    ihamouda New Member

    Re: Spam filter

    If your spam is tagged in the subject, let's say your subject contains ***SPAM***, yo can just create a domain wide filter from the ISPConfig 3 interface to move to the .Junk
     
  11. Ovidiu

    Ovidiu Active Member

    sounds all like good advice, still 2 more questions:

    - can't find a domain wide filter, only the mailboxes seem to have a fitler attached, I wouldn't want to set this filter up for every emailbox manually or am I just not seeing the right place to put the filter?
    - modifying /usr/local/ispconfig/server/plugins-enabled/mail_plugin.inc.php accordingly to your file, when is this applied? how to apply it retroactively to existing mailboxes?
     
  12. OnePercentile

    OnePercentile New Member

    still not working

    I've used this information. It looks good, but when creating a new email account no "Junk" folder appears within SquirrelMail .. Additionally, there appears to be no domain filter rule. Am I missing something? This thread seems to have died with no resolution. Thanks
    Jordan

     
  13. jbryner

    jbryner New Member

    I'd love to add this, but after looking at mail_plugin.inc.php, I am at a little bit of a loss about where to put it and what to replace. I found reference to create mailbox, but... Any help you could give me would be great. My apologies for not being quite up to speed on php. Am learning (slowly)
     
  14. int0x21

    int0x21 New Member

    Im having a little trouble with the filter
    How would a filter look to make something tagged with ***SPAM*** end up in .Spam folder
     
  15. radim_h

    radim_h Member HowtoForge Supporter

    Seems simple but it doesnt work for me folders are not created :(

    Nothing in ispc debug log:
    04.10.2009-19:47 - DEBUG - Set Lock: /usr/local/ispconfig/server/temp/.ispconfig_lock
    04.10.2009-19:47 - DEBUG - Found 2 changes, starting update process.
    04.10.2009-19:47 - DEBUG - Processed datalog_id 801
    04.10.2009-19:47 - DEBUG - Processed datalog_id 802
    04.10.2009-19:47 - DEBUG - Remove Lock: /usr/local/ispconfig/server/temp/.ispconfig_lock


     
    Last edited: Oct 4, 2009
  16. radim_h

    radim_h Member HowtoForge Supporter

    and one more question, please..

    in original script /usr/local/ispconfig/server/plugins-enabled/mail_plugin.inc.php

    there are two same blocks starting with:

    //* Create the maildir, if it doesn not exist, set permissions, set quota.
    if(!empty($maildomain_path) && !is_dir($maildomain_path)) {
    exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);


    At line 105

    And line 156

    Are you modyfying both of them ??
     
  17. radim_h

    radim_h Member HowtoForge Supporter

    no one has any idea, what's wrong? :(
     
  18. radim_h

    radim_h Member HowtoForge Supporter

Share This Page