X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mailstream%2Fmailstream.php;h=d76ccf86e61cdc8428c52f3fb7beb810a48247f3;hb=d9c54193518678408093f21101b1bcc1c5796d57;hp=1392d0d1d611286124ee951c66c0cd41beb41e4c;hpb=4b315884842a2861f52b1d07526ef7c322262286;p=friendica-addons.git diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 1392d0d1..d76ccf86 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -102,7 +102,7 @@ function mailstream_addon_admin_post() */ function mailstream_generate_id(string $uri): string { - $host = DI::baseUrl()->getHostname(); + $host = DI::baseUrl()->getHost(); $resource = hash('md5', $uri); $message_id = "<" . $resource . "@" . $host . ">"; Logger::debug('mailstream: Generated message ID ' . $message_id . ' for URI ' . $uri); @@ -214,7 +214,12 @@ function mailstream_do_images(array &$item, array &$attachments) } $cookiejar = tempnam(System::getTempPath(), 'cookiejar-mailstream-'); - $curlResult = DI::httpClient()->fetchFull($url, HttpClientAccept::DEFAULT, 0, $cookiejar); + try { + $curlResult = DI::httpClient()->fetchFull($url, HttpClientAccept::DEFAULT, 0, $cookiejar); + } catch (InvalidArgumentException $e) { + Logger::error('mailstream_do_images exception fetching url', ['url' => $url, 'item_id' => $item['id']]); + continue; + } $attachments[$url] = [ 'data' => $curlResult->getBody(), 'guid' => hash('crc32', $url), @@ -253,12 +258,13 @@ function mailstream_sender(array $item): string * Converts a bbcode-encoded subject line into a plaintext version suitable for the subject line of an email * * @param string $subject bbcode-encoded subject line + * @param int $uri_id * * @return string plaintext subject line */ -function mailstream_decode_subject(string $subject): string +function mailstream_decode_subject(string $subject, int $uri_id): string { - $html = BBCode::convert($subject); + $html = BBCode::convertForUriId($uri_id, $subject); if (!$html) { return $subject; } @@ -293,7 +299,7 @@ function mailstream_decode_subject(string $subject): string function mailstream_subject(array $item): string { if ($item['title']) { - return mailstream_decode_subject($item['title']); + return mailstream_decode_subject($item['title'], $item['uri-id']); } $parent = $item['thr-parent']; // Don't look more than 100 levels deep for a subject, in case of loops @@ -306,7 +312,7 @@ function mailstream_subject(array $item): string break; } if ($parent_item['title']) { - return DI::l10n()->t('Re:') . ' ' . mailstream_decode_subject($parent_item['title']); + return DI::l10n()->t('Re:') . ' ' . mailstream_decode_subject($parent_item['title'], $item['uri-id']); } $parent = $parent_item['thr-parent']; } @@ -328,7 +334,7 @@ function mailstream_subject(array $item): string return DI::l10n()->t("Diaspora post"); } if ($contact['network'] === 'face') { - $text = mailstream_decode_subject($item['body']); + $text = mailstream_decode_subject($item['body'], $item['uri-id']); // For some reason these do show up in Facebook $text = preg_replace('/\xA0$/', '', $text); $subject = (strlen($text) > 150) ? (substr($text, 0, 140) . '...') : $text; @@ -412,7 +418,7 @@ function mailstream_send(string $message_id, array $item, array $user): bool $template = Renderer::getMarkupTemplate('mail.tpl', 'addon/mailstream/'); $mail->AltBody = BBCode::toPlaintext($item['body']); $item['body'] = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::CONNECTORS); - $item['url'] = DI::baseUrl()->get() . '/display/' . $item['guid']; + $item['url'] = DI::baseUrl() . '/display/' . $item['guid']; $mail->Body = Renderer::replaceMacros($template, [ '$upstream' => DI::l10n()->t('Upstream'), '$uri' => DI::l10n()->t('URI'),