#! /usr/bin/php -q * All rights reserved * * This script is part of the TYPO3 project. The TYPO3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * A copy is found in the textfile GPL.txt and important notices to the license * from the author is found in LICENSE.txt distributed with these scripts. * * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ /** * Cron tack for return mails analysis * * @author Kasper Skaarhoj * @author Stanislas Rolland * * $Id: returnmail.phpsh 6012 2007-07-23 12:54:25Z ivankartolo $ * */ error_reporting (E_ALL ^ E_NOTICE); if ($_SERVER['PHP_SELF']) { if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', $_SERVER['PHP_SELF']))); } else { if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', $_ENV['_']))); } if (!defined('PATH_site')) define('PATH_site', dirname(dirname(dirname(dirname(dirname(dirname(PATH_thisScript)))))).'/'); if (!defined('PATH_t3lib')) if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/'); define('PATH_typo3conf', PATH_site.'typo3conf/'); define('TYPO3_mainDir', 'typo3/'); if (!defined('PATH_typo3')) define('PATH_typo3', PATH_site.TYPO3_mainDir); if (!defined('PATH_tslib')) { if (@is_dir(PATH_site.'typo3/sysext/cms/tslib/')) { define('PATH_tslib', PATH_site.'typo3/sysext/cms/tslib/'); } elseif (@is_dir(PATH_site.'tslib/')) { define('PATH_tslib', PATH_site.'tslib/'); } } define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':''); define('TYPO3_MODE', 'BE'); require_once(PATH_t3lib.'class.t3lib_div.php'); require_once(PATH_t3lib.'class.t3lib_extmgm.php'); require_once(PATH_t3lib.'config_default.php'); require_once(PATH_typo3conf.'localconf.php'); if (!defined ('TYPO3_db')) die ('The configuration file was not included.'); if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) die('You cannot set the GLOBALS-array from outside this script.'); // Connect to the database require_once(PATH_t3lib.'class.t3lib_db.php'); $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB'); $result = $TYPO3_DB->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password); if (!$result) { die("Couldn't connect to database at ".TYPO3_db_host); } $TYPO3_DB->sql_select_db(TYPO3_db); require_once(t3lib_extMgm::extPath('direct_mail').'res/scripts/class.readmail.php'); // MAIL CONTENT $filename = 'php://stdin'; $content = t3lib_div::getUrl($filename); if (trim($content)) { $readMail = t3lib_div::makeInstance('readmail'); // Split mail into head and content $mailParts = $readMail->extractMailHeader($content); // Find id $midArr = $readMail->find_XTypo3MID($content); if (!is_array($midArr)) { $midArr = $readMail->find_MIDfromReturnPath($mailParts['to']); } // Extract text content $c = trim($readMail->getMessage($mailParts)); $cp = $readMail->analyseReturnError($c); $res = $TYPO3_DB->exec_SELECTquery('uid,email', 'sys_dmail_maillog', 'rid='.intval($midArr['rid']).' AND rtbl="'.$TYPO3_DB->quoteStr($midArr['rtbl'], 'sys_dmail_maillog').'" AND mid='.intval($midArr['mid']).' AND response_type=0'); if (!$TYPO3_DB->sql_num_rows($res)) { $midArr = array(); $cp = $mailParts; } else { $row = $TYPO3_DB->sql_fetch_assoc($res); $midArr['email'] = $row['email']; } $insertFields = array( 'tstamp' => time(), 'response_type' => -127, 'mid' => intval($midArr['mid']), 'rid' => intval($midArr['rid']), 'email' => $midArr['email'], 'rtbl' => $midArr['rtbl'], 'return_content' => serialize($cp), 'return_code' => intval($cp['reason']) ); $TYPO3_DB->exec_INSERTquery('sys_dmail_maillog', $insertFields); } ?>