UAPI store_filter doesn't create filter.yaml for email user

ipublicis

Member
Apr 27, 2018
10
2
3
Lisboa, Portugal
cPanel Access Level
Root Administrator
I'm having a problem creating SPAM filters when creating new email users.

I use the following code:

private function addFilters($completeMail, $email) {

$this->cPanel->uapi->Email->add_spam_filter([ "account" => $completeMail ]);

$this->cPanel->uapi->Email->store_filter([
'filtername' => 'SPAM',
'account' => $completeMail,
'action1' => 'save',
'dest1' => '$home/mail/quercus.pt/'.$email.'/.spam',
'part1' => '$h_X-Spam-Status:',
'match1' => 'begins with',
'val1' => 'Yes',
'opt1' => 'or',
'part2' => '$h_X-Spam-Score:',
'match2' => 'is above',
'val2' => '4',
'opt2' => 'or',
'part3' => '$h_X-Spam-Bar:',
'match3' => 'contains',
'val3' => '++++'
]);
}

Assuming $completeMail = [email protected] and $email = teste21:
  1. the .spam folder is not generated
  2. This is the contents of
    cat /home/username/etc/mydomain.com/teste21/filter.yaml
    ---
    filter: []

    max_allowed_spam_score: 5
    version: '2.2'
What is missing here?

Thanks in advance.
 
Last edited:

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
Hello @ipublicis,

Can you confirm if your aim is to automatically setup a SPAM folder when new email accounts are created? If so, cPanel & WHM version 80 includes a new feature to do this for you. The following section of the cPanel & WHM Version 80 Release Notes explains how it works:

Enable SpamBox by default on new cPanel account creation
We added the Enable Spam Box option in WHM's Create a New Account interface (WHM >> Home >> Account Functions >> Create a New Account). When you create a new account, the system enables this option by default. This makes the process of keeping spam out of your users' inboxes much easier.

Notes:
  • You must enable Apache SpamAssassin™ to use this feature.
  • When you disable this setting, the system will deliver messages marked as spam to the user's inbox.
  • When you upgrade to cPanel & WHM version 80, the system creates spam folders for all existing email accounts that do not have them. This action ensures that users do not need to log into IMAP to create and subscribe to the spam folder.
Since the update to version 80 will automatically create spam folders for all existing email accounts that do not already have them, you won't have to setup a post email account creation hook for this purpose.

Note that cPanel & WHM Version 80 is currently published to the EDGE release tier and is not yet ready for production servers. You can read about release tiers and release schedules on the following document:

Product Versions and the Release Process - cPanel Knowledge Base - cPanel Documentation

Let me know if this helps.

Thank you.
 

ipublicis

Member
Apr 27, 2018
10
2
3
Lisboa, Portugal
cPanel Access Level
Root Administrator
Hi @Michael,

Can you confirm if your aim is to automatically setup a SPAM folder when new email accounts are created?
Yes. I want to create a SPAM folder and also to filter all incomming SPAM to be delivered to that folder.

Since the update to version 80 will automatically create spam folders for all existing email accounts that do not already have them, you won't have to setup a post email account creation hook for this purpose.
We use on the server the version 78 -- and I don't control that -- so I do need to create it and to activate the filters :)

Thank you.
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
We use on the server the version 78 -- and I don't control that -- so I do need to create it and to activate the filters
Hello @ipublicis,

Can you open a support ticket so we can take a closer look and see why the store_filter UAPI function isn't properly storing the filter rules? You can post the ticket number here and we'll link this thread to it.

Thank you.