<?php
include_once '../../../../tools/inc.php';
include '../../../common.php';
include '../tools/class.XMLCreator.php';
include '../tools/class.taskList.php';
include "../tools/class.pop3.php";

$table='newsletters'.$config["table_prefix"];
$table_pop3='pop3_accounts'.$config["table_prefix"];
$n_id=intval($n_id);

$sql="update {$table} set last_bounced='".time()."'";
$db->execute($sql);

$sql="select p.* from $table n 
left join $table_pop3 p on n.pop3=p.id
where n.id='$n_id'";
list($account)=$db->select($sql);
if (isset($account['id'])) {
	$pop=new POP3();
	if ($pop->connect($account['login'], $account['password'], $account['host'], $account['port'])) {
		$count=$pop->getMessageCount();
		$pop->close();
	} else $count=0;
}
$t=new taskList();
$task=new task('Checking bounced emails', $count);
for ($i=1; $i<=$count; $i++) $task->add('check.php?n_id='.$n_id, "Checking message {$i} of {$count}", 1);
$t->add($task);
$t->output();
exit;
?>