How to use exim variables in filters

mcowper

Registered
Mar 12, 2013
3
1
3
cPanel Access Level
DataCenter Provider
I'm trying to create an account-level filter that will match any email where the from address and the to address are the same. My approach was to check if the from header matched the to header using the exim variable $header_to. I created this through the web interface and tested it and it didn't work. After some experimenting and research I found that the filter that is created that way is actually in /etc/vfilters/<domain>. Looking at that file I found that the '$' is escaped by '\\', which is not what I want. I can modify that file by removing the '\\' and the filter works as I expect, however that file will be overwritten. Is there a way to do it so that the '$' is not escaped?

Here is what is put in the file by the cPanel interface:
Code:
#Test
if
 $header_from: contains "\\$header_to"
then
 if error_message then save "/dev/null" 660 else fail "Don't send email to myself" endif
endif
Here is what works the way that I want:
Code:
#Test
if
 $header_from: contains "$header_to"
then
 if error_message then save "/dev/null" 660 else fail "Don't send email to myself" endif
endif
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello @mcowper,

Can you use our Defects link so we can take a closer look and verify if this is a defect with the way filter rules are added? You can post the ticket number here once it's open and we'll link this thread to it.

Thank you.
 

mcowper

Registered
Mar 12, 2013
3
1
3
cPanel Access Level
DataCenter Provider
I understand that there is no way around this currently using cPanel. I will be putting in a feature request. In the meantime this is the solution that I came up with in case anybody else runs into this.

I installed incron on the server. It is a daemon similar to cron that runs commands on filesystem events rather than time events. I then created an incrontab entry for the user that contained the following line:
Code:
/etc/vfilters/<domain> IN_MODIFY echo '%s/\\//g|w|q' | ex - /etc/vfilters/<domain>
That removes the '\\' from the file every time cPanel adds it.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello @mcowper,

Thank you for submitting the ticket and sharing the workaround. Let me the feature request URL once it's opened and I'll link it to the internal case noted below.

Internal case CPANEL-27301 was opened to request an improvement to the filter creation UI in cPanel so that Exim variables are supported as values.

Thank you.