Hi there,
this is my first post on this forum so don't beat to hard on me. Currently I'am using spamassassin and sauserprefs - so the users can control their Spamfilter. Sadly some of my users are just able to hit a "Spam"-Button - so I came out with markasjunk2.
What I would like to achieve is, that by hitting the "spam"-Button, the senders email-address will be written into the mysql-DB spamassassin in the tab. "userprefs" and blacklisted for the user preference. So the SA_Learn / HAM_Learn command in markasjunk2 would come out with an sql-command (?).
But I am not quit sure if this is generally possible - any ideas / comments?
Thanks for all answers!
Best regards
osterhase
I think perhaps the best way to do this would be to write a driver for markasjunk2 plugin which opens the message and gets the sender address and adds it to the spamassassin blacklist. Try something like the attached.
Wow... thanks. It works.
One little problem remains:
When the user hits the spam button, the sender of the spam-mail is blacklisted.
When the user hits the ham button in the spam folder, the sender is whitelisted - the blacklisting rule persists. (Mail is received anyhow)
When the user decides again that the same sender of the former whitelisted address is spam - the whitelisting rule persists as well and the mail gets through.
I'am not much of a coder... so maybe you could fix it - I would really appreciate it.
Best regards and thanks again for your help and work - it's great!
try adding something like
// delete any whitelisting for this address
$db->query("DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $_SESSION['username'] ."' AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = 'whitelist_from' AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = '". $email ."';");
after `if ($spam) {` and something similar after the `else {` to delete any blacklisting before an address is whitelisted.
Hi JohnDoh,
thanks for your help again, but as I've stated before I'm not much of a coder so I expierence difficulties - I would really appreciate your help.
I've made the adjustments in sa_blacklist.php (as I understood) - the mentioned section looks now like this:
if ($spam) {
// delete any whitelisting for this address
// $db->query("DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ."
// check address is not already blacklisted
$sql_result = $db->query("DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." SELECT value FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $_SESSION['username'] ."' AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = 'blacklist_from' AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = '". $email ."';");
if ($db->num_rows($sql_result) == 0) {
$db->query("INSERT INTO ". $rcmail->config->get('sauserprefs_sql_table_name') ." (". $rcmail->config->get('sauserprefs_sql_username_field') .", ". $rcmail->config->get('sauserprefs_sql_preference_field') .", ". $rcmail->config->get('sauserprefs_sql_value_field') .") VALUES ('". $_SESSION['username'] ."', 'blacklist_from', '". $email ."');");
if ($rcmail->config->get('markasjunk2_debug'))
write_log('markasjunk2', $_SESSION['username'] . ' blacklist ' . $email);
}
}
else {
// delete any whitelisting for this address
// $db->query("DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ."
// check address is not already whitelisted
$sql_result = $db->query("DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." SELECT value FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = '". $_SESSION['username'] ."' AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = 'whitelist_from' AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = '". $email ."';");
if ($db->num_rows($sql_result) == 0) {
$db->query("INSERT INTO ". $rcmail->config->get('sauserprefs_sql_table_name') ." (". $rcmail->config->get('sauserprefs_sql_username_field') .", ". $rcmail->config->get('sauserprefs_sql_preference_field') .", ". $rcmail->config->get('sauserprefs_sql_value_field') .") VALUES ('". $_SESSION['username'] ."', 'whitelist_from', '". $email ."');");
if ($rcmail->config->get('markasjunk2_debug'))
write_log('markasjunk2', $_SESSION['username'] . ' whitelist ' . $email);
}
Did you mean this? (As you can see I tried to execute it as a single command - but it produced errors, so I commented it out.)
What happens now, is that I can create more than one Blacklist / Whitelist entry for the same sender. I thought the goal would be to check, if a blacklist/whitelist entry is present and - if necesarry - delete it. Did I implement the code correctly? I would really like to get this running properly.
Thanks for any help!
(Currently used sa_blacklist.php attached)
sorry but you fail at copy and paste. you can get the full file here drivers/sa_blacklist.php at master from JohnDoh's Roundcube-Plugin-Mark-as-Junk-2 - GitHub (http://github.com/JohnDoh/Roundcube-Plugin-Mark-as-Junk-2/blob/master/drivers/sa_blacklist.php)
Uuh - that was nice. :p
It works perfectly... thanks for your work and help!
Edit:
I've just realized, that I really failed at copy & paste... I'm embarrassed.