function mimemail_extract_files in Mime Mail 7
Same name and namespace in other branches
- 5 mimemail.inc \mimemail_extract_files()
- 6 mimemail.inc \mimemail_extract_files()
Extracts links to local images from HTML documents.
Parameters
string $html: A string containing the HTML source of the message.
Return value
array An array containing the document body and the extracted files like the following. array( array( 'name' => document name 'content' => html text, local image urls replaced by Content-IDs, 'Content-Type' => 'text/html; charset=utf-8') array( 'name' => file name, 'file' => reference to local file, 'Content-ID' => generated Content-ID, 'Content-Type' => derived using mime_content_type if available, educated guess otherwise ) )
1 call to mimemail_extract_files()
- mimemail_html_body in ./
mimemail.inc - Generate a multipart message body with a text alternative for some HTML text.
File
- ./
mimemail.inc, line 114 - Common mail functions for sending e-mail. Originally written by Gerhard.
Code
function mimemail_extract_files($html) {
$pattern = '/(<link[^>]+href=[\'"]?|<object[^>]+codebase=[\'"]?|@import (?:url\\()?[\'"]?|[\\s]src=[\'"]?)([^\'>")]+)([\'"]?)/mis';
$content = preg_replace_callback($pattern, '_mimemail_replace_files', $html);
$encoding = '8Bit';
$body = explode("\n", $content);
foreach ($body as $line) {
if (drupal_strlen($line) > 998) {
$encoding = 'base64';
break;
}
}
if ($encoding == 'base64') {
$content = rtrim(chunk_split(base64_encode($content)));
}
$document = array(
array(
'Content-Type' => "text/html; charset=utf-8",
'Content-Transfer-Encoding' => $encoding,
'content' => $content,
),
);
$files = _mimemail_file();
return array_merge($document, $files);
}