<commit_before><?php
/**
 * Copyright (c) 2012 <NAME> <<EMAIL>>
 * Copyright (c) 2014 <NAME> <<EMAIL>>
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

namespace OCA\Mail;

use Horde_Imap_Client_Ids;
use Horde_Imap_Client_Mailbox;
use Horde_Imap_Client_Socket;
use Horde_Imap_Client;
use Horde_Mail_Transport_Smtphorde;
use OCA\Mail\Cache\Cache;
use OCA\Mail\Db\MailAccount;
use OCP\IConfig;

class Account {

	/**
	 * @var MailAccount
	 */
	private $account;

	/**
	 *  @var Mailbox[]
	 */
	private $mailboxes;

	/**
	 * @var Horde_Imap_Client_Socket
	 */
	private $client;

	/** @var IConfig */
	private $config;

	/**
	 * @param MailAccount $account
	 */
	function __construct(MailAccount $account) {
		$this->account = $account;
		$this->mailboxes = null;
		$this->crypto = \OC::$server->getCrypto();
		$this->config = \OC::$server->getConfig();
	}

	/**
	 * @return int
	 */
	public function getId() {
		return $this->account->getId();
	}

	/**
	 * @return string
	 */
	public function getName() {
		return $this->account->getName();
	}

	/**
	 * @return string
	 */
	public function getEMailAddress() {
		return $this->account->getEmail();
	}

	/**
	 * @return Horde_Imap_Client_Socket
	 */
	public function getImapConnection() {
		if (is_null($this->client)) {
			$host = $this->account->getInboundHost();
			$user = $this->account->getInboundUser();
			$password = $this->account->getInboundPassword();
			$password = $this->crypto->decrypt($password);
			$port = $this->account->getInboundPort();
			$ssl_mode = $this->convertSslMode($this->account->getInboundSslMode());

			$params = [
				'username' => $user,
				'password' => $password,
				'hostspec' => $host,
				'port' => $port,
				'secure' => $ssl_mode,
				'timeout' => 20,
			];
			if ($this->config->getSystemValue('app.mail.imaplog.enabled', false)) {
				$params['debug'] = $this->config->getSystemValue('datadirectory') . '/horde.log';
			}
			if ($this->config->getSystemValue('app.mail.server-side-cache.enabled', false)) {
				$cacheFac = \OC::$server->getMemCacheFactory();
				if ($cacheFac->isAvailable()) {
					$params['cache'] = [
						'backend' => new Cache(array(
							'cacheob' => $cacheFac->create(md5($this->getId() . $this->getEMailAddress()))
						))];
				}
<commit_msg>Get cache factory in constructor, a la dependency injection<commit_after><?php
/**
 * Copyright (c) 2012 <NAME> <<EMAIL>>
 * Copyright (c) 2014 <NAME> <<EMAIL>>
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

namespace OCA\Mail;

use Horde_Imap_Client_Ids;
use Horde_Imap_Client_Mailbox;
use Horde_Imap_Client_Socket;
use Horde_Imap_Client;
use Horde_Mail_Transport_Smtphorde;
use OCA\Mail\Cache\Cache;
use OCA\Mail\Db\MailAccount;
use OCP\IConfig;
use OCP\ICacheFactory;

class Account {

	/**
	 * @var MailAccount
	 */
	private $account;

	/**
	 *  @var Mailbox[]
	 */
	private $mailboxes;

	/**
	 * @var Horde_Imap_Client_Socket
	 */
	private $client;

	/** @var IConfig */
	private $config;

	/** @var ICacheFactory */
	private $memcacheFactory;

	/**
	 * @param MailAccount $account
	 */
	function __construct(MailAccount $account) {
		$this->account = $account;
		$this->mailboxes = null;
		$this->crypto = \OC::$server->getCrypto();
		$this->config = \OC::$server->getConfig();
		$this->memcacheFactory = \OC::$server->getMemcacheFactory();
	}

	/**
	 * @return int
	 */
	public function getId() {
		return $this->account->getId();
	}

	/**
	 * @return string
	 */
	public function getName() {
		return $this->account->getName();
	}

	/**
	 * @return string
	 */
	public function getEMailAddress() {
		return $this->account->getEmail();
	}

	/**
	 * @return Horde_Imap_Client_Socket
	 */
	public function getImapConnection() {
		if (is_null($this->client)) {
			$host = $this->account->getInboundHost();
			$user = $this->account->getInboundUser();
			$password = $this->account->getInboundPassword();
			$password = $this->crypto->decrypt($password);
			$port = $this->account->getInboundPort();
			$ssl_mode = $this->convertSslMode($this->account->getInboundSslMode());

			$params = [
				'username' => $user,
				'password' => $password,
				'hostspec' => $host,
				'port' => $port,
				'secure' => $ssl_mode,
				'timeout' => 20,
			];
			if ($this->config->getSystemValue('app.mail.imaplog.enabled', false)) {
				$params['debug'] = $this->config->getSystemValue('datadirectory') . '/horde.log';
			}
			if ($this->config->getSystemValue('app.mail.server-side-cache.enabled', false)) {
				if ($this->memcacheFactory->isAvailable()) {
					$params['cache'] = [
						'backend' => new Cache(array(
							'cacheob' => $this->memcacheFactory
								->create(md5($this->getId() . $this->getEMailAddress()))
						))];
				}

{'fraction_non_alphanumeric': 0.18284656519950637, 'fraction_numerical': 0.0049362402303578775, 'mean_word_length': 3.698550724637681, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 108, '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': '3548932', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1672, 'n_words': 319}