/functions/mime.php

Description

mime.php

This contains the functions necessary to detect and decode MIME messages.

Includes
require_once (SM_PATH.'functions/imap.php') (line 16)

The typical includes...

Functions
decodeBody (line 556)

Decodes encoded message body

This function decodes the body depending on the encoding type. Currently quoted-printable and base64 encodings are supported. decode_body hook was added to this function in 1.4.2/1.5.0

  • return: decoded string
  • since: 1.0
string decodeBody (string $body, string $encoding)
  • string $body: encoded message body
  • string $encoding: used encoding
decodeHeader (line 591)

Decodes headers

This functions decode strings that is encoded according to RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text). Patched by Christian Schmidt <[email protected]> 23/03/2002

void decodeHeader ( $string, [ $utfencode = true], [ $htmlsave = true], [ $decide = false])
  • $string
  • $utfencode
  • $htmlsave
  • $decide
encodeHeader (line 717)

Encodes header as quoted-printable

Encode a string according to RFC 1522 for use in headers if it contains 8-bit characters or anything that looks like it should be encoded.

void encodeHeader ( $string)
  • $string
encodeHeaderBase64 (line 879)

Encodes string according to rfc2047 B encoding header formating rules

It is recommended way to encode headers with character sets that store symbols in more than one byte.

Function requires mbstring support. If required mbstring functions are missing, function returns false and sets E_USER_WARNING level error message.

Minimal requirements - php 4.0.6 with mbstring extension. Please note, that mbstring functions will generate E_WARNING errors, if unsupported character set is used. mb_encode_mimeheader function provided by php mbstring extension is not used in order to get better control of header encoding.

Used php code functions - function_exists(), trigger_error(), strlen() (is used with charset names and base64 strings). Used php mbstring functions - mb_strlen and mb_substr.

Related documents: rfc 2045 (BASE64 encoding), rfc 2047 (mime header encoding), rfc 2822 (header folding)

  • return: string encoded according to rfc2047 B encoding formating rules
  • since: 1.5.1 and 1.4.6
string encodeHeaderBase64 (string $string, string $charset)
  • string $string: header string that must be encoded
  • string $charset: character set. Must be supported by mbstring extension. Use sq_mb_list_encodings() to detect supported charsets.
find_ent_id (line 942)
void find_ent_id ( $id,  $message)
  • $id
  • $message
formatAttachments (line 393)
void formatAttachments ( $message,  $exclude_id,  $mailbox,  $id)
  • $message
  • $exclude_id
  • $mailbox
  • $id
formatBody (line 300)

This returns a parsed string called $body. That string can then be displayed as the actual message in the HTML. It contains everything needed, including HTML Tags, Attachments at the bottom, etc.

void formatBody ( $imap_stream,  $message,  $color,  $wrap_at,  $ent_num,  $id, [ $mailbox = 'INBOX'], [ $clean = false])
  • $imap_stream
  • $message
  • $color
  • $wrap_at
  • $ent_num
  • $id
  • $mailbox
  • $clean
getEntity (line 237)
void getEntity ( $message,  $ent_id)
  • $message
  • $ent_id
getPriorityStr (line 209)
void getPriorityStr ( $priority)
  • $priority
listEntities (line 194)
void listEntities ( $message)
  • $message
magicHTML (line 1949)

This is a wrapper function to call html sanitizing routines.

  • return: string with html safe to display in the browser.
a magicHTML (mixed $body, mixed $id,  $message, [ $mailbox = 'INBOX'])
  • $message
  • $mailbox
mime_fetch_body (line 100)
void mime_fetch_body ( $imap_stream,  $id, [ $ent_id = 1], [ $fetch_size = 0])
  • $imap_stream
  • $id
  • $ent_id
  • $fetch_size
mime_print_body_lines (line 162)
void mime_print_body_lines ( $imap_stream,  $id, [ $ent_id = 1],  $encoding)
  • $imap_stream
  • $id
  • $ent_id
  • $encoding
mime_structure (line 30)

Get the MIME structure

This function gets the structure of a message and stores it in the "message" class. It will return this object for use with all relevant header information and fully parsed into the standard "message" object format.

void mime_structure ( $bodystructure, [ $flags = array()])
  • $bodystructure
  • $flags
SendDownloadHeaders (line 2118)

function SendDownloadHeaders - send file to the browser

Original Source: SM core src/download.php moved here to make it available to other code, and separate front end from back end functionality.

void SendDownloadHeaders (string $type0, string $type1, string $filename, boolean $force, [mixed $filesize = 0])
  • string $type0: first half of mime type
  • string $type1: second half of mime type
  • string $filename: filename to tell the browser for downloaded file
  • boolean $force: whether to force the download dialog to pop
sqimap_base64_decode (line 521)
void sqimap_base64_decode ( &$string)
  • &$string
sq_body2div (line 1737)

This function changes the <body> tag into a <div> tag since we can't really have a body-within-body.

  • return: modified array of attributes to be set for <div>
a sq_body2div (mixed $attary, mixed $mailbox, mixed $message, mixed $id)
sq_casenormalize (line 1060)

A small helper function to use with array_walk. Modifies a by-ref value and makes it lowercase.

  • return: since it modifies a by-ref value.
void sq_casenormalize (mixed &$val)
sq_check_save_extension (line 966)
void sq_check_save_extension ( $message)
  • $message
sq_cid2http (line 1673)

This function converts cid: url's into the ones that can be viewed in the browser.

  • return: string with a http-friendly url
a sq_cid2http (mixed $message, mixed $id, mixed $cidurl, mixed $mailbox)
sq_deent (line 1431)

Translates entities into literal values so they can be checked.

  • return: or False depending on whether there were matches.
True sq_deent (mixed &$attvalue, mixed $regex, [mixed $hex = false])
sq_defang (line 986)

This function checks attribute values for entity-encoded values and returns them translated into 8-bit strings so we can run checks on them.

  • return: modifies a reference value.
Nothing, sq_defang (mixed &$attvalue)
sq_findnxreg (line 1117)

This function takes a PCRE-style regexp and tries to match it within the string.

  • return: a false if no matches found, or an array with the following members:
    • integer with the location of the match within $body
    • string with whatever content between offset and the match
    • string with whatever it is we matched
Returns sq_findnxreg (mixed $body, mixed $offset, mixed $reg)
sq_findnxstr (line 1095)

This function looks for the next character within a string. It's really just a glorified "strpos", except it catches if failures nicely.

  • return: of the next occurance of the needle, or strlen($body) if needle wasn't found.
location sq_findnxstr (mixed $body, mixed $offset, mixed $needle)
sq_fixatts (line 1463)

This function runs various checks against the attributes.

  • return: with modified attributes.
Array sq_fixatts (mixed $tagname, mixed $attary, mixed $rm_attnames, mixed $bad_attvals, mixed $add_attr_to_tag, mixed $message, mixed $id,  $mailbox)
  • $mailbox
sq_fixstyle (line 1567)

This function edits the style definition to make them friendly and usable in SquirrelMail.

  • return: string with edited content.
a sq_fixstyle (mixed $body, mixed $pos, mixed $message, mixed $id,  $mailbox)
  • $mailbox
sq_getnxtag (line 1146)

This function looks for the next tag.

  • return: if no more tags exist in the body, or an array with the following members:
    • string with the name of the tag
    • array with attributes and their values
    • integer with tag type (1, 2, or 3)
    • integer where the tag starts (starting "<")
    • integer where the tag ends (ending ">")
    first three members will be false, if the tag is invalid.
false sq_getnxtag (mixed $body, mixed $offset)
sq_sanitize (line 1787)

This is the main function and the one you should actually be calling.

There are several variables you should be aware of an which need special description.

Since the description is quite lengthy, see it here: http://linux.duke.edu/projects/mini/htmlfilter/

  • return: html safe to show on your pages.
sanitized sq_sanitize (mixed $body, mixed $tag_list, mixed $rm_tags_with_content, mixed $self_closing_tags, mixed $force_tag_closing, mixed $rm_attnames, mixed $bad_attvals, mixed $add_attr_to_tag, mixed $message, mixed $id,  $mailbox)
  • $mailbox
sq_skipspace (line 1074)

This function skips any whitespace from the current position within a string and to the next non-whitespace value.

  • return: location within the $body where the next non-whitespace char is located.
the sq_skipspace (mixed $body, mixed $offset)
sq_tagprint (line 1031)

This function returns the final tag out of the tag name, an array of attributes, and the type of the tag. This function is called by sq_sanitize internally.

  • return: string with the final tag representation.
a sq_tagprint (mixed $tagname, mixed $attary, mixed $tagtype)
sq_unspace (line 1013)

Kill any tabs, newlines, or carriage returns. Our friends the makers of the browser with 95% market value decided that it'd be funny to make "java[tab]script" be just as good as "javascript".

  • return: Nothing, modifies a reference value.
attvalue sq_unspace (mixed &$attvalue)
translateText (line 245)
void translateText ( &$body,  $wrap_at,  $charset)
  • &$body
  • $wrap_at
  • $charset

Documentation generated on Sat, 07 Oct 2006 16:32:29 +0300 by phpDocumentor 1.3.0RC6