collect() public method

Constructor
public collect ( $mailgateID, $display ) : if
$mailgateID ID of the mailgate
$display display messages in MessageAfterRedirect or just return error (default 0=)
return if $display = false return messages result string
Example #1
0
        Event::log($newID, "mailcollector", 4, "setup", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"]));
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($mailgate->getFormURL() . "?id=" . $newID);
        }
    }
    Html::back();
} else {
    if (isset($_POST["purge"])) {
        $mailgate->check($_POST['id'], PURGE);
        $mailgate->delete($_POST, 1);
        Event::log($_POST["id"], "mailcollector", 4, "setup", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
        $mailgate->redirectToList();
    } else {
        if (isset($_POST["update"])) {
            $mailgate->check($_POST['id'], UPDATE);
            $mailgate->update($_POST);
            Event::log($_POST["id"], "mailcollector", 4, "setup", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
            Html::back();
        } else {
            if (isset($_POST["get_mails"])) {
                $mailgate->check($_POST['id'], UPDATE);
                $mailgate->collect($_POST["id"], 1);
                Html::back();
            } else {
                Html::header(MailCollector::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "config", "mailcollector");
                $mailgate->display(array('id' => $_GET["id"]));
                Html::footer();
            }
        }
    }
}
 /**
  * Cron action on mailgate : retrieve mail and create tickets
  *
  * @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 MailCollector();
             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->log("{$message}\n");
                 $task->addVolume($mc->fetch_emails);
                 $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;
 }