Location: PHPKode > projects > phlyMail Lite > phlymail/reindexer.php
<?php
/**
 * Reindexer to update already indexed mails in the database. The current mailparser is capable of
 * much more things, which should be present for old mails too.
 * Usage: Copy to the root folder of phlyMail 4.0, open in browser
 * @package phlyMail 4.0
 * @subpackage Email handler
 * @copyright 2005-2010 phlyLabs Berlin, http://phlylabs.de/
 * @version 0.2.0 2010-09-24
 */
define('_IN_PHM_', true);
@set_include_path(dirname(__FILE__));
$choices = dirname(__FILE__).'/choices.ini.php';
if (!file_exists($choices) || !is_readable($choices)) die('Could not initialise basic settings.');
$_PM_ = parse_ini_file($choices, true);

require($_PM_['path']['lib'].'/init.frontend.php');
error_reporting(0);

if (isset($_REQUEST['start'])) {
    $qh = $DB->query('SELECT idx FROM '.$DB->DB['db_pref'].'email_index ORDER BY idx DESC');
    while ($line = $DB->fetchassoc($qh)) {
        $chk[] = $line['idx'];
    }
    header('Content-Type: application/json; charset="UTF-8"');
    echo '{"liste":['.join(',', $chk).']}';
    exit;
}

if (isset($_REQUEST['test'])) {
    header('Content-Type: application/json; charset="UTF-8"');
    require_once('shared/lib/phm_streaming_mailparser.php');
    $idx = intval($_REQUEST['test']);
    $qid = $DB->query('SELECT i.idx, i.uid, f.folder_path, i.uidl FROM '.$DB->DB['db_pref'].'email_index i'
            .','.$DB->DB['db_pref'].'email_folders f WHERE i.folder_id=f.idx AND i.idx='.$idx);
    $line = $DB->fetchassoc($qid);
    if (!preg_match('!^(\d+)\:!', $line['folder_path'])) {
        $file = $_PM_['path']['storage'].'/'.$line['uid'].'/email/'.$line['folder_path'].'/'.$line['uidl'];
        if (!file_exists($file) || !is_readable($file)) {
            $DB->query('DELETE FROM '.$DB->DB['db_pref'].'email_index WHERE idx='.$idx);
            echo '{"done":1}';
            exit;
        }
    }
    require_once('handlers/email/fs.php');
    $FS = new email_storage($line['uid']);
    $mailhead = $FS->get_mail_header($idx);
    $res = $DB->query('UPDATE '.$DB->DB['db_pref'].'email_index SET `hmessage_id`="'.$DB->escape($mailhead['message_id']).'"'
            .',`hcc`="'.$DB->escape($mailhead['cc']).'",`hbcc`="'.$DB->escape($mailhead['bcc']).'" WHERE idx='.$idx);
    $FS->IDX->thread_add_item($idx, $mailhead, $line['uid']);
    echo '{"done":1}';
    exit;
}

if (isset($_REQUEST['delete']) && $_REQUEST['delete']) {
    @unlink(__FILE__);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>phlyMail 4.0 Reindexer - Updating your database</title>
 <link rel="stylesheet" href="frontend/themes/Yokohama/style.css" type="text/css"></link>
</head>
<script type="text/javascript" src="frontend/js/jquery/jquery-min.js"></script>
<script type="text/javascript">
//<![CDATA[
liste = [];
cnt = 0;
cur = 0;
base_url = '<?php echo PHP_SELF; ?>';
function AJAX_call(url)
{
    $.ajax({'url': url, 'dataType': 'json', 'success': AJAX_process});
}

function AJAX_process(next)
{
    if (next !== null && next['liste']) {
        liste = next['liste'];
        cur = 0;
        cnt = liste.length;
        $('#cnt').text(cnt);
    }
    updater();
}

function updater()
{
    if (liste.length == 0) {
        AJAX_call(base_url + '?delete=1');
        alert('Ready updating your email index!');
        self.location.href = './index.php';
        return
    }
    ++cur;
    $('#cur').text(cur);
    AJAX_call(base_url + '?test=' + liste.pop());
}

$(document).ready(function () {
    AJAX_call(base_url + '?start=1');
});
// ]]>
</script>
<body>
    <div align="center" style="padding-top:100px;">
        <div class="sendmenubut" style="width:200px;margin:auto;text-align:center;">
            Updating ...<br />
            <span id="cur">0</span> / <span id="cnt">0</span><br />
        </div>
    </div>
</body>
</html>
Return current item: phlyMail Lite