<commit_before><?php
namespace Concrete\Core\Mail\Importer;
use Concrete\Core\Foundation\Object;
use Loader;
use Core;
use \Concrete\Core\Package\PackageList;
class MailImporter extends Object {

	/**
	 * gets the text string that's used to identify the body of the message
	 * @return string
	 */
	public function getMessageBodyHeader() {
		return t('--- Reply ABOVE. Do not alter this line --- [' . $this->validationHash  . '] ---');
	}

	public function getValidationHash() {
		return $this->validationHash;
	}
	

	public function getMessageBodyHashRegularExpression() {
		return t('/\-\-\- Reply ABOVE\. Do not alter this line \-\-\- \[(.*)\] \-\-\-/i');
	}

	public function getList() {
		$db = Loader::db();
		$r = $db->Execute('select miID from MailImporters order by miID asc');
		$importers = array();
		while ($row = $r->FetchRow()) {
			$importers[] = MailImporter::getByID($row['miID']);
		}
		return $importers;
	}

	public function getEnabledList() {
		$db = Loader::db();
		$r = $db->Execute('select miID from MailImporters where miIsEnabled = 1 order by miID asc');
		$importers = array();
		while ($row = $r->FetchRow()) {
			$importers[] = MailImporter::getByID($row['miID']);
		}
		return $importers;
	}
	
	public static function getByID($miID) {
		$db = Loader::db();
		$row = $db->GetRow("select miID, miHandle, miServer, miUsername, miPassword, miEncryption, miIsEnabled, miEmail, miPort, miConnectionMethod, Packages.pkgID, pkgHandle from MailImporters left join Packages on MailImporters.pkgID = Packages.pkgID where miID = ?", array($miID));
		if (isset($row['miID'])) {
			$txt = Loader::helper('text');
			$mi = Core::make('\\Concrete\\Core\\Mail\\Importer\\Type\\' . $txt->camelcase($row['miHandle']));
			$mi->setPropertiesFromArray($row);
			return $mi;
		}
	}

	public static function getByHandle($miHandle) {
		$db = Loader::db();
		$miID = $db->GetOne("select miID from MailImporters where miHandle = ?", $miHandle);
		return MailImporter::getByID($miID);
	}
	
	public function delete() {
		$db = Loader::db();
		$db->Execute('delete from MailImporters where miID = ?', array($this->miID));
	}
	
	public static function getListByPackage($pkg) {
		$db = Loader::db();
		$list = array();
		$r = $db->Execute('select miID from MailImporters where pkgID = ? order by miID asc', array($pkg->getPackageID()));
		while ($row = $r->FetchRow()) {
			$list[] = self::getByID($row['miID']);
		}
		$r->Close();
		return $list;
	}	
	
	public function getMailImporterID() {return $this->miID;}
	public function getMailImporterName() {
		$txt = Loader::helper('text');
		return $txt->unhandle($this->miHandle);
	}
	public function getMailImporterHandle() {return $this->miHandle;}
	public function getMailImporterServer() {return $this->miServer;}
	public function getMailImporterUsername() {return $this->miUsername;}
	public function getMailImporterPassword() {return $this->miPassword;}
	public function getMailImporterEncryption() {return $this->miEncryption;}
	public function getMailImporterEmail() {return $this->miEmail;}
	public function getMailImporterPort() {return $this->miPort;}
	public function isMailImporterEnabled() {return $this->miIsEnabled;}
	public function getMailImporterConnectionMethod() {return $this->miConnectionMethod;}
	public function getPackageID() { return $this->pkgID;}
	public function getPackageHandle() {
		return PackageList::getHandle($this->pkgID);
	}

	public function add($args, $pkg = null) {
		$db = Loader::db();
		extract($args);
		
		if ($miPort < 1) {
			$miPort = 0;
		}
		
		if ($miIsEnabled != 1) {
			$miIsEnabled = 0;
		}
		
		if ($miEncryption == '') {
			$miEncryption == null;
		}
		
		if (!$miConnectionMethod) {
			$miConnectionMethod = 'POP';
		}

		
		$pkgID = ($pkg == null) ? 0 : $pkg->getPackageID();
		
		$db->Execute('insert into MailImporters (miHandle, miServer, miUsername, miPassword, miEncryption, miIsEnabled, miEmail, miPort, miConnectionMethod, pkgID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', 
			array(
				$miHandle,
				Loader::helper('security')->sanitizeString($miServer),
				$miUsername,
				$miPassword,
				$miEncryption,
				$miIsEnabled,
				Loader::helper('security')->sanitizeString($miEmail),
				$miPort, 
				$miConnectionMethod, 
				$pkgID
			));
		
		$miID = $db->Insert_ID();
		return MailImporter::getByID($miID);
	}
	
	public function update($args) {
		$db = Loader::db();
		extract($args);
		
		if ($miPort < 1) {
			$miPort = 0;
		}
		
		if ($miIsEnabled != 1) {
			$miIsEnabled = 0;
		}
		
		if ($miEncryption == '') {
			$miEncryption == null;
		}

		$db->Execute('update MailImporters set miServer = ?, miUsername = ?, miPassword = ?, miEncryption = ?, miIsEnabled = ?, miEmail = ?, miPort = ?, miConnectionMethod = ? where miID = ?', 
			array(
				Loader::helper('security')->sanitizeString($miServer),
				$miUsername,
				$miPassword,
				$miEncryption,
				$miIsEnabled,<commit_msg>Changed a couple expressions to be value assignments<commit_after><?php
namespace Concrete\Core\Mail\Importer;
use Concrete\Core\Foundation\Object;
use Loader;
use Core;
use \Concrete\Core\Package\PackageList;
class MailImporter extends Object {

	/**
	 * gets the text string that's used to identify the body of the message
	 * @return string
	 */
	public function getMessageBodyHeader() {
		return t('--- Reply ABOVE. Do not alter this line --- [' . $this->validationHash  . '] ---');
	}

	public function getValidationHash() {
		return $this->validationHash;
	}
	

	public function getMessageBodyHashRegularExpression() {
		return t('/\-\-\- Reply ABOVE\. Do not alter this line \-\-\- \[(.*)\] \-\-\-/i');
	}

	public function getList() {
		$db = Loader::db();
		$r = $db->Execute('select miID from MailImporters order by miID asc');
		$importers = array();
		while ($row = $r->FetchRow()) {
			$importers[] = MailImporter::getByID($row['miID']);
		}
		return $importers;
	}

	public function getEnabledList() {
		$db = Loader::db();
		$r = $db->Execute('select miID from MailImporters where miIsEnabled = 1 order by miID asc');
		$importers = array();
		while ($row = $r->FetchRow()) {
			$importers[] = MailImporter::getByID($row['miID']);
		}
		return $importers;
	}
	
	public static function getByID($miID) {
		$db = Loader::db();
		$row = $db->GetRow("select miID, miHandle, miServer, miUsername, miPassword, miEncryption, miIsEnabled, miEmail, miPort, miConnectionMethod, Packages.pkgID, pkgHandle from MailImporters left join Packages on MailImporters.pkgID = Packages.pkgID where miID = ?", array($miID));
		if (isset($row['miID'])) {
			$txt = Loader::helper('text');
			$mi = Core::make('\\Concrete\\Core\\Mail\\Importer\\Type\\' . $txt->camelcase($row['miHandle']));
			$mi->setPropertiesFromArray($row);
			return $mi;
		}
	}

	public static function getByHandle($miHandle) {
		$db = Loader::db();
		$miID = $db->GetOne("select miID from MailImporters where miHandle = ?", $miHandle);
		return MailImporter::getByID($miID);
	}
	
	public function delete() {
		$db = Loader::db();
		$db->Execute('delete from MailImporters where miID = ?', array($this->miID));
	}
	
	public static function getListByPackage($pkg) {
		$db = Loader::db();
		$list = array();
		$r = $db->Execute('select miID from MailImporters where pkgID = ? order by miID asc', array($pkg->getPackageID()));
		while ($row = $r->FetchRow()) {
			$list[] = self::getByID($row['miID']);
		}
		$r->Close();
		return $list;
	}	
	
	public function getMailImporterID() {return $this->miID;}
	public function getMailImporterName() {
		$txt = Loader::helper('text');
		return $txt->unhandle($this->miHandle);
	}
	public function getMailImporterHandle() {return $this->miHandle;}
	public function getMailImporterServer() {return $this->miServer;}
	public function getMailImporterUsername() {return $this->miUsername;}
	public function getMailImporterPassword() {return $this->miPassword;}
	public function getMailImporterEncryption() {return $this->miEncryption;}
	public function getMailImporterEmail() {return $this->miEmail;}
	public function getMailImporterPort() {return $this->miPort;}
	public function isMailImporterEnabled() {return $this->miIsEnabled;}
	public function getMailImporterConnectionMethod() {return $this->miConnectionMethod;}
	public function getPackageID() { return $this->pkgID;}
	public function getPackageHandle() {
		return PackageList::getHandle($this->pkgID);
	}

	public function add($args, $pkg = null) {
		$db = Loader::db();
		extract($args);
		
		if ($miPort < 1) {
			$miPort = 0;
		}
		
		if ($miIsEnabled != 1) {
			$miIsEnabled = 0;
		}
		
		if ($miEncryption == '') {
			$miEncryption = null;
		}
		
		if (!$miConnectionMethod) {
			$miConnectionMethod = 'POP';
		}

		
		$pkgID = ($pkg == null) ? 0 : $pkg->getPackageID();
		
		$db->Execute('insert into MailImporters (miHandle, miServer, miUsername, miPassword, miEncryption, miIsEnabled, miEmail, miPort, miConnectionMethod, pkgID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', 
			array(
				$miHandle,
				Loader::helper('security')->sanitizeString($miServer),
				$miUsername,
				$miPassword,
				$miEncryption,
				$miIsEnabled,
				Loader::helper('security')->sanitizeString($miEmail),
				$miPort, 
				$miConnectionMethod, 
				$pkgID
			));
		
		$miID = $db->Insert_ID();
		return MailImporter::getByID($miID);
	}
	
	public function update($args) {
		$db = Loader::db();
		extract($args);
		
		if ($miPort < 1) {
			$miPort = 0;
		}
		
		if ($miIsEnabled != 1) {
			$miIsEnabled = 0;
		}
		
		if ($miEncryption == '') {
			$miEncryption = null;
		}

		$db->Execute('update MailImporters set miServer = ?, miUsername = ?, miPassword = ?, miEncryption = ?, miIsEnabled = ?, miEmail = ?, miPort = ?, miConnectionMethod = ? where miID = ?', 
			array(
				Loader::helper('security')->sanitizeString($miServer),
				$miUsername,
				$miPassword,
				$miEncryption,
				$miIsEnabled,
{'fraction_non_alphanumeric': 0.17037262666260533, 'fraction_numerical': 0.0020306630114732462, 'mean_word_length': 4.189673340358272, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 77, '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': '6881039', 'n_tokens_mistral': 3662, 'n_tokens_neox': 3235, 'n_words': 750}