<commit_before><?php

namespace Ddeboer\Imap;

/**
 * An IMAP mailbox
 */
class Mailbox implements \IteratorAggregate
{
    protected $name;
    protected $stream;
    protected $messageIds;

    /**
     * Constructor
     *
     * @param string   $name   Mailbox name
     * @param resource $stream PHP IMAP resource
     */
    public function __construct($name, $stream)
    {
        $this->name = $name;
        $this->stream = $stream;
    }

    /**
     * Get number of messages in this mailbox
     *
     * @return int
     */
    public function count()
    {
        return \imap_num_msg($this->stream);
    }

    /**
     * Get message ids
     *
     * @return array
     */
    public function getMessages()
    {
        if (null === $this->messageIds) {
            $this->messageIds = \imap_search($this->stream, 'ALL');
        }

        return $this->messageIds;
    }

    /**
     * Get a message by message number
     *
     * @param int $number Message number
     *
     * @return Message
     */
    public function getMessage($number)
    {
        return new Message($this->stream, $number);
    }

    /**
     * Get messages in this mailbox
     *
     * @return MessageIterator
     */
    public function getIterator()
    {
        return new MessageIterator($this->stream);
    }
}<commit_msg>Re-initialize resource when necessary<commit_after><?php

namespace Ddeboer\Imap;

/**
 * An IMAP mailbox (commonly referred to as a ‘folder’)
 *
 */
class Mailbox implements \IteratorAggregate
{
    protected $name;
    protected $stream;
    protected $messageIds;

    /**
     * Constructor
     *
     * @param string   $name   Mailbox name
     * @param resource $stream PHP IMAP resource
     */
    public function __construct($mailbox, $stream)
    {
        $this->mailbox = $mailbox;
        $this->stream = $stream;
        $this->name = substr($mailbox, strpos($mailbox, '}')+1);
    }

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

    /**
     * Get number of messages in this mailbox
     *
     * @return int
     */
    public function count()
    {
        $this->init();
        return \imap_num_msg($this->stream);
    }

    /**
     * Get message ids
     *
     * @return array
     */
    public function getMessages()
    {
        if (null === $this->messageIds) {
            $this->init();
            $this->messageIds = \imap_search($this->stream, 'ALL');
        }

        return $this->messageIds;
    }

    /**
     * Get a message by message number
     *
     * @param int $number Message number
     *
     * @return Message
     */
    public function getMessage($number)
    {
        $this->init();

        return new Message($this->stream, $number);
    }

    /**
     * Get messages in this mailbox
     *
     * @return MessageIterator
     */
    public function getIterator()
    {
        $this->init();

        return new MessageIterator($this->stream);
    }

    protected function init()
    {
        $check = \imap_check($this->stream);
        if ($check->Mailbox != $this->mailbox) {
            \imap_reopen($this->stream, $this->mailbox);
        }
    }
}
{'fraction_non_alphanumeric': 0.1295496607032696, 'fraction_numerical': 0.00030845157310302283, 'mean_word_length': 1.8249128919860627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '638721', 'n_tokens_mistral': 974, 'n_tokens_neox': 960, 'n_words': 235}