In the last article, we talked about how users can create their own email rules to more effectively manage the flow of emails entering their inboxes. However, a situation may arise in which the creation of a mail rule falls on the shoulders of the Carbonio administrator. Such situations include the creation of mail rules in the mailbox of a manager who does not want to waste his time on this, as well as the mass creation of rules of the same type. Their centralized creation eliminates errors on the part of users and, accordingly, avoids the need for additional control and correction of problems that arise. In this article, we’ll cover two ways an administrator can create mail rules for users.
First method – Administrator Panel
The easiest way to create a new mail rule is to log into the Administrator Panel and use the “View Mail” option. Having selected the desired account, click on this button to log in on its behalf and gain access to the user’s web client.
After successful authentication, a mail rule can be created following the instructions from the previous article.
Also, authentication on behalf of the user allows you to manage existing mail rules. For example, delete irrelevant ones or change their order in case of any conflicts caused by mail rules.
The disadvantage of this method is that filters created in this way can be deleted or edited by users.
Second method – Command Line
This method is a little more complicated to implement, but it allows you to make not only specific changes but also automate the process of creating similar mail rules for users, as well as applying them to entire Classes of Service.
Carbonio uses Sieve for administrative filtering of emails. This is a powerful tool that allows the administrator not only to sort emails but also to edit their content. For example, add various warnings to the headers.
By default, the ability to add headers to emails using Sieve in Carbonio CE is disabled. You can enable it, for example, for Service Class:
carbonio prov modifyCos default zimbraSieveEditHeaderEnabled TRUE
Once it is enabled, you can add a new mail rule.
For example, a mail rule that will mark incoming messages from external mail domains with appropriate headers in the source code of the email, as well as words in the subject.
require ["editheader"];
if allof(
not address :domain :is ["from"] ["example.tld", "company.tld", "company.local"]
)
{
addheader "X-External-Domain" "Warning come from external domain";
}
Also, using mail filters, you can impose restrictions on sending emails to domain users, allowing them to be sent only to specific email domains and specific email addresses.
require ["reject", "discard"];
if allof(
address :domain :is ["from"] ["example.tld"],
not address :domain :is ["to"] ["company.tld"],
not address :is ["cc", "to"] ["info@company.local"]
)
{
reject "The company's security policy does not allow sending emails to external email addresses. If you have any questions, please contact support@example.tld.";
stop;
}
In this case, a sender from the example.tld domain who tries to send an email to a domain other than the company.tld domain or info@company.local address will receive a message that this action is unacceptable.
If you replace the reject action with discard in the script, then the rule-violating message will be deleted without any notification.
To use mail rules, you need to save the created Sieve script to a file and apply it at the user, class of service, server, or domain level. When adding an administrative rule, you must indicate exactly when the created rule will be processed – before or after applying user rules.
For example, let’s save the script that adds headers to emails to a file /tmp/header_sieve
.
Then its application at different levels, with the condition that it will be processed before applying custom filters, will be carried out by the commands
cat /tmp/header_sieve |xargs -0 carbonio prov modifyAccount user@example.tld zimbraAdminSieveScriptBefore
cat /tmp/header_sieve |xargs -0 carbonio prov modifyCos default zimbraAdminSieveScriptBefore
cat /tmp/header_sieve |xargs -0 carbonio prov modifyDomain example.tld zimbraAdminSieveScriptBefore
cat /tmp/header_sieve |xargs -0 carbonio prov modifyServer mail.example.tld zimbraAdminSieveScriptBefore
To ensure that Sieve filters are applied after custom mail rules are applied, use the zimbraAdminSieveScriptAfter
parameter
cat /tmp/header_sieve |xargs -0 carbonio prov modifyAccount user@example.tld zimbraAdminSieveScriptAfter
cat /tmp/header_sieve |xargs -0 carbonio prov modifyCos default zimbraAdminSieveScriptAfter
cat /tmp/header_sieve |xargs -0 carbonio prov modifyDomain example.tld zimbraAdminSieveScriptAfter
cat /tmp/header_sieve |xargs -0 carbonio prov modifyServer mail.example.tld zimbraAdminSieveScriptAfter
To remove added rules, use an empty line. Examples:
carbonio prov modifyAccount user@example.tld zimbraAdminSieveScriptBefore ""
carbonio prov modifyAccount user@example.tld zimbraAdminSieveScriptAfter ""
You can also add custom rules in the command line, which will subsequently appear in the list of rules in your account settings and will be available for deletion and editing as if you had done this using the first method using the “View Mail” function.
For example, let’s add a rule to the user that will move any letter that contains the word bitcoin to the trash.
zmmailbox -z -m user@example.tld addFilterRule -f "BITCOIN" active all body contains "bitcoin" fileinto "Trash"
This rule moves any email that mentions the word bitcoin to the trash, and the -f parameter means that it will be first in the list of active mail rules.
zmmailbox -z -m user@example.tld addFilterRule -l "BITCOIN" active all body contains "bitcoin" fileinto "Trash"
This rule also moves any email that mentions the word bitcoin to the trash, and the -l parameter means it will be last in the list of active mail rules.
Thus, Carbonio’s built-in email filtering tool not only allows you to effectively manage message flows but also protect users from receiving unwanted email and warn them about possible dangers.