[mailstream] Support new img format with alt text
[friendica-addons.git/.git] / mailstream / mailstream.php
index c0ea211..563dd90 100644 (file)
@@ -163,13 +163,15 @@ function mailstream_do_images($a, &$item, &$attachments) {
        $attachments = [];
        preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", $item["body"], $matches1);
        preg_match_all("/\[img\](.*?)\[\/img\]/ism", $item["body"], $matches2);
-       foreach (array_merge($matches1[3], $matches2[1]) as $url) {
+       preg_match_all("/\[img\=([^\]]*)\]([^[]*)\[\/img\]/ism", $item["body"], $matches3);
+       foreach (array_merge($matches1[3], $matches2[1], $matches3[1]) as $url) {
+               $components = parse_url($url);
                $cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-');
                $curlResult = Network::fetchUrlFull($url, true, 0, '', $cookiejar);
                $attachments[$url] = [
                        'data' => $curlResult->getBody(),
                        'guid' => hash("crc32", $url),
-                       'filename' => basename($url),
+                       'filename' => basename($components['path']),
                        'type' => $curlResult->getContentType()
                ];
 
@@ -298,6 +300,7 @@ function mailstream_send(\Friendica\App $a, $message_id, $item, $user) {
                $mail->IsHTML(true);
                $mail->CharSet = 'utf-8';
                $template = Renderer::getMarkupTemplate('mail.tpl', 'addon/mailstream/');
+               $mail->AltBody = BBCode::toPlaintext($item['body']);
                $item['body'] = BBCode::convert($item['body']);
                $item['url'] = $a->getBaseURL() . '/display/' . $item['guid'];
                $mail->Body = Renderer::replaceMacros($template, [