<?php
if (THIS_SCRIPT != 'payment_gateway')
{
	if ($vbulletin->options['bounceemail'])
	{
		$headers .= 'X-vBMail-BouncedFrom: ' . $toemail . $delimiter;
		$headers .= 'X-vBMail-BounceKey: ' . md5(md5($toemail) . md5($toemail)) . $delimiter;
	}
	
	if (class_exists('VBMAIL') AND VBMAIL::$pluginglobals['mailinglist'])
	{
		// Store the mailing list ID
		$headers .= 'X-vBMail-Mailinglist: ' . VBMAIL::$pluginglobals['mailinglist']['mailinglistid'] . $delimiter;

		// Do some header tweaking
		$headers = str_replace(
			array(
				'From: "' . VBMAIL::$pluginglobals['mailinglist']['fromemail'] . '"',
				'Sender: ' . $vbulletin->options['webmasteremail'],
				'text/plain',
			),
			array(
				'From: "' . VBMAIL::$pluginglobals['mailinglist']['title'] . '"',
				'Sender: ' . VBMAIL::$pluginglobals['mailinglist']['fromemail'],
				'text/html',
			),
			$headers
		);

		if ($existing = VBMAIL::$db->fetchRow('SELECT * FROM $' . (VBMAIL::$pluginglobals['mailinglist']['external'] ? 'dbtech_vbmail_' : '') . 'user WHERE email = ?', array($toemail)))
		{
			global $vbphrase;

			$hash = VBMAIL::create_subscriptionhash($existing, VBMAIL::$pluginglobals['mailinglist']);
			$headers .= 'List-Unsubscribe: <mailto:' . VBMAIL::$pluginglobals['mailinglist']['fromemail'] . '?subject=' . $vbphrase['dbtech_vbmail_unsubscribe'] . '>, <' . $vbulletin->options['bburl'] . '/vbmail.php?do=mailinglists&action=managesubscription&mailinglistid=' . VBMAIL::$pluginglobals['mailinglist']['mailinglistid'] . '&u=' . $existing['userid'] . '&type=subscribed&subscriptionhash=' . $hash . '>' . $delimiter;
		}
	}
}
?>