mail bugfix

This commit is contained in:
Roman 2021-04-09 16:30:49 +02:00
parent 779550cab4
commit d41cc29845

@ -199,6 +199,18 @@ namespace Api\Mail {
return $this->success; return $this->success;
} }
private function parseDate($date) {
$formats = [null, "D M d Y H:i:s e+"];
foreach ($formats as $format) {
try {
return ($format === null ? new \DateTime($date) : \DateTime::createFromFormat($format, $date));
} catch (\Exception $exception) {
}
}
return $this->createError("Could not parse date: $date");
}
public function execute($values = array()): bool { public function execute($values = array()): bool {
if (!parent::execute($values)) { if (!parent::execute($values)) {
return false; return false;
@ -254,7 +266,11 @@ namespace Api\Mail {
$messages = []; $messages = [];
foreach ($result as $msgNo) { foreach ($result as $msgNo) {
$header = imap_headerinfo($mbox, $msgNo); $header = imap_headerinfo($mbox, $msgNo);
$date = new \DateTime($header->date); $date = $this->parseDate($header->date);
if ($date === false) {
return false;
}
if ($lastSync === 0 || \datetimeDiff($lastSyncDateTime, $date) > 0) { if ($lastSync === 0 || \datetimeDiff($lastSyncDateTime, $date) > 0) {
$references = property_exists($header, "references") ? $references = property_exists($header, "references") ?
@ -300,7 +316,7 @@ namespace Api\Mail {
} }
@imap_close($mbox); @imap_close($mbox);
if (!$this->insertMessages($messages)) { if (!empty($messages) && !$this->insertMessages($messages)) {
return false; return false;
} }