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
* @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);
if (trim($ret['body']) == '') {
$ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'plain');
+
+ $message = ['text' => $ret['body'], 'html' => ''];
+ Hook::callAll('email_getmessage', $message, $ret);
+ $ret['body'] = $message['text'];
} else {
$message = ['text' => '', 'html' => $ret['body']];
- Hook::callAll('email_getmessage', $message);
+ Hook::callAll('email_getmessage', $message, $ret);
$ret['body'] = $message['html'];
$ret['body'] = HTML::toBBCode($ret['body']);
}
$message = ['text' => trim($text), 'html' => trim($html)];
- Hook::callAll('email_getmessage', $message);
+ Hook::callAll('email_getmessage', $message, $ret);
$html = $message['html'];
$text = $message['text'];
$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;
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;
$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);
+ $headers2 = imap_rfc822_parse_headers(imap_fetchheader($mbox, $meta->msgno));
+ Logger::info('Got header', ['header' => $headers2]);
+
$object = [];
if (!empty($headers->from)) {
$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']) {