If you’re a Dreamhost customer and is willing to add too many filters rules to your mail accounts, then you’re lost! Currently, Dreamhost only allows you to add filters criteria five by five, what is a pain in the ass if you have hundreds of rules.

@noAlvaro asked for help at Dreamhost’s support channel and was pointed to open a feature request to enlarge this limit, but he ended up on a never ending queue of new features request, subjected to community voting. Doing the maths, it will never happen.

If you have this same problem, then maybe you could try using the script below. IMPORTANT: this is a hypothetical solution, use this script by your own risk. You need a browser with a console compatible to Firebug, like Chrome, Firefox, IE9 or Safari.

The script basically iteratively send GET requests Dreamhost’s servers adding rule by rule. All you have to do is modify the array of rules (RULES) to list the rules you want to add. For each rule you must have 4 elements in the array, respectively being the “field”, “contains/no-contains”, “criteria” and “folder to move”. The valid values for field are “from”, “to”, “reply-to”, “headers”, “cc”, “body” or “subject”, with quotes. For contains/no-contains are “yes” or “no”, with quotes. For criteria you write the criteria that must be match or not be matched, and for folder to move you just write the name of the folder you want your messages to be directed to. After modifying the RULES (at line 24) array:

    1. go to https://panel.dreamhost.com/index.cgi?tree=mail.filters&
    2. choose the account you wish to add the rules and click “Edit”;
    3. open the console (right button > inspect element; then click the console button Chrome Console Button)
    4. copy and paste the entire script and hit ENTER.

You must wait until the message “End. All rules were added“. If you close the browser before the end the process will stop, of course. But you can resume the process from the rule you stopped by either changing the current variable at the start method or by removing the already added rules from the array.


/**
 *
 * Developed by CaioToOn!
 * caiotoon.com
 * @caiotoon
 *
 * This is a conceptual script aimed to add rules to Dreamhost mail filters.
 * To use it read http://caiotoon.com/blog/adding-many-mail-filters-to-dreamhost-by-javascript/
 */

// No. of elements per rule in the array
var TUPLE = 4;

// Current rule
var current = -1;

// Security key
var securityKey;

// Account ID
var accId;
// Array of rules. All rules should be sequentially put in here. Each 4 values represent one rule, with
// "field" (from, subject, body, reply-to, to, cc, headers), "contains/not contains" (yes/no), "rule criteria", "folder where to move the message"
var RULES = [
 "from", "yes", "mailman@mytest.com", "Personal",
 "subject","no","@dreamhost.com", "Trash",
 "subject","yes", "@test.com.br", "Tests"
];

// RPC Routines
var xmlHttp = null;

function doGet(Url, callback)
{
 xmlHttp = new XMLHttpRequest();
 xmlHttp.onreadystatechange = function() { response(callback); };
 xmlHttp.open( "GET", Url, true );
 xmlHttp.send( null );
}

function response(callback)
{
 if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 )
 {
 if ( xmlHttp.responseText == "Not found" )
 {
 console.error("Error at rule #"+cur);
 }
 else
 {
 callback();
 }
 }
}

// Prepare asking session.

function prepare() {

doGet( "https://panel.dreamhost.com/index.cgi?tab=mail&subtab=filters&current_step=Mailbox&next_step=Add&us_id="+accId, add );

}
// Ask the insertion.

function add() {

var at = current*TUPLE;

var field = RULES[at+0];
 var contains= RULES[at+1];
 var text = RULES[at+2];
 var folder = RULES[at+3];

console.info(" adding "+field+", "+contains+", "+text+", "+folder+"...");

doGet( "https://panel.dreamhost.com/index.cgi?tab=mail&subtab=filters&current_step=Add&next_step=AddFinal&security_key="+securityKey+"&num_filter_fields=1&filter_field0="+field+"&filter_contains0="+contains+"&filter_text0="+text+"&filter_match=any&action=move&action_folder="+folder+"&action_subject=&action_header=&action_email=&forward_peon=3781622169&stop=yes", next );

}
// Execute the next rule or finish the proccess.

function next() {

var at = ++current*TUPLE;

if( at < RULES.length ) {

console.info("Asking rule #" + current + " ("+at+")");
 prepare();

} else
 console.info("End. All rules were added.");

}

// Starts the proccess, finding the Security Key and the Account ID.

function start() {

var usIdMatcher = /.*us_id=(\d.+)*/

securityKey = document.getElementsByName("security_key")[0].value;
 accId = usIdMatcher.exec(window.location)[1];
 current = -1;

if( accId == undefined )
 console.error("Can't find acct ID. You must go to https://panel.dreamhost.com/index.cgi?tree=mail.filters& and access the account you wish to create the rules.");

else if( securityKey == undefined )
 console.error("Can't find security ID. You must go to https://panel.dreamhost.com/index.cgi?tree=mail.filters& and access the account you wish to create the rules.");

else next();

}

// Call the start of the proccess.

start();

This is a very limited script, but you can adapt it to your needs by changing the URLs variables to change any other configuration to the rule. Feel free to enhance and change it, then post it back here.

Cheers!

Comment now!
















Trackbacks