Merge pull request #7861 from annando/mail-hook

E-Mail import: The item is now provided to the hook
This commit is contained in:
Hypolite Petovan 2019-11-23 08:33:45 -05:00 committed by GitHub
commit 5825f35422
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 18 deletions

View file

@ -6,8 +6,10 @@ namespace Friendica\Protocol;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Model\Item;
use Friendica\Util\Strings;
/**
* @brief Email class
@ -110,9 +112,9 @@ class Email
* @return array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getMessage($mbox, $uid, $reply)
public static function getMessage($mbox, $uid, $reply, $item)
{
$ret = [];
$ret = $item;
$struc = (($mbox && $uid) ? @imap_fetchstructure($mbox, $uid, FT_UID) : null);
@ -126,9 +128,15 @@ class Email
if (trim($ret['body']) == '') {
$ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'plain');
} else {
$message = ['text' => '', 'html' => $ret['body']];
$message = ['text' => $ret['body'], 'html' => '', 'item' => $ret];
Hook::callAll('email_getmessage', $message);
$ret = $message['item'];
$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']);
@ -148,8 +156,9 @@ class Email
}
}
$message = ['text' => trim($text), 'html' => trim($html)];
$message = ['text' => trim($text), 'html' => trim($html), 'item' => $ret];
Hook::callAll('email_getmessage', $message);
$ret = $message['item'];
$html = $message['html'];
$text = $message['text'];
@ -171,6 +180,9 @@ class Email
$ret['body'] = self::unifyAttributionLine($ret['body']);
$ret['body'] = Strings::escapeHtml($ret['body']);
$ret['body'] = BBCode::limitBodySize($ret['body']);
Hook::callAll('email_getmessage_end', $ret);
return $ret;

View file

@ -494,6 +494,8 @@ class OnePoll
Logger::log("Mail: Parsing mail ".$msg_uid, Logger::DATA);
$datarray = [];
$datarray['uid'] = $importer_uid;
$datarray['contact-id'] = $contact['id'];
$datarray['verb'] = Activity::POST;
$datarray['object-type'] = Activity\ObjectType::NOTE;
$datarray['network'] = Protocol::MAIL;
@ -596,18 +598,8 @@ class OnePoll
$datarray['parent-uri'] = $datarray['uri'];
}
$r = Email::getMessage($mbox, $msg_uid, $reply);
if (!$r) {
Logger::log("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']);
continue;
}
$datarray['body'] = Strings::escapeHtml($r['body']);
$datarray['body'] = BBCode::limitBodySize($datarray['body']);
Logger::log("Mail: Importing ".$msg_uid." for ".$mailconf['user']);
$headers = imap_headerinfo($mbox, $meta->msgno);
$object = [];
if (!empty($headers->from)) {
@ -643,16 +635,23 @@ class OnePoll
$datarray['owner-link'] = "mailto:".$contact['addr'];
$datarray['owner-avatar'] = $contact['photo'];
$datarray['uid'] = $importer_uid;
$datarray['contact-id'] = $contact['id'];
if ($datarray['parent-uri'] === $datarray['uri']) {
$datarray['private'] = 1;
}
if (!PConfig::get($importer_uid, 'system', 'allow_public_email_replies')) {
$datarray['private'] = 1;
$datarray['allow_cid'] = '<' . $contact['id'] . '>';
}
$datarray = Email::getMessage($mbox, $msg_uid, $reply, $datarray);
if (empty($datarray['body'])) {
Logger::log("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']);
continue;
}
Logger::log("Mail: Importing ".$msg_uid." for ".$mailconf['user']);
Item::insert($datarray);
switch ($mailconf['action']) {