<commit_before><?php

require 'lib/hm-imap.php';

class Hm_Handler_imap_folder_expand extends Hm_Handler_Module {
    public function process($data) {
        $data['imap_expanded_folder_data'] = array();
        list($success, $form) = $this->process_form(array('imap_server_id', 'folder'));
        if ($success) {
            $path = sprintf("imap_%d_%s", $form['imap_server_id'], $form['folder']);
            $page_cache =  Hm_Page_Cache::get('imap_folders_'.$path);
            if ($page_cache) {
                $data['imap_expanded_folder_path'] = $path;
                $data['imap_expanded_folder_formatted'] = $page_cache;
                return $data;
            }
            $details = Hm_IMAP_List::dump($form['imap_server_id']);
            $cache = Hm_IMAP_List::get_cache($this->session, $form['imap_server_id']);
            $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache);
            if (is_object($imap) && $imap->get_state() == 'authenticated') {
                $msgs = $imap->get_folder_list_by_level($form['folder']);
                if (isset($msgs[$form['folder']])) {
                    unset($msgs[$form['folder']]);
                }
                $data['imap_expanded_folder_data'] = $msgs;
                $data['imap_expanded_folder_id'] = $form['imap_server_id'];
                $data['imap_expanded_folder_path'] = $path;
            }
        }
        return $data;
    }
}

class Hm_Handler_save_folder_state extends Hm_Handler_Module {
    public function process($data) {
        list($success, $form) = $this->process_form(array('imap_folder_state'));
        if ($success) {
            Hm_Page_Cache::add('imap_folders', $form['imap_folder_state'], true);
        }
    }
}

class Hm_Handler_save_unread_state extends Hm_Handler_Module {
    public function process($data) {
        list($success, $form) = $this->process_form(array('formatted_unread_data'));
        if ($success) {
            Hm_Page_Cache::add('formatted_unread_data',
                preg_replace("/<tr style=\"opacity: \d(\.\d+|);\"/", "<tr ", $form['formatted_unread_data']));
        }
    }
}

class Hm_Handler_imap_folder_page extends Hm_Handler_Module {
    public function process($data) {

        $sort = 'ARRIVAL';
        $rev = true;
        $filter = 'ALL';
        $offset = 0;
        $limit = 20;
        $msgs = array();
        $list_page = 1;

        list($success, $form) = $this->process_form(array('imap_server_id', 'folder'));
        if ($success) {
            if (isset($this->request->get['list_page'])) {
                $list_page = (int) $this->request->get['list_page'];
                if ($list_page && $list_page > 1) {
                    $offset = ($list_page - 1)*$limit;
                }
                else {
                    $list_page = 1;
                }
            }
            $path = sprintf("imap_%d_%s", $form['imap_server_id'], $form['folder']);
            $details = Hm_IMAP_List::dump($form['imap_server_id']);
            $cache = Hm_IMAP_List::get_cache($this->session, $form['imap_server_id']);
            $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache);
            if (is_object($imap) && $imap->get_state() == 'authenticated') {
                $data['imap_mailbox_page_path'] = $path;
                $data['imap_mailbox_page_title'] = $form['folder'];
                $data['imap_mailbox_page_id'] = $form['imap_server_id'];
                foreach ($imap->get_mailbox_page($form['folder'], $sort, $rev, $filter, $offset, $limit) as $msg) {
                    $msg['server_id'] = $form['imap_server_id'];
                    $msg['server_name'] = $details['name'];
                    $msg['folder'] = $form['folder'];
                    $msgs[] = $msg;
                }
                $data['imap_folder_detail'] = $imap->selected_mailbox;
                $data['imap_folder_detail']['offset'] = $offset;
                $data['imap_folder_detail']['limit'] = $limit;
            }
            $data['imap_mailbox_page'] = $msgs;
            $data['list_page'] = $list_page;
            $data['imap_server_id'] = $form['imap_server_id'];
        }
        return $data;
    }
}

class Hm_Handler_imap_message_list_type extends Hm_Handler_Module {
    public function process($data) {
        $data['list_path'] = false;<commit_msg>remove unused vars<commit_after><?php

require 'lib/hm-imap.php';

class Hm_Handler_imap_folder_expand extends Hm_Handler_Module {
    public function process($data) {
        $data['imap_expanded_folder_data'] = array();
        list($success, $form) = $this->process_form(array('imap_server_id', 'folder'));
        if ($success) {
            $path = sprintf("imap_%d_%s", $form['imap_server_id'], $form['folder']);
            $page_cache =  Hm_Page_Cache::get('imap_folders_'.$path);
            if ($page_cache) {
                $data['imap_expanded_folder_path'] = $path;
                $data['imap_expanded_folder_formatted'] = $page_cache;
                return $data;
            }
            $details = Hm_IMAP_List::dump($form['imap_server_id']);
            $cache = Hm_IMAP_List::get_cache($this->session, $form['imap_server_id']);
            $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache);
            if (is_object($imap) && $imap->get_state() == 'authenticated') {
                $msgs = $imap->get_folder_list_by_level($form['folder']);
                if (isset($msgs[$form['folder']])) {
                    unset($msgs[$form['folder']]);
                }
                $data['imap_expanded_folder_data'] = $msgs;
                $data['imap_expanded_folder_id'] = $form['imap_server_id'];
                $data['imap_expanded_folder_path'] = $path;
            }
        }
        return $data;
    }
}

class Hm_Handler_save_folder_state extends Hm_Handler_Module {
    public function process($data) {
        list($success, $form) = $this->process_form(array('imap_folder_state'));
        if ($success) {
            Hm_Page_Cache::add('imap_folders', $form['imap_folder_state'], true);
        }
    }
}

class Hm_Handler_save_unread_state extends Hm_Handler_Module {
    public function process($data) {
        list($success, $form) = $this->process_form(array('formatted_unread_data'));
        if ($success) {
            Hm_Page_Cache::add('formatted_unread_data',
                preg_replace("/<tr style=\"opacity: \d(\.\d+|);\"/", "<tr ", $form['formatted_unread_data']));
        }
    }
}

class Hm_Handler_imap_folder_page extends Hm_Handler_Module {
    public function process($data) {

        $sort = 'ARRIVAL';
        $rev = true;
        $filter = 'ALL';
        $offset = 0;
        $limit = 20;
        $msgs = array();
        $list_page = 1;

        list($success, $form) = $this->process_form(array('imap_server_id', 'folder'));
        if ($success) {
            if (isset($this->request->get['list_page'])) {
                $list_page = (int) $this->request->get['list_page'];
                if ($list_page && $list_page > 1) {
                    $offset = ($list_page - 1)*$limit;
                }
                else {
                    $list_page = 1;
                }
            }
            $path = sprintf("imap_%d_%s", $form['imap_server_id'], $form['folder']);
            $details = Hm_IMAP_List::dump($form['imap_server_id']);
            $cache = Hm_IMAP_List::get_cache($this->session, $form['imap_server_id']);
            $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache);
            if (is_object($imap) && $imap->get_state() == 'authenticated') {
                $data['imap_mailbox_page_path'] = $path;
                foreach ($imap->get_mailbox_page($form['folder'], $sort, $rev, $filter, $offset, $limit) as $msg) {
                    $msg['server_id'] = $form['imap_server_id'];
                    $msg['server_name'] = $details['name'];
                    $msg['folder'] = $form['folder'];
                    $msgs[] = $msg;
                }
                $data['imap_folder_detail'] = $imap->selected_mailbox;
                $data['imap_folder_detail']['offset'] = $offset;
                $data['imap_folder_detail']['limit'] = $limit;
            }
            $data['imap_mailbox_page'] = $msgs;
            $data['list_page'] = $list_page;
            $data['imap_server_id'] = $form['imap_server_id'];
        }
        return $data;
    }
}

class Hm_Handler_imap_message_list_type extends Hm_Handler_Module {
    public function process($data) {
        $data['list_path'] = false;
{'fraction_non_alphanumeric': 0.1627418978782933, 'fraction_numerical': 0.0016320820704126837, 'mean_word_length': 2.3034270311898344, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, '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': '628617', 'n_tokens_mistral': 2822, 'n_tokens_neox': 2750, 'n_words': 385}