PERL script : change blacklist stat w/o sending email

Solutions for other advanced phplisters

PERL script : change blacklist stat w/o sending email

Postby Guest » 12:41am, Mon 01 Dec, 2008

PERL script that changes appropriate tables for blacklisting purposes. I wrote this because I didn't want to do it by hand, I wanted the interface to work properly, and I didn't want to email someone when being blacklisted. This is the appropriate action for users that have opted out in the past (I cannot import this attribute and "disabled" doesn't work). I wrote this quickly, so it's not idiot proof, not pretty, and not guaranteed to work :

Code: Select all

# usage: <filename>

use DBI;
use DBD::mysql;

$database = "phplistdb";
$user = "USER"; $password = "PASSWORD";

if ($#ARGV != 0) { print 'usage: <filename>' . "\n"; exit; }


while (<LIST>) {
   my $p = $m->prepare("UPDATE phplist_user_user SET blacklisted = \'1\' \
   WHERE email = \'$_\' AND blacklisted = \'0\'");
   my $rows = $p->execute();
        if ($rows != 1) {$p->finish(); print "No $_\n"; next; }

   my $p = $m->prepare("INSERT INTO phplist_user_blacklist (email,added) \
   VALUES (\'$_\',NOW())");

   my $p = $m->prepare("INSERT INTO phplist_user_blacklist_data \
   (email,name,data) VALUES (?,?,?)");
        $p->execute($_,'reason','manually added');




sub mysql_connect {
   $m = DBI->connect("DBI:mysql:$database","$user","$password", { RaiseError => 1 } );
sub mysql_disconnect {
sub warn {
   if ($DBI::err) { print "Error - $DBI::errstr\n"; }

(I ignored the user_history table on purpose)

Feed it a text file with emails separated by carriage returns. The email address must already exist and not be blacklisted already. You also have to define your mysql user name and password. Of course, you need mysql DBD/DBI and PERL installed.

This was tested on phplist 2.10.7. Hack as you see fit, this is free to use without acknowledgment.

PLEASE NOTE - You can still undo blacklisting like you normally would (User->History). Also be aware, the front end appears to cache data, so it takes about 5 minutes to show the updates in certain areas.


Postby J_S » 1:16pm, Mon 01 Dec, 2008

This is great! I'll give it a try and tell you how it goes :)
Posts: 674
Joined: 10:18pm, Fri 11 Apr, 2003

Return to Advanced Answers, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 1 guest