// Source Path
 $S->setPath($path['name']);
 $src_path_stat = $S->pathStat();
 // print_r($src_path_stat);
 if (empty($src_path_stat['mail_count'])) {
     echo "S: Skip {$src_path_stat['mail_count']} messages\n";
     continue;
 }
 echo "S: {$src_path_stat['mail_count']} messages\n";
 // Target Path
 $tgt_path = _path_map($path['name']);
 echo "T: Indexing: {$tgt_path}\n";
 $T->setPath($tgt_path);
 // Creates if needed
 // Show info on Target
 $tgt_path_stat = $T->pathStat();
 echo "T: {$tgt_path_stat['mail_count']} messages\n";
 // Build Index of Target
 $tgt_mail_list = array();
 for ($i = 1; $i <= $tgt_path_stat['mail_count']; $i++) {
     $mail = $T->mailStat($i);
     if (array_key_exists('message_id', $mail)) {
         $tgt_mail_list[$mail['message_id']] = !empty($mail['subject']) ? $mail['subject'] : "[ No Subject ] Message {$i}";
     }
 }
 for ($src_idx = $src_path_stat['mail_count']; $src_idx >= 1; $src_idx--) {
     $stat = $S->mailStat($src_idx);
     $stat['answered'] = trim($stat['Answered']);
     $stat['unseen'] = trim($stat['Unseen']);
     if (empty($stat['subject'])) {
         $stat['subject'] = "[ No Subject ] Message {$src_idx}";
    Imports Messages from POP3/IMAP Mailbox to Request Queue
    Imports and Adds Attachments too
*/
/**
  Uses the Native PHP to read a IMAP/POP3(+SSL) mailbox and put messages into Imperium
  @todo drop dependency on ZF, use base-PHP
  @todo import to Trac using the Trac Web Interface - basically HTTP POST
*/
// CLI
require_once dirname(dirname(__FILE__)) . '/lib/cli.php';
if (empty($_ENV['mail']['imap'])) {
    die("No IMAP Configuration\n");
}
echo "Checking: {$_ENV['mail']['imap']}\n";
$imap = new IMAP($_ENV['mail']['imap']);
$imap_stat = $imap->pathStat();
if (empty($imap_stat)) {
    die("Cannot Check Mailbox\n");
}
// print_r($imap_stat);
if ($imap_stat['mail_count'] == 0) {
    return 0;
}
for ($i = $imap_stat['mail_count']; $i >= 1; $i--) {
    $stat = $imap->mailStat($i);
    // echo "S: {$stat['subject']} {$stat['MailDate']}\n";
    // print_r($stat['from'][0]);
    $from = $stat['from'][0];
    $from_mail = $from->mailbox . '@' . $from->host;
    if (!preg_match('/[\\w\\+\\.]+@[\\w\\.]+/', $from_mail)) {
        die("Invalid From: " . print_r($from, true));