Current File : /home/inlingua/public_html/decay_sym/root/var/softaculous/apps/exim/boxtrapper_url.php
<?php

/**
 * Boxtrapper PHP program URL File
 *
 * @author Julfekar Shaikh
 */

// Set custom header
// NOTE : Never ever remove this as its checked by our Service Check script
header('Server:Webuzo');

// Define SOFTACULOUS
@define('SOFTACULOUS', 1);
@define('EXIM_USERS_PATH', '/etc/exim/users/');

// Load Boxtrapper Functions
include_once(__DIR__.'/boxtrapper_func.php');

// Get the mail and msgid from URL
$msgid = $_GET['msgid'];
$email = $_GET['email'];

// Get the user from email
$user = get_user_from_email($email);

// If boxtrapper is enabled on the mail
if(!exim_check_boxtrapper_enabled($user, $email)){
	echo "Boxtrapper is not enabled on this email. \n";
}

$temail = explode('@', $email);

// Connect with Queue DB 
$con = new SQLite3('/etc/exim/users/'.$user.'/'.$temail[1].'/boxtrapper/'.$temail[0].'/queue.db');

// Get the list of Queue ID's from the DB
$results = $con->query('SELECT * FROM `queue` WHERE msgid = "'.trim($msgid).'"');
if(empty($results->fetchArray())){
	// Means the authentication Key is wrong So we have to reply with wrong Msg id message
	echo __('Wrong Key! Please follow the proper url.');
	exit(0);
}
while ($row = $results->fetchArray()){
	$from = $row['from'];
}

// If valid, Deliver Message
$res = $con->query('SELECT * FROM `queue` WHERE `from` = "'.trim($from).'"');

while ($row = $res->fetchArray()){
	deliver_to_mail_address($user, $email, '', $row['msgid']);
}

// After delivery the mails remove entry from the DB
$con->query('DELETE FROM `queue` WHERE `from` = "'.trim($from).'"');

// Make it whitelist if conf allowed us
add_mail_in_whilelist($user, $email, $from);

function get_user_from_email($mail){

	$email = explode('@', $mail);

	$userdomain = file('/etc/userdomains');

	foreach($userdomain as $k => $v){
		preg_match('/'.$v.': (.*)/', $v, $out);
		if(!empty($out[1])){
			return trim($out[1]);
		}
	}

}

// End the script
exit(0);