I was trying to do a simple find/replace operation on a header and ran
into an issue.
The solution might help others and perhaps there would be a better way
to solve.
So. I'm sharing....
Our system allows the system admin to define a string template for how
the Subject header in Spam messages should be tagged...
Simplest version of that template is:
[***SPAM***] @@SUBJ@@
And our code simply replaces @@SUBJ@@ with the actual subject.
Since that marker could be anywhere in the template, I needed to have
a simple find/replace and the closest I could come up with was to use
sg{} like so:
set acl_m_temp_text = ${extract{spam_tag_subject}
{$acl_c_system_prefs}{$value}{@@SUBJ@@}}
set acl_c_temp_text = ${sg{$acl_c_temp_text}{@@SUBJ@@}{$h_Subject:}}
and that would work. Most of the time.
However, I found some errors with that when the subject contained a $
like this one:
T="The electronic products the factory directly sells: laptop, LCD
TV, camera ,mobile,Mp4, GPS\033$B!$\033(Band so on."
and exim would complain like so:
failed to expand ACL string "${sg{$acl_m_temp_text}{\N@@SUBJ@@\N}
{$h_Subject:}}": unknown variable name "B"
so, I devised an simpler method:
set acl_m_temp_text = ${extract{spam_tag_subject}
{$acl_c_system_prefs}{$value}{@@SUBJ@@}}
set acl_m_temp_text = ${sg{$acl_m_temp_text}{\N^(.*)@@SUBJ@@(.*)$\N}
{\$1\n\$2}}
This puts whatever was before the SUBJ marker into line 1 and whatever
was after into line 2 of the temp variable.
Then... we simply concatenate:
set acl_m_temp_text = ${extract{1}{\n}{$acl_m_temp_text}}\
$h_Subject:${extract{2}{\n}{$acl_m_temp_text}}
(line 1 of temp)(Subject header)(line 2 of temp)
and then we use the ubiquitous:
add_header = X-New-Subject: $acl_m_temp_text
This also is more secure in that the code is no longer running Email
Data through the regular expression, but merely breaking apart a
string which I can control inputs for through the web admin interface.
Regards,
Brian