<!--%%INCLUDE "i_defaulthead.incl" ("PolluStop custom rules")-->
   <form action="regex" method="post">


   <fieldset><legend><select class="ed" name="m_useregex"><!--%%BOOLMENU settings.m_useregex DEFAULT defaultsettings.m_useregex DISPLAY enabledisable--></select> regular expressions</legend>

   <p class="explain">Regular expressions can be entered to add custom rules to the spam filter. These regular expressions are matched against the message <strong>line by line</strong>, so multi-line regex or regex containing \n characters are useless.</p>
   <p class="explain">These are Perl or Javascript regular expressions, without the / / delimiters. Regex flags (cgimosx) are not allowed, except the "ignore case" one which can be set with the checkbox.</p>
   <p class="explain">Each regex has a name/comment field to identify it. The name of matched regex can be inserted in the message headers if desired. The Value field is the value added or subtracted from the message score if the regex is matched. Each regex can only be matched once per message. Once a regex has been matched it is disabled for the remaining text of the message.</p>
   <p class="explain">The regex are currently matched against the mime-decoded text of the message, including headers, text/plain and text/html parts. Base64 and quoted-printable is decoded before regex are matched, but the original character set (utf-8, iso-8859-x, gb2312, etc) is kept. Basically, the regex must be the ascii representation of this character set (for instance, the character "&eacute;" from an utf-8 message would be represented as "&Atilde;&copy;").</p>
   <p class="explain">Note: Due to multiple internal rules applying, the message score may be over 1.0 or below 0 before these rules are matched. Any score over 1.0 is displayed as 1.0, so subtracting 1.0 from the message score may still result in a message marked as spam. This is why the Value drop-down has "Whitelist" and "Blacklist" entries, which will make sure the message get the appropriate final score.</p>
   <fieldset><legend><select class="ed" name="m_logregex"><!--%%BOOLMENU settings.m_logregex DEFAULT defaultsettings.m_logregex DISPLAY enabledisable--></select> matched regex display in message headers</legend>
      <p class="explain">When a regular expression is matched against a message, PolluStop can add the regex' name to the message headers.</p>
      <p class="explain">There will be one header per matched regex, in the form <span style="font-family:courier new; font-weight:bold;">X-PolluStop-Regex-Match: [name]</span>.</p>
   </fieldset>

   <fieldset><legend>Regex load report</legend>

<!--%%IF zzz-->
   <p class="explain">Be careful not to overload your server by installing too many or too complex regular expressions. You can get a report of the additional load your regex will incur, but this report is only a guess, since regex processing time varies in function of the message.</p>
   <p class="explain">Make sure to save your regex before creating the report. The Report button does not save the regex and the page will be reloaded, any unsaved regex will be lost.</p>
   <!--%%IF EXISTS(report)-->
   <p style="padding:6px; border:1px solid black; background-color:yellow;">%%report%%</p>
   <!--%%ENDIF-->
   <p><input type="button" onclick="window.location.replace('regex?report=')" name="Report" value="Report" /></p>
   </fieldset>
<!--%%ENDIF-->

   <!--%%IF settings.updateserverregex-->
   <fieldset><legend>Shared regular expressions</legend>
      <p class="explain">These Regular Expressions are provided and updated by Niversoft, and <a href="upgrade">automatically downloaded</a> by PolluStop periodically.</p>
      <!--%%IF settings.hasserverregex--><!--%%IF settings.reportserverregexusage-->
      <p class="explain">Usage data of these regular expressions will be sent back to Niversoft. See the <a href="upgrade">software updates</a> page for more informations.</p><!--%%ENDIF-->
      <table class="regex server" style="width:100%"><col width="20" /><col width="150" /><col /><col width="25" /><col width="20" />
         <tr><th></th><th>Name</th><th>Regular expression</th><th>Value</th><th>Usage</th></tr><!--%%FORALL regex IN settings.serverregex-->
         <tr>
            <td style="text-align:center"><input %%CHECKED(NOT(regex[].disabled))%% type="checkbox" onclick="this.nextSibling.disabled = this.checked" /><input name="serv_regex" value="%%HTML:regex[].name%%" <!--%%IF NOT(regex[].disabled)-->disabled="disabled"<!--%%ENDIF--> type="hidden" /></td>
            <td><input style="width:100%;" readonly="readonly" value="%%HTML:regex[].name%%" type="text" /></td>
            <td><input style="width:100%;" readonly="readonly" value="%%HTML:regex[].regex%%" type="text" /></td>
            <td>%%TRANSLATE(regex[].value USING DICTIONARY("regexscoresdisp"))%%</td>
            <td>&nbsp;(<!--%%IF CONTAINS(regex[].name IN DICTIONARY("regexusage"))-->%%TRANSLATE(regex[].name USING DICTIONARY("regexusage"))%%<!--%%ELSE-->0<!--%%ENDIF-->)</td>
         </tr>
         <!--%%ENDFOR regex-->
      </table>
      <input type="submit" name="Apply" value="Save changes" onclick="return VerifySyntax(false, false) ? true : VerifySyntax(true, true);"/>
      <!--%%ELSE-->
      <p class="errors">Note: These regex definitions are available only for servers with a valid maintenance contract.</p>
      <!--%%ENDIF-->
   </fieldset>
   <!--%%ENDIF-->

   <fieldset><legend>Regular expressions</legend><!--%%IF settings.updateserverregex & settings.reportuserregexusage-->
      <p class="explain">Usage data of these regular expressions will be sent back to Niversoft. See the <a href="upgrade">software updates</a> page for more informations.</p><!--%%ENDIF-->
      <p class="explain">* Usage column: Number of times the regex matched a message since last <a href="statistics">statistics</a> reset.</p>
      <table class="regex" style="width:100%"><col width="120" /><col /><col width="25" /><col width="50" /><col width="20" /><col width="20" />
         <tr><th>Name</th><th>Regular expression</th><th style="text-align:center">i</th><th>Value</th><th></th><th>Usage *</th></tr><!--%%FORALL regex IN settings.userregex-->
         <tr>
            <td><input name="num" value="%%INDEX:regex%%" type="hidden" /><input name="name_%%INDEX:regex%%" value="%%HTML:regex[].name%%" type="text" /></td>
            <td><input style="width:100%" name="regex_%%INDEX:regex%%" value="%%HTML:regex[].regex%%" type="text" onblur="VerifyRegex(this)" /></td>
            <td style="text-align:center"><input name="nocase_%%INDEX:regex%%" value="1" %%CHECKED(regex[].nocase)%% type="checkbox" /></td>
            <td><select name="value_%%INDEX:regex%%" class="nw"><!--%%ENUMMENU regex[].value DEFAULT "999" in regexscores DISPLAY regexscoresdisp--></select></td>
            <td class="link" onclick="DelRow(this)">delete</td>
            <td>&nbsp;(<!--%%IF CONTAINS(regex[].name IN DICTIONARY("regexusage"))-->%%TRANSLATE(regex[].name USING DICTIONARY("regexusage"))%%<!--%%ELSE-->0<!--%%ENDIF-->)</td>
         </tr>
         <!--%%ENDFOR regex-->
         <tr id="obj_template">
            <td><input name="num" value="xxx" type="hidden" /><input name="name_xxx" value="" type="text" /></td>
            <td><input style="width:100%" name="regex_xxx" value="" type="text" /></td>
            <td style="text-align:center"><input name="nocase_xxx" value="1" checked="checked" type="checkbox" /></td>
            <td><select name="value_xxx" class="nw"><!--%%ENUMMENU "999" DEFAULT "999" in regexscores DISPLAY regexscoresdisp--></select></td>
            <td class="link" onclick="DelRow(this)">delete</td>
            <td></td>
         </tr>
      </table>
      <div class="link" onclick="AddRow(this)">Add regex</div>

      <p><input type="button" value="Verify regex syntax" onclick="VerifySyntax(false, true)" />
         <input type="submit" name="Apply" value="Save regex" onclick="return VerifySyntax(false, false) ? true : VerifySyntax(true, true);"/>
         <input type="submit" name="ClearStats" style="float:right" value="Save regex and Clear usage stats" onclick="return VerifySyntax(false, false) ? true : VerifySyntax(true, true);"/>
      </p>

   </fieldset>

   <fieldset><legend>Test regular expressions</legend>
      <p class="explain">Test your regular expressions on your text. This test will use the entered regex above, not the ones already saved. You can perform this test before saving the regex, the test will be performed using javascript and the page will not reload. This test is slower than the real processing.</p>
      <p class="errors">Note: for this test, the text is taken as-is, it is not MIME-decoded before being processed by the regex.</p>
      <p><textarea id="customtext" cols="80" rows="10"></textarea></p>
      <p id="testresults"></p>
      <p><input type="button" value="Test" onclick="MatchRegex()" /></p>
   </fieldset>

   </fieldset>
   </form>
<!--%%INCLUDE "i_defaultfoot.incl"-->