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

namespace OCA\Mail;

class Mailbox {

	/**
	 * @var \Horde_Imap_Client_Socket
	 */
	private $conn;

	private $folder_id;

	// input $conn = IMAP conn, $folder_id = folder id
	function __construct($conn, $folder_id) {
		$this->conn = $conn;
		$this->folder_id = $folder_id;
	}

	public function getMessages($from = 0, $count = 2) {
		$total = $this->getTotalMessages();
		if (($from + $count) > $total) {
			$count = $total - $from;
		}

		$headers = array();

		$fetch_query = new \Horde_Imap_Client_Fetch_Query();
		$fetch_query->envelope();
		$fetch_query->flags();
		$fetch_query->seq();
		$fetch_query->size();
		$fetch_query->uid();
		$fetch_query->imapDate();

		$headers = array_merge($headers, array(
			'importance',
			'list-post',
			'x-priority'
		));
		$headers[] = 'content-type';

		$fetch_query->headers('imp', $headers, array(
			'cache' => true,
			'peek'  => true
		));

		$opt = array('ids' => ($from + 1) . ':' . ($from + 1 + $count));
		$opt = array();
		// $list is an array of Horde_Imap_Client_Data_Fetch objects.
		$headers = $this->conn->fetch($this->folder_id, $fetch_query, $opt);

		ob_start(); // fix for Horde warnings
		$messages = array();
		foreach ($headers as $message_id => $header) {
			$message = new Message($this->conn, $this->folder_id, $message_id);
			$message->setInfo($header);
			$messages[] = $message->getListArray();
		}
		ob_clean();

		// sort by time
		usort($messages, function($a, $b) {
			return $a['date-int'] < $b['date-int'];
		});

		return $messages;
	}

	/**
	 * @param $message_id
	 * @return Message
	 */
	public function getMessage($message_id) {
		return new Message($this->conn, $this->folder_id, $message_id);
	}

	private function getStatus($flags = \Horde_Imap_Client::STATUS_ALL) {
		return $this->conn->status($this->folder_id, $flags);
	}

	public function getTotalMessages() {
		$status = $this->getStatus(\Horde_Imap_Client::STATUS_MESSAGES);
		return $status['messages'];
	}

	public function getDisplayName() {
		return \Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($this->folder_id);
	}

	/**
	 * @return array
	 */
	public function getListArray() {
		$display_name = $this->getDisplayName();
		try {
			$status = $this->getStatus();
			return array('id' => $this->folder_id, 'name' => $display_name, 'unseen' => $status['unseen'], 'total' => $status['messages']);
		} catch (\Horde_Imap_Client_Exception $e) {
			return array('id' => $this->folder_id, 'name' => $display_name, 'unseen' => 0, 'total' => 0, 'error' => $e->getMessage());
		}
	}

}
<commit_msg>fixing merge issue - setInfo no longer exists<commit_after><?php
/**
 * Copyright (c) 2012 <NAME> <<EMAIL>>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

namespace OCA\Mail;

class Mailbox {

	/**
	 * @var \Horde_Imap_Client_Socket
	 */
	private $conn;

	private $folder_id;

	// input $conn = IMAP conn, $folder_id = folder id
	function __construct($conn, $folder_id) {
		$this->conn = $conn;
		$this->folder_id = $folder_id;
	}

	public function getMessages($from = 0, $count = 2) {
		$total = $this->getTotalMessages();
		if (($from + $count) > $total) {
			$count = $total - $from;
		}

		$headers = array();

		$fetch_query = new \Horde_Imap_Client_Fetch_Query();
		$fetch_query->envelope();
		$fetch_query->flags();
		$fetch_query->seq();
		$fetch_query->size();
		$fetch_query->uid();
		$fetch_query->imapDate();

		$headers = array_merge($headers, array(
			'importance',
			'list-post',
			'x-priority'
		));
		$headers[] = 'content-type';

		$fetch_query->headers('imp', $headers, array(
			'cache' => true,
			'peek'  => true
		));

		$opt = array('ids' => ($from + 1) . ':' . ($from + 1 + $count));
		$opt = array();
		// $list is an array of Horde_Imap_Client_Data_Fetch objects.
		$headers = $this->conn->fetch($this->folder_id, $fetch_query, $opt);

		ob_start(); // fix for Horde warnings
		$messages = array();
		foreach ($headers as $message_id => $header) {
			$message = new Message($this->conn, $this->folder_id, $message_id, $header);
			$messages[] = $message->getListArray();
		}
		ob_clean();

		// sort by time
		usort($messages, function($a, $b) {
			return $a['date-int'] < $b['date-int'];
		});

		return $messages;
	}

	/**
	 * @param $message_id
	 * @return Message
	 */
	public function getMessage($message_id) {
		return new Message($this->conn, $this->folder_id, $message_id);
	}

	private function getStatus($flags = \Horde_Imap_Client::STATUS_ALL) {
		return $this->conn->status($this->folder_id, $flags);
	}

	public function getTotalMessages() {
		$status = $this->getStatus(\Horde_Imap_Client::STATUS_MESSAGES);
		return $status['messages'];
	}

	public function getDisplayName() {
		return \Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($this->folder_id);
	}

	/**
	 * @return array
	 */
	public function getListArray() {
		$display_name = $this->getDisplayName();
		try {
			$status = $this->getStatus();
			return array('id' => $this->folder_id, 'name' => $display_name, 'unseen' => $status['unseen'], 'total' => $status['messages']);
		} catch (\Horde_Imap_Client_Exception $e) {
			return array('id' => $this->folder_id, 'name' => $display_name, 'unseen' => 0, 'total' => 0, 'error' => $e->getMessage());
		}
	}

}

{'fraction_non_alphanumeric': 0.18974358974358974, 'fraction_numerical': 0.005128205128205128, 'mean_word_length': 4.02391904323827, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 94, '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': '2830063', 'n_tokens_mistral': 2143, 'n_tokens_neox': 1944, 'n_words': 416}