require_once KNEWS_DIR . "/includes/knews_util.php";
    if ($inst = knews_pop3_login($Knews_plugin->post_safe('bounce_host_knews'), $Knews_plugin->post_safe('bounce_port_knews'), $Knews_plugin->post_safe('bounce_user_knews'), html_entity_decode(stripslashes($Knews_plugin->post_safe('bounce_pass_knews', '', 'unsafe'))), "INBOX", $Knews_plugin->post_safe('bounce_ssl_knews'), $Knews_plugin->post_safe('bounce_mode_knews'))) {
        //print_r($inst);
        _e('Connection seems OK, looking for messages:', 'knews');
        echo '<br>';
        $stat = knews_pop3_stat($inst);
        if (isset($stat['Unread'])) {
            echo __('Unread messages:') . ' ' . $stat['Unread'] . '<br>';
        }
        if (isset($stat['Nmsgs'])) {
            echo __('Total messages:') . ' ' . $stat['Nmsgs'] . '<br>';
            if ($stat['Nmsgs'] == 0) {
                _e('Send one email to the bounce account to test the email reading', 'knews');
            } else {
                echo __("Let's try to read the first email:", 'knews') . '<br>';
                $testmessage = knews_pop3_list($inst, 1, false);
                if (isset($testmessage[0]) && $testmessage[0] != '') {
                    echo sprintf(__('The message was readed <strong>successfully</strong>, if has %s bytes length.', 'knews'), strlen($testmessage[0]));
                    echo ' <a href="#" onclick="show_code(); return false;">' . __('See email content', 'knews') . '</a>';
                    ?>
					<div class="showcode" style="display:none; padding:10px 0;"><?php 
                    echo htmlentities($testmessage[0]);
                    ?>
</div>
					<?php 
                } else {
                    echo __("The message can't be readed.");
                }
            }
        } else {
            _e("Can't read the total messages number, something isn't working");
    $Knews_plugin->init();
}
if ($knewsOptions['bounce_on'] == '1') {
    require_once KNEWS_DIR . "/includes/knews_util.php";
    require_once KNEWS_DIR . "/includes/bouncehandler/bounce_driver.class.php";
    $bouncehandler = new Bouncehandler();
    if ($inst = knews_pop3_login($knewsOptions['bounce_host'], $knewsOptions['bounce_port'], $knewsOptions['bounce_user'], $knewsOptions['bounce_pass'], "INBOX", $knewsOptions['bounce_ssl'], $knewsOptions['bounce_mode'])) {
        $stat = knews_pop3_stat($inst);
        //print_r($stat);
        //die();
        if ($stat['Nmsgs'] > 0) {
            $messages = $stat['Nmsgs'];
            if ($messages > 50) {
                $messages = 50;
            }
            $list = knews_pop3_list($inst, $messages);
            $count = 0;
            foreach ($list as $row) {
                $count++;
                $b = $bouncehandler->get_the_facts($row);
                $fail_code = 0;
                $read_blog_id = 0;
                $posid = strpos($row, 'Knews-Blog-Id:');
                $posid = $posid + 14;
                if ($posid !== false) {
                    $posid2 = strpos($row, '_', $posid);
                    if ($posid2 !== false) {
                        $read_blog_id = substr($row, $posid, $posid2 - $posid);
                    }
                    $read_blog_id = intval(trim($read_blog_id));
                }