diff --git a/include/class.thread.php b/include/class.thread.php
index 0722c80d2027ca5691afe4dc37e805911f86658b..b11eac143cecda88779ccc7d2ee2c80cc1e890c2 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1036,7 +1036,7 @@ Class ThreadEntry {
                 // content-id will be discarded, only the unique hash-code
                 // will be available to retrieve the image later
                 if ($a['cid'] && $a['key']) {
-                    $body = str_replace('src="cid:'.$a['cid'].'"',
+                    $body = preg_replace('/src=("|\'|\b)cid:'.$a['cid'].'\1/i',
                         'src="cid:'.$a['key'].'"', $body);
                 }
             }