You are here

static function MailMIME::guess_mimetype in Mail MIME 6.2

Same name and namespace in other branches
  1. 8.2 mailmime.inc \MailMIME::guess_mimetype()

Guess the content type of a file or inline data stream.

Uses the Mime Detect module if available; otherwise uses the file_get_mimetype() function. Provides a smaller-than-default mime-type mapping to improve performance a bit.

Parameters

$filename: The name of the file, used for guessing the mime type based on the filename extension.

$data: (optional) The contents of the file, used by the Mime Detect module if it is available. If omitted or blank, the Mime Detect module will try to open the file referenced by the $filename parameter.

Return value

The MIME content-type matching the file contents or filename extension, or "application/octet-stream" if no match could be found.

1 call to MailMIME::guess_mimetype()
MailMIME::addHTMLImage in ./mailmime.inc
Adds an image to the list of embedded images.

File

./mailmime.inc, line 284
Provides the MailMIME class for creating MIME-formatted email messages.

Class

MailMIME
The MailMIME class is used to create MIME email messages.

Code

static function guess_mimetype($filename, $data = NULL) {
  static $mapping;

  // @todo: Use Mime Detect module if available.
  if (!isset($mapping)) {
    $mapping = array(
      'pdf' => 'application/pdf',
      'ps|ai|eps' => 'application/postscript',
      'km(l|z)' => 'application/vnd.google-earth',
      'pp(a|s|t)(m|x|)' => 'application/vnd.ms-powerpoint',
      'swf(l|)' => 'application/x-shockwave-flash',
      'gif' => 'image/gif',
      'jp(e|eg|g)' => 'image/jpeg',
      'pcx' => 'image/pcx',
      'png' => 'image/png',
      'svg(z|)' => 'image/svg+xml',
      'tif(f|)' => 'image/tiff',
      'wbmp' => 'image/vnd.wap.wbmp',
      'ico' => 'image/x-icon',
      'art' => 'image/x-jg',
      'bmp' => 'image/x-ms-bmp',
      'eml' => 'message/rfc822',
      'ics|icz' => 'text/calendar',
      'css' => 'text/css',
      'vrm(l|)|wrl' => 'x-world/x-vrml',
    );
    $mapping = variable_get('mime_extension_mapping', $mapping);
  }
  return file_get_mimetype($filename, $mapping);
}