| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License and the CiviCRM Licensing Exception along | |
| 21 | | with this program; if not, contact CiviCRM LLC | |
| 22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 25 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * When runing script from cli : |
| 38 | * 1. By default script is being used for civimail processing. |
| 39 | * eg : nice -19 php bin/EmailProcessor.php -u<login> -p<password> -s<sites(or default)> |
| 40 | * |
| 41 | * 2. Pass "activities" as argument to use script for 'Email To Activity Processing'. |
| 42 | * eg : nice -19 php bin/EmailProcessor.php -u<login> -p<password> -s<sites(or default)> activities |
| 43 | * |
| 44 | */ |
| 45 | |
| 46 | // bootstrap the environment and run the processor |
| 47 | // you can run this program either from an apache command, or from the cli |
| 48 | if (php_sapi_name() == "cli") { |
| 49 | require_once "bin/cli.php"; |
| 50 | $cli = new civicrm_cli(); |
| 51 | //if it doesn't die, it's authenticated |
| 52 | //log the execution of script |
| 53 | CRM_Core_Error::debug_log_message('EmailProcessor.php from the cli'); |
| 54 | require_once 'CRM/Core/Lock.php'; |
| 55 | $lock = new CRM_Core_Lock('EmailProcessor'); |
| 56 | |
| 57 | if (!$lock->isAcquired()) { |
| 58 | throw new Exception('Could not acquire lock, another EmailProcessor process is running'); |
| 59 | } |
| 60 | |
| 61 | require_once 'CRM/Utils/Mail/EmailProcessor.php'; |
| 62 | |
| 63 | // check if the script is being used for civimail processing or email to |
| 64 | // activity processing. |
| 65 | if (isset($cli->args[0]) && $cli->args[0] == "activities") { |
| 66 | CRM_Utils_Mail_EmailProcessor::processActivities(); |
| 67 | } |
| 68 | else { |
| 69 | CRM_Utils_Mail_EmailProcessor::processBounces(); |
| 70 | } |
| 71 | $lock->release(); |
| 72 | } |
| 73 | else { |
| 74 | session_start(); |
| 75 | require_once '../civicrm.config.php'; |
| 76 | require_once 'CRM/Core/Config.php'; |
| 77 | $config = CRM_Core_Config::singleton(); |
| 78 | CRM_Utils_System::authenticateScript(TRUE); |
| 79 | |
| 80 | require_once 'CRM/Utils/System.php'; |
| 81 | CRM_Utils_System::loadBootStrap(); |
| 82 | |
| 83 | //log the execution of script |
| 84 | CRM_Core_Error::debug_log_message('EmailProcessor.php'); |
| 85 | |
| 86 | require_once 'CRM/Core/Lock.php'; |
| 87 | $lock = new CRM_Core_Lock('EmailProcessor'); |
| 88 | |
| 89 | if (!$lock->isAcquired()) { |
| 90 | throw new Exception('Could not acquire lock, another EmailProcessor process is running'); |
| 91 | } |
| 92 | |
| 93 | // try to unset any time limits |
| 94 | if (!ini_get('safe_mode')) { |
| 95 | set_time_limit(0); |
| 96 | } |
| 97 | |
| 98 | require_once 'CRM/Utils/Mail/EmailProcessor.php'; |
| 99 | |
| 100 | // cleanup directories with old mail files (if they exist): CRM-4452 |
| 101 | CRM_Utils_Mail_EmailProcessor::cleanupDir($config->customFileUploadDir . DIRECTORY_SEPARATOR . 'CiviMail.ignored'); |
| 102 | CRM_Utils_Mail_EmailProcessor::cleanupDir($config->customFileUploadDir . DIRECTORY_SEPARATOR . 'CiviMail.processed'); |
| 103 | |
| 104 | // check if the script is being used for civimail processing or email to |
| 105 | // activity processing. |
| 106 | $isCiviMail = !empty($_REQUEST['emailtoactivity']) ? FALSE : TRUE; |
| 107 | CRM_Utils_Mail_EmailProcessor::process($isCiviMail); |
| 108 | |
| 109 | $lock->release(); |
| 110 | } |