1
0
Fork 0

Merge pull request #7862 from annando/mail-again

Only read undeleted mails / improved structure
This commit is contained in:
Hypolite Petovan 2019-11-23 16:58:20 -05:00 committed by GitHub
commit 1cf44d92c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,21 +56,21 @@ class Email
return []; return [];
} }
$search1 = @imap_search($mbox, 'FROM "' . $email_addr . '"', SE_UID); $search1 = @imap_search($mbox, 'UNDELETED FROM "' . $email_addr . '"', SE_UID);
if (!$search1) { if (!$search1) {
$search1 = []; $search1 = [];
} else { } else {
Logger::log("Found mails from ".$email_addr, Logger::DEBUG); Logger::log("Found mails from ".$email_addr, Logger::DEBUG);
} }
$search2 = @imap_search($mbox, 'TO "' . $email_addr . '"', SE_UID); $search2 = @imap_search($mbox, 'UNDELETED TO "' . $email_addr . '"', SE_UID);
if (!$search2) { if (!$search2) {
$search2 = []; $search2 = [];
} else { } else {
Logger::log("Found mails to ".$email_addr, Logger::DEBUG); Logger::log("Found mails to ".$email_addr, Logger::DEBUG);
} }
$search3 = @imap_search($mbox, 'CC "' . $email_addr . '"', SE_UID); $search3 = @imap_search($mbox, 'UNDELETED CC "' . $email_addr . '"', SE_UID);
if (!$search3) { if (!$search3) {
$search3 = []; $search3 = [];
} else { } else {
@ -119,27 +119,29 @@ class Email
$struc = (($mbox && $uid) ? @imap_fetchstructure($mbox, $uid, FT_UID) : null); $struc = (($mbox && $uid) ? @imap_fetchstructure($mbox, $uid, FT_UID) : null);
if (!$struc) { if (!$struc) {
Logger::notice("IMAP structure couldn't be fetched", ['uid' => $uid]);
return $ret; return $ret;
} }
if (empty($struc->parts)) { if (empty($struc->parts)) {
$ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'html'); $html = trim(self::messageGetPart($mbox, $uid, $struc, 0, 'html'));
$html = $ret['body'];
if (trim($ret['body']) == '') { if (!empty($html)) {
$ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'plain'); $message = ['text' => '', 'html' => $html, 'item' => $ret];
Hook::callAll('email_getmessage', $message);
$ret = $message['item'];
if (empty($ret['body'])) {
$ret['body'] = HTML::toBBCode($message['html']);
}
}
$message = ['text' => $ret['body'], 'html' => '', 'item' => $ret]; if (empty($ret['body'])) {
$text = self::messageGetPart($mbox, $uid, $struc, 0, 'plain');
$message = ['text' => $text, 'html' => '', 'item' => $ret];
Hook::callAll('email_getmessage', $message); Hook::callAll('email_getmessage', $message);
$ret = $message['item']; $ret = $message['item'];
$ret['body'] = $message['text']; $ret['body'] = $message['text'];
} else {
$message = ['text' => '', 'html' => $ret['body'], 'item' => $ret];
Hook::callAll('email_getmessage', $message);
$ret = $message['item'];
$ret['body'] = $message['html'];
$ret['body'] = HTML::toBBCode($ret['body']);
} }
} else { } else {
$text = ''; $text = '';
@ -159,13 +161,13 @@ class Email
$message = ['text' => trim($text), 'html' => trim($html), 'item' => $ret]; $message = ['text' => trim($text), 'html' => trim($html), 'item' => $ret];
Hook::callAll('email_getmessage', $message); Hook::callAll('email_getmessage', $message);
$ret = $message['item']; $ret = $message['item'];
$html = $message['html'];
$text = $message['text'];
if (!empty($html)) { if (empty($ret['body']) && !empty($message['html'])) {
$ret['body'] = HTML::toBBCode($html); $ret['body'] = HTML::toBBCode($message['html']);
} else { }
$ret['body'] = $text;
if (empty($ret['body'])) {
$ret['body'] = $message['text'];
} }
} }