We’re converting to Maia Mailguard and one “major” drawback for me and a few other users on our shared email server is that we’re already long time users of SpamAssassin. Now, Amavis uses SA, but it doesn’t use your SA files, so you either lose your long hand crafted whitelist and blacklists, or you enter them one at a time in a web page.
That annoys me.
Because it’s open source, though, I have the opportunity to improve that. And I did. Patches vs 1.0.0rc5 below:
--- wblist.php 2005/09/05 17:09:30 1.1
+++ wblist.php 2005/09/05 17:36:29
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: wblist.php,v 1.1 2005/09/05 17:09:30 root Exp $
+ * $Id: wblist.php,v 1.3 2005/09/05 17:36:22 root Exp $
*
* MAIA MAILGUARD LICENSE v.1.0
*
@@ -117,6 +117,24 @@
</tr>
</table>
+
+<!--- mark added here -->
+<p>
+<table>
+<td class="menubody">
+Enter a batch file to process here
+</td>
+<td><textarea name=batch_wb cols=40 rows=4></textarea></td>
+</tr>
+<tr>
+<td class="menubody" colspan="2" align="center">
+<input type="submit" name="addbatch" value="Add batch to database">
+</td>
+</tr>
+</table>
+<!--- end mark -->
+
+
</div><br>
<?php
@@ -182,4 +200,15 @@
</form>
+<p>
+<center>
+Note: Accepted batch formats are:
+<pre>
+whitelist_from email@host.com
+whitelist email2@host.com
+blacklist_from email3@host.com
+blacklist email4@host.com
+</pre>
+</center>
+
<?php display_html_foot(); ?>
--- xwblist.php 2005/09/05 17:09:44 1.1
+++ xwblist.php 2005/09/05 17:10:40
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: xwblist.php,v 1.1 2005/09/05 17:09:44 root Exp $
+ * $Id: xwblist.php,v 1.2 2005/09/05 17:10:27 root Exp $
*
* MAIA MAILGUARD LICENSE v.1.0
*
@@ -101,6 +101,11 @@
} else {
$newaddr = "";
}
+ if (isset($HTTP_POST_VARS["batch_wb"])) {
+ $batch_wb = trim($HTTP_POST_VARS["batch_wb"]);
+ } else {
+ $batch_wb = “”;
+ }
// User pressed the “Add to List” button to add an address to the
@@ -112,6 +117,63 @@
add_address_to_wb_list($euid, $newaddr, $list);
}
}
+ elseif ( $batch_wb != “” ){
+ if (preg_match(”/(whitelist|whitelist_from)\s+[\w\+\-]+\@[\.\w\+\-]/i”,$batch_wb)
+ ||
+ preg_match(”/(blacklist|blacklist_from)\s+[\w\+\-]+\@[\.\w\+\-]/i”,$batch_wb)){
+ // sa style white list. Process
+ $batch_output_data.=”Processing SA style inputs.<br>\n”;
+ $my_batch_lines=preg_split(”/\n/”,$batch_wb);
+ foreach ($my_batch_lines as $my_line){
+ // ignore comments and empty lines
+ if (preg_match(”/^\s*$/”,$my_line)){
+ continue;
+ }
+ if (preg_match(”/^\s*#/”,$my_line)){
+ continue;
+ }
+
+ $my_wb=”";
+ $data=preg_split(”/\s+/”,$my_line);
+ $data[0]=strtolower($data[0]);
+ if ($data[0] == “whitelist” || $data[0] == “whitelist_from”){
+ $my_wb=”W”;
+ }
+ elseif($data[0]==”blacklist” || $data[0]==”blacklist_from”){
+ $my_wb=”B”;
+ }
+ else{
+ $batch_output_error.= “Error: Can’t parse \”$my_line\”<br> Error: First element not whitelist or blacklist. Skipping.<br>”;
+ continue; // skip, we can’t process this line.
+ }
+ $data[1]=strtolower($data[1]);
+ if (preg_match(”/\*/”,$data[1])){
+ $batch_output_error.= “Error: Skipping email $data[1]. Amvis can not process a wildcard.<br>\n”;
+ continue;
+ }
+
+ // confirm data[1] has what appears to be an email address
+ if (preg_match(”/^[\w\+\.\-]+\@[\.\w\+\-]+$/”,$data[1],$match)){
+ $my_addr=$match[0];
+ }
+ else{
+ $batch_output_error.= “Error: Can’t parse \”$my_line\”<br> Error: Second element not an email. Skipping.<br>”;
+ continue; // skip, we can’t process this line.
+ }
+ // all good. Add.
+ add_address_to_wb_list($euid, $my_addr, $my_wb);
+ $batch_output_data.= “Added <b>$my_addr</b> as a <b>”;
+ if ($my_wb == “W”){
+ $batch_output_data.=”whitelist”;
+ }
+ else{
+ $batch_output_data.= “blacklist”;
+ }
+ $batch_output_data.=”</b><br>\n”;
+
+ }
+ }
+ }
// User pressed the “Update” button to modify the whitelist/blacklist
// settings.
@@ -168,6 +230,17 @@
<tr>
<td class=”messagebox” align=”center”>
+<?php
+if ($batch_output_error != “”){
+ print $batch_output_error;
+ print “<p>\n”;
+}
+if ($batch_output_data != “”){
+ print $batch_output_data;
+ print “<p>\n”;
+}
+?>
+
<?php print($lang_text_lists_updated); ?>
</td>
</tr>
Recent Comments