- $id = 1;
- $matches = array();
- preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", $item["body"], $matches);
- if (count($matches)) {
- foreach ($matches[3] as $url) {
- $attachments[$url] = array();
+ 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) {
+ $redirects;
+ $cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-');
+ $attachments[$url] = array(
+ 'data' => fetch_url($url, true, $redirects, 0, Null, $cookiejar),
+ 'guid' => hash("crc32", $url),
+ 'filename' => basename($url),
+ 'type' => $a->get_curl_content_type());
+ if (strlen($attachments[$url]['data'])) {
+ $item['body'] = str_replace($url, 'cid:' . $attachments[$url]['guid'], $item['body']);
+ continue;