<commit_before><?php
namespace OCA\Mail\Tests\Imap;

use OCA\Mail\Account;
use OCA\Mail\Db\MailAccount;
use OCA\Mail\Mailbox;

abstract class AbstractTest extends \PHPUnit_Framework_TestCase {

	/**
	 * @var Account
	 */
	private static $account;

	/**
	 * @var Mailbox[]
	 */
	private static $createdMailboxes = [];

	public static function setUpBeforeClass() {
		if (false === \getenv('EMAIL_USER')) {
			throw new \RuntimeException(
				'Please set environment variable EMAIL_USER before running functional tests'
			);
		}

		if (false === \getenv('EMAIL_PASSWORD')) {
			throw new \RuntimeException(
				'Please set environment variable EMAIL_PASSWORD before running functional tests'
			);
		}
		$user = \getenv('EMAIL_USER');
		$password = \getenv('EMAIL_PASSWORD');
		$a = new MailAccount();
		$a->setId(-1);
		$a->setName('ownCloudMail');
		$a->setInboundHost('imap.gmail.com');
		$a->setInboundPort(993);
		$a->setInboundUser($user);
		$a->setInboundPassword($password);
		$a->setInboundSslMode('ssl');
		$a->setEmail($user);
		$a->setOutboundHost('smtp.gmail.com');
		$a->setOutboundPort(465);
		$a->setOutboundUser($user);
		$a->setOutboundPassword($password);
		$a->setOutboundSslMode('ssl');

		self::$account = new Account($a);
		self::$account->getImapConnection();
	}

	public static function tearDownAfterClass() {
		foreach(self::$createdMailboxes as $createdMailbox) {
			self::deleteMailbox($createdMailbox);
		}
	}

	/**
	 * @param $name
	 * @return \OCA\Mail\Mailbox
	 */
	public function createMailBox($name) {
		$uniqueName = $name . uniqid();

		try {
			$mailbox = $this->getTestAccount()->getMailbox($uniqueName);
			$this->deleteMailbox($mailbox);
		} catch (\Exception $e) {
			// Ignore mailbox not found
		}

		$mailbox = $this->getTestAccount()->createMailbox($uniqueName);
		self::$createdMailboxes[]= $mailbox;
		return $mailbox;
	}

	/**
	 * @return Account
	 */
	protected function getTestAccount() {
		return self::$account;
	}

	private static function deleteMailbox($mailbox) {
		self::$account->deleteMailbox($mailbox);
	}

	protected function createTestMessage(
		Mailbox $mailbox,
		$subject = 'Don\'t panic!',
		$contents = 'Don\'t forget your towel',
		$from = '<EMAIL>',
		$to = '<EMAIL>'
	) {
		$message = "From: $from
Subject: $subject
To: $to
Message-ID: <20150415133206.Horde.M8uzSs0lxFX6uUE2sc6_rw5@localhost>
User-Agent: Horde Application Framework 5
Date: Wed, 15 Apr 2015 13:32:06 +0000
Content-Type: text/plain; charset=UTF-8; format=flowed; DelSp=Yes
MIME-Version: 1.0


$contents";
		$mailbox->saveMessage($message);
	}

}
<commit_msg>Fixing unit test execution<commit_after><?php
namespace OCA\Mail\Tests\Imap;

use OCA\Mail\Account;
use OCA\Mail\Db\MailAccount;
use OCA\Mail\Mailbox;

abstract class AbstractTest extends \PHPUnit_Framework_TestCase {

	/**
	 * @var Account
	 */
	private static $account;

	/**
	 * @var Mailbox[]
	 */
	private static $createdMailboxes = [];

	public static function setUpBeforeClass() {
		if (false === \getenv('EMAIL_USER')) {
			throw new \RuntimeException(
				'Please set environment variable EMAIL_USER before running functional tests'
			);
		}

		if (false === \getenv('EMAIL_PASSWORD')) {
			throw new \RuntimeException(
				'Please set environment variable EMAIL_PASSWORD before running functional tests'
			);
		}
		$user = \getenv('EMAIL_USER');
		$password = \getenv('EMAIL_PASSWORD');
		$password = \OC::$server->getCrypto()->encrypt($password);
		$a = new MailAccount();
		$a->setId(-1);
		$a->setName('ownCloudMail');
		$a->setInboundHost('imap.gmail.com');
		$a->setInboundPort(993);
		$a->setInboundUser($user);
		$a->setInboundPassword($password);
		$a->setInboundSslMode('ssl');
		$a->setEmail($user);
		$a->setOutboundHost('smtp.gmail.com');
		$a->setOutboundPort(465);
		$a->setOutboundUser($user);
		$a->setOutboundPassword($password);
		$a->setOutboundSslMode('ssl');

		self::$account = new Account($a);
		self::$account->getImapConnection();
	}

	public static function tearDownAfterClass() {
		foreach(self::$createdMailboxes as $createdMailbox) {
			self::deleteMailbox($createdMailbox);
		}
	}

	/**
	 * @param $name
	 * @return \OCA\Mail\Mailbox
	 */
	public function createMailBox($name) {
		$uniqueName = $name . uniqid();

		try {
			$mailbox = $this->getTestAccount()->getMailbox($uniqueName);
			$this->deleteMailbox($mailbox);
		} catch (\Exception $e) {
			// Ignore mailbox not found
		}

		$mailbox = $this->getTestAccount()->createMailbox($uniqueName);
		self::$createdMailboxes[]= $mailbox;
		return $mailbox;
	}

	/**
	 * @return Account
	 */
	protected function getTestAccount() {
		return self::$account;
	}

	private static function deleteMailbox($mailbox) {
		self::$account->deleteMailbox($mailbox);
	}

	protected function createTestMessage(
		Mailbox $mailbox,
		$subject = 'Don\'t panic!',
		$contents = 'Don\'t forget your towel',
		$from = '<EMAIL>',
		$to = '<EMAIL>'
	) {
		$message = "From: $from
Subject: $subject
To: $to
Message-ID: <20150415133206.Horde.M8uzSs0lxFX6uUE2sc6_rw5@localhost>
User-Agent: Horde Application Framework 5
Date: Wed, 15 Apr 2015 13:32:06 +0000
Content-Type: text/plain; charset=UTF-8; format=flowed; DelSp=Yes
MIME-Version: 1.0


$contents";
		$mailbox->saveMessage($message);
	}

}

{'fraction_non_alphanumeric': 0.16470140737923164, 'fraction_numerical': 0.01787751996957018, 'mean_word_length': 4.53578947368421, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, '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': '1333441', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1826, 'n_words': 357}