Script PHP

Previous Next

Questo script legge tutti gli indirizzi email degli utenti e li cerca all'interno dei file *.eml che sono stati inviati in precedenza. La provenienza dei file *.eml è indifferente, basta che siano in formato testo. Potenzialmente possono essere anche solo liste di singoli indirizzi email da escludere. In tal caso però la motivazione sarà incomprensibile all'utente. Il singolo file *.eml, viene allegato alla notifica, assieme alle intestazioni, per cui non hanno nessuna scusa. Chi ha grandi forum apprezzerà questa aggiunta in particolare, perché gli utenti si inventano di tutto purché impiegare gli amministratori di forum con ricerche inutili.


Il messaggio di notifica contiene 2 segnaposti (%s), di cui il primo è il nome utente, il secondo il contenuto del file *.eml. Questi segnaposti non devono mancare e non è possibile invertirli, a meno che non si modifichi anche il codice. Il resto può essere modificato a piacere, facendo attenzione di fare l'escape delle virgolette singole.


<?php

/*============================================================================*\

|| ########################################################################## ||

|| # Rimuove gli indirizzi email da utenti con email invalide               # ||

|| # ---------------------------------------------------------------------- # ||

|| # (C) Copyright Y2K Software s.a.s. 2009-2013 - All Rights Reserved.     # ||

|| # This file may not be redistributed in whole or significant part.       # ||

|| ########################################################################## ||

\*============================================================================*/


/**

* @author Y2K Software

* @copyright (C) Copyright Y2K Software 2009-2013 - All Rights Reserved

* @version 1.0.2

* @link www.pagerobot.com

*/


// Change TABLE_PREFIX, if needed

define('TABLE_PREFIX', '');


// Notification message (please change to your needs, leaving all %s placeholders alone)

$fmt = 'Ciao %s,


il tuo indirizzo email è stato rimosso in seguito al problema di consegna indicato in basso.


Spesso si tratta di caselle email piene o disabilitate per inutilizzo. Fino a quando non sarà risolto in modo definitivo, il problema si ripeterà alla prossima notifica.


Preghiamo di indicare nel proprio profilo un indirizzo email che permetta l\'invio delle notifiche da parte del forum.


Puoi [URL="profile.php?do=editpassword"][B]impostare il nuovo indirizzo email qui[/B][/URL].


Per ulteriori domande puoi [URL="sendmessage.php"][B]contattarci qui[/B][/URL].

[HR][/HR]

Questo è il motivo che ci è stato comunicato da parte del server di posta.

[CODE]%s[/CODE]';


// #############################################################################

// #############################################################################

// #############################################################################


$count = 0;

$timenow = time();


// Connect to database ---------------------------------------------------------

mysql_connect('localhost', 'root', 'password') or die(mysql_error());

mysql_select_db('databasename') or die(mysql_error());


// Get currently existing email addresses --------------------------------------

$values = array();

$SQL = "SELECT userid, username, email

       FROM " . TABLE_PREFIX . "user

       WHERE email>''";

$rss = mysql_query($SQL);

while($rs = mysql_fetch_assoc($rss))

{

   $values["$rs[userid]"] = array('email' => $rs['email'], 'username' => $rs['username']);

}

mysql_free_result($rss);


// Get email files from folder -------------------------------------------------

$files = glob('*.eml', GLOB_NOSORT);

if($files === false)

{

   $files = array();

}


// For each file in list

foreach($files as $f)

{

   // Get file contente

   if(!$a = file_get_contents($f))

   {

       continue;

   }

   

   // Remove CR

   $a = str_replace("\r", '', $a);


   // Remove 'X-' tags from file

   $b = explode("\n", $a);

   $a = array();

   foreach($b as $bvalue)

   {

       $i = strpos($bvalue, 'X-');

       if($i === false || $i > 0)

       {

           $a[] = $bvalue;

       }

   }

   

   // Make it a normal email file

   $a = implode("\r\n", $a);


   // For each email address

   foreach($values as $key => $value)

   {

       if(stripos($a, $value['email']) === false)

       {

           // Skip if not found

           continue;

       }


       // Add email address to discard

       $count++;

       unset($values[$key]);


       // Make a PM to user

       $message = mysql_escape_string(sprintf($fmt, $value['username'], $a));


       // Insert message into pmtext

       $SQL = "INSERT INTO " . TABLE_PREFIX . "pmtext SET

           fromuserid=0,

           fromusername='Webmaster',

           title='Rimozione di indirizzo email invalido',

           message='$message',

           touserarray='a:0:{}',

           iconid=4,

           dateline=$timenow,

           showsignature=0,

           allowsmilie=0,

           reportthreadid=0";

       mysql_query($SQL);

       if(!$pmtextid = mysql_insert_id())

       {

           continue;

       }

       

       // Insert private message into pm

       $SQL = "INSERT INTO " . TABLE_PREFIX . "pm SET

           pmtextid=$pmtextid,

           userid=$key,

           folderid=0,

           messageread=0,

           parentpmid=0";

       mysql_query($SQL);

       

       // Notify user passively and clear email

       $SQL = "UPDATE " . TABLE_PREFIX . "user SET

           pmtotal=pmtotal+1,

           pmunread=pmunread+1,

           email=''

           WHERE userid=$key";

       mysql_query($SQL);

       

       // Add other queries here, such as newsletter tables etc

   }

}


// Removal of files

$n = 0;

foreach($files as $f)

{

   $n += intval(@unlink($f));

}


echo "$n file email eliminati; $count utenti notificati";

die;