Multiple Spam Folders configured

Post modules, themes or any other code you want to share with the community.

Moderator: Developers

redoonetworks
Posts: 1
Joined: Sat Jun 03, 2017 9:25 am

Multiple Spam Folders configured

Postby redoonetworks » Sat Jun 03, 2017 9:39 am

Hy,

We, like many others I think, connect multiple different (external) mail server to a Group Office.
So there are Plesk and ISPConfig Server.

We have many users, which "complain" about the not working "Mark mail as Spam" Button.
Plesk use a MailDir like INBOX.Junk and Ispconfig only "Junk", which is a problem, because in GroupOffice I was able to only configure one folder. (Regardless there is a call $imap->create_folder, which does nothing in our case.)

So I decided to make the configuration spam_folder optionally to an array.
Now I had:

Code: Select all

$config["spam_folder"]=array("Junk.Anlernen",'INBOX.Junk.Anlernen');

I used the Learn subfolder, because I train the Bayes filter based on this.
The function actionMoveToSpam in MessageController was modified to:

Code: Select all

   protected function actionMoveToSpam($params) {
      
      $accountModel = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
            
      $imap = $accountModel->openImapConnection($params['from_mailbox_name']);
      
      $spamFolder = isset(GO::config()->spam_folder) ? GO::config()->spam_folder : 'Spam';
      
      if(is_array($spamFolder)) {
         $wasAbleToMove = false;
         foreach($spamFolder as $folderName) {
            if(!$imap->get_status($folderName)){
               continue;
            }
            
            if (!$imap->move(array($params['mail_uid']), $folderName)) {
               continue;
            }
            $wasAbleToMove = true;
         }
         if($wasAbleToMove == false) {
            $imap->disconnect();
            throw new \Exception('Could not move message to Junk folders. Does it exist?');
         }
      } else {
         if(!$imap->get_status($spamFolder)){
            $imap->create_folder($spamFolder);
         }
                        
         if (!$imap->move(array($params['mail_uid']), $spamFolder)) {
            $imap->disconnect();
            throw new \Exception('Could not move message to "'.$spamFolder.'" folder. Does it exist?');
         }
      }
      
      $response = array('success'=>true);
      echo json_encode($response);
      
   }


This works and solve my problem. Maybe other users also want to use this or it could merged into Group Office, because the "Built In Multiple Account Feature" is the really USP of Group Office and differ from other solutions.

PS: Do GroupOffice 6 is available on Github? Then I could prepare a Merge Request, because the modification is backwards compatible.

Stefan

Return to “Contributed development”

Who is online

Users browsing this forum: No registered users and 1 guest