<commit_before><?php
/**
 * Mail class.
 * 
 * This class provides mail sending functionality.
 * 
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright &copy; 2008, Telaxus LLC
 * @license MIT
 * @version 1.0
 * @package epesi-base
 * @subpackage mail
 */
defined("_VALID_ACCESS") || die('Direct access forbidden');

require_once ('modules/Base/Mail/class.phpmailer.php');

class Base_MailCommon extends Base_AdminModuleCommon {
	/**
	 * For internal use only.
	 */
	public static function admin_caption() {
		return 'Mail server settings';
	}
	
	/**
	 * For internal use only.
	 */
	public static function admin_access() {
		return !DEMO_MODE;
	}

	public static function admin_access_levels() {
		return !DEMO_MODE?false:null;
	}
	
	public static function send_critical($to,$subject,$body,$from_addr=null, $from_name=null, $html=false) {
		return self::send($to,$subject,$body,$from_addr, $from_name, $html, true);
	}
	
	public static function check_sending_method($critical=false) {
		$msg = false;
		if (Variable::get('mail_method') != 'smtp') {
			$msg = Base_LangCommon::ts('Base_Mail','Mail server configuration error');
		}
		if ($msg) Base_StatusBarCommon::message($msg,'error');
	}

	/**
	 * Sends an email.
	 * 
	 * Server settings are stored in epesi variables
	 * and can be changed by administrator.
	 * 
	 * @param string recipent
	 * @param string subject
	 * @param string email message
	 * @param string sender
	 * @param string sender's name
	 * @return true on success, false otherwise
	 */
	public static function send($to,$subject,$body,$from_addr=null, $from_name=null, $html=false, $critical=false) {
		$mailer = self::new_mailer();
		if(!isset($from_addr)) $from_addr = Variable::get('mail_from_addr');
		if(!isset($from_name)) $from_name = Variable::get('mail_from_name');
		$mailer->SetFrom($from_addr, $from_name);
		if(Variable::get('mail_method') == 'smtp') {
			$mailer->IsSMTP();
			$h = explode(':', Variable::get('mail_host'));
			$mailer->Host = $h[0];
			if(isset($h[1]))
				$mailer->Port = $h[1];
			$mailer->Username = Variable::get('mail_user');
			$mailer->Password = Variable::get('mail_password');
			$mailer->SMTPAuth = Variable::get('mail_auth');
		} else {
			if ($critical) return false;
		}
		
		if(is_array($to))
			foreach($to as $m)
				$mailer->AddAddress($m);<commit_msg>Campaign Manager - block using php.ini to send mails<commit_after><?php
/**
 * Mail class.
 * 
 * This class provides mail sending functionality.
 * 
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright &copy; 2008, Telaxus LLC
 * @license MIT
 * @version 1.0
 * @package epesi-base
 * @subpackage mail
 */
defined("_VALID_ACCESS") || die('Direct access forbidden');

require_once ('modules/Base/Mail/class.phpmailer.php');

class Base_MailCommon extends Base_AdminModuleCommon {
	/**
	 * For internal use only.
	 */
	public static function admin_caption() {
		return 'Mail server settings';
	}
	
	/**
	 * For internal use only.
	 */
	public static function admin_access() {
		return !DEMO_MODE;
	}

	public static function admin_access_levels() {
		return !DEMO_MODE?false:null;
	}
	
	public static function send_critical($to,$subject,$body,$from_addr=null, $from_name=null, $html=false) {
		return self::send($to,$subject,$body,$from_addr, $from_name, $html, true);
	}
	
	public static function check_sending_method($critical=false) {
		$msg = false;
		if (Variable::get('mail_method') != 'smtp' && HOSTING_MODE) {
			$msg = Base_LangCommon::ts('Base_Mail','Mail server configuration error');
		}
		if ($msg) Base_StatusBarCommon::message($msg,'error');
	}

	/**
	 * Sends an email.
	 * 
	 * Server settings are stored in epesi variables
	 * and can be changed by administrator.
	 * 
	 * @param string recipent
	 * @param string subject
	 * @param string email message
	 * @param string sender
	 * @param string sender's name
	 * @return true on success, false otherwise
	 */
	public static function send($to,$subject,$body,$from_addr=null, $from_name=null, $html=false, $critical=false) {
		$mailer = self::new_mailer();
		if(!isset($from_addr)) $from_addr = Variable::get('mail_from_addr');
		if(!isset($from_name)) $from_name = Variable::get('mail_from_name');
		$mailer->SetFrom($from_addr, $from_name);
		if(Variable::get('mail_method') == 'smtp') {
			$mailer->IsSMTP();
			$h = explode(':', Variable::get('mail_host'));
			$mailer->Host = $h[0];
			if(isset($h[1]))
				$mailer->Port = $h[1];
			$mailer->Username = Variable::get('mail_user');
			$mailer->Password = Variable::get('mail_password');
			$mailer->SMTPAuth = Variable::get('mail_auth');
		} elseif (HOSTING_MODE) {
			if (!$critical) return false;
		}
		
		if(is_array($to))
			foreach($to as $m)
				$mailer->AddAddress($m);
{'fraction_non_alphanumeric': 0.16380589107861834, 'fraction_numerical': 0.003814367450731087, 'mean_word_length': 4.6594724220623505, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4104016', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1537, 'n_words': 358}