$totalcount = $selectresult['totalcount'];
     echo $totalcount;
 } else {
     if ($action == 'fetchheaders') {
         $fetchresult = handmadeimap_fetch_envelopes($connection, $startindex, $endindex);
         if (!handmadeimap_was_ok()) {
             die("FETCH failed: " . handmadeimap_get_error() . "\n");
         }
         $messagexml = envelopes_to_xml($fetchresult, 'received');
         print '<?xml version="1.0" encoding="ISO-8859-1"?><messagelist>' . "\n";
         //'
         print $messagexml;
         print "</messagelist>\n";
     } else {
         if ($action == 'fetchsince') {
             $searchresult = handmadeimap_search_since_date($connection, $date);
             if (!handmadeimap_was_ok()) {
                 die("SEARCH failed: " . handmadeimap_get_error() . "\n");
             }
             print_r($searchresult);
         } else {
             if ($action == 'indexsince') {
                 $totalcount = $selectresult['totalcount'];
                 $searchresult = handmadeimap_earliest_index_since_time($connection, $time, $totalcount);
                 if (!handmadeimap_was_ok()) {
                     die("handmadeimap_earliest_index_since_time() failed: " . handmadeimap_get_error() . "\n");
                 }
                 print "{$searchresult}:{$totalcount}\n";
             }
         }
     }
Example #2
0
function handmadeimap_earliest_index_since_time($connection, $unixtime, $totalcount)
{
    // The IMAP search ignores the time zone, so bump the time backwards by a day to avoid missing any
    $conservativetime = $unixtime - 24 * 60 * 60;
    $date = date('d-M-Y', $conservativetime);
    $messageindices = handmadeimap_search_since_date($connection, $date);
    $minindex = $totalcount;
    foreach ($messageindices as $index) {
        $minindex = min($minindex, $index);
    }
    return $minindex;
}