/** * Cron action on mailgate : retrieve mail and create tickets * * @param $task * * @return -1 : done but not finish 1 : done with success **/ static function cronMailgate($task) { global $DB; NotImportedEmail::deleteLog(); $query = "SELECT *\n FROM `glpi_mailcollectors`\n WHERE `is_active` = '1'"; if ($result = $DB->query($query)) { $max = $task->fields['param']; if ($DB->numrows($result) > 0) { $mc = new self(); while ($max > 0 && ($data = $DB->fetch_assoc($result))) { $mc->maxfetch_emails = $max; $task->log("Collect mails from " . $data["host"] . "\n"); $message = $mc->collect($data["id"]); $task->addVolume($mc->fetch_emails); $task->log("{$message}\n"); $max -= $mc->fetch_emails; } } if ($max == $task->fields['param']) { return 0; // Nothin to do } else { if ($max > 0) { return 1; // done } } return -1; // still messages to retrieve } return 0; }