Support cid URLs as used in mailstream plugin
authorMatthew Exon <mat.github@exon.name>
Sat, 27 Feb 2021 16:54:52 +0000 (16:54 +0000)
committerMatthew Exon <mat.github@exon.name>
Sat, 27 Feb 2021 16:54:52 +0000 (16:54 +0000)
src/Content/Text/BBCode.php
src/Content/Text/HTMLPurifier_URIScheme_cid.php [new file with mode: 0644]

index 25812db..51a1b05 100644 (file)
@@ -28,6 +28,7 @@ use Friendica\Content\ContactSelector;
 use Friendica\Content\Item;
 use Friendica\Content\OEmbed;
 use Friendica\Content\Smilies;
+use Friendica\Content\Text\HTMLPurifier_URIScheme_cid;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
@@ -1874,6 +1875,8 @@ class BBCode
                        $text
                );
 
+               \HTMLPurifier_URISchemeRegistry::instance()->register('cid', new HTMLPurifier_URIScheme_cid());
+
                $config = \HTMLPurifier_HTML5Config::createDefault();
                $config->set('HTML.Doctype', 'HTML5');
                $config->set('HTML.SafeIframe', true);
diff --git a/src/Content/Text/HTMLPurifier_URIScheme_cid.php b/src/Content/Text/HTMLPurifier_URIScheme_cid.php
new file mode 100644 (file)
index 0000000..f11e646
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace Friendica\Content\Text;
+
+use \HTMLPurifier_URIScheme;
+
+/**
+ * Validates content-id ("cid") as used in multi-part MIME messages, as defined by RFC 2392
+ */
+class HTMLPurifier_URIScheme_cid extends HTMLPurifier_URIScheme
+{
+       /**
+        * @type bool
+        */
+       public $browsable = true;
+
+       /**
+        * @type bool
+        */
+       public $may_omit_host = true;
+
+       /**
+        * @param HTMLPurifier_URI $uri
+        * @param HTMLPurifier_Config $config
+        * @param HTMLPurifier_Context $context
+        * @return bool
+        */
+       public function doValidate(&$uri, $config, $context)
+       {
+               $uri->userinfo = null;
+               $uri->host = null;
+               $uri->port = null;
+               $uri->query = null;
+               // typecode check needed on path
+               return true;
+       }
+}