#!/usr/bin/perl use Digest::MD5 qw(md5_hex); use Email::Address; use JSON; use strict; # There are 3 sections in this example you should edit # to integrate with your Customer Management System (CMS) my $searchhost = 'ws.contactclean.com'; # the load balanced search cluster my $json = new JSON; # EDIT 1 # config for the control files and to get the results back my $bulk_name = 's_' . time(); # a unique name for each search set my $return_userhost = 'user@myserver.domain'; my $notify_email = 'my.email@domain'; my $account = 'acc name'; # this will be given to you by ContactClean admin my $key = '0123456789abcdef0123456789abcdef'; # from https://www.contactclean.com/user/license_key.php?gdet=yes # end EDIT 1 # EDIT 2 # generate list of emails # this is the section to integrate into your CMS... my @emails = ( 'Arthur Pewty ', 'TestOld@ContactClean.com', ); # end EDIT 2 # generate data and control files my $fnamedata = "${bulk_name}_data.gz"; my $fnamecontrol = "${bulk_name}_control.json"; open(DATA, "| gzip > $fnamedata") || die "Failed: | gzip > $fnamedata"; open(CONTROL, "> $fnamecontrol") || die "Failed: > $fnamecontrol"; my %md_map = (); Email::Address->disable_cache; for my $email (@emails) { my @addr = Email::Address->parse($email); my $addr = lc $addr[0]->address; # print "$email cleaned up to: $addr \n"; my $md = md5_hex($addr); $md_map{$md} = $email; # possible EDIT for large lists this should be stored in a database print DATA "$md\n"; } close DATA; print CONTROL $json->objToJson({ key => $key, return_userhost => $return_userhost, notify_email => $notify_email, }); close CONTROL; # transfer data and control my $remote = "${account}\@${searchhost}:"; `scp $fnamedata $fnamecontrol $remote`; # set the search going `touch ${bulk_name}_ready`; `scp ${bulk_name}_ready $remote`; # now poll $return_dir until the file ${bulk_name}_done appears... print "Looking for ${bulk_name}_done \n"; while (1) { if (-f "${bulk_name}_done") { print "Results are here in ${bulk_name}_results.gz \n"; last; } print "Results not appeared yet\n"; sleep(10); } open(R, "${bulk_name}_report.json") || die "Report file ${bulk_name}_report.json missing"; my $report = $json->jsonToObj(join('', )); close(R); if ($report->{'error'}) { print join("\n", $report->{'error'}), "\n"; exit 1; } # EDIT 3 # process $return_dir/${bulk_name}_results.gz open(RES, "zcat ${bulk_name}_results.gz |") || die "Results file ${bulk_name}_results.gz missing"; while () { chomp; next if m/norecord$/; if (! m/,/) { print "ERROR: malformed result line: $_ \n"; } my ($md, $update) = split ','; my $old = $md_map{$md}; # this is the second section to integrate into your CMS... if ($update =~ /@/) { print "UPDATE LIST: $old -> $update \n"; } else { print "INFO: $old - $update \n"; } }