/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 607)

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 642)

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 777)

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 940)

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 1003)
void find_ent_id ( $id,  $message)
  • $id
  • $message
formatAttachments (line 431)
void formatAttachments ( $message,  $exclude_id,  $mailbox,  $id)
  • $message
  • $exclude_id
  • $mailbox
  • $id
formatBody (line 312)

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 249)
void getEntity ( $message,  $ent_id)
  • $message
  • $ent_id
getPriorityStr (line 221)
void getPriorityStr ( $priority)
  • $priority
listEntities (line 206)
void listEntities ( $message)
  • $message
magicHTML (line 2374)

This is a wrapper function to call html sanitizing routines.

  • return: string with html safe to display in the browser.
a magicHTML ($body $body, $id $id,  $message, [ $mailbox = 'INBOX'], [boolean $take_mailto_links = true])
  • boolean $take_mailto_links: When TRUE, converts mailto: links into internal SM compose links (optional; default = TRUE)
  • $body $body: the body of the message
  • $id $id: the id of the message
  • $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 170)
void mime_print_body_lines ( $imap_stream,  $id, [ $ent_id = 1],  $encoding, [ $rStream = 'php://stdout'])
  • $imap_stream
  • $id
  • $ent_id
  • $encoding
  • $rStream
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 2653)

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, [optional $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
  • optional $filesize: integer $filesize send the Content-Header and length to the browser
sqimap_base64_decode (line 572)
void sqimap_base64_decode ( &$string)
  • &$string
sq_body2div (line 2101)

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 ($attary $attary, $mailbox $mailbox, $message $message, $id $id)
  • $attary $attary: an array of attributes and values of <body>
  • $mailbox $mailbox: mailbox we're currently reading (for cid2http)
  • $message $message: current message (for cid2http)
  • $id $id: current message id (for cid2http)
sq_casenormalize (line 1198)

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 ($val &$val)
  • $val &$val: a value passed by-ref.
sq_check_save_extension (line 1027)
void sq_check_save_extension ( $message)
  • $message
sq_cid2http (line 2037)

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 ($message $message, $id $id, $cidurl $cidurl, $mailbox $mailbox)
  • $message $message: the message object
  • $id $id: the message id
  • $cidurl $cidurl: the cid: url.
  • $mailbox $mailbox: the message mailbox
sq_deent (line 1568)

Translates entities into literal values so they can be checked.

  • return: or False depending on whether there were matches.
True sq_deent ($attvalue &$attvalue, $regex $regex, [$hex $hex = false])
  • $attvalue &$attvalue: the by-ref value to check.
  • $regex $regex: the regular expression to check against.
  • $hex $hex: whether the entites are hexadecimal.
sq_defang (line 1047)

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 ($attvalue &$attvalue)
  • $attvalue &$attvalue: A string to run entity check against.
sq_findnxreg (line 1254)

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 ($body $body, $offset $offset, $reg $reg)
  • $body $body: The string to look for needle in.
  • $offset $offset: Start looking from here.
  • $reg $reg: A PCRE-style regex to match.
sq_findnxstr (line 1232)

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 ($body $body, $offset $offset, $needle $needle)
  • $body $body: The string to look for needle in.
  • $offset $offset: Start looking from this position.
  • $needle $needle: The character/string to look for.
sq_fixatts (line 1601)

This function runs various checks against the attributes.

  • return: with modified attributes.
Array sq_fixatts ($tagname $tagname, $attary $attary, $rm_attnames $rm_attnames, $bad_attvals $bad_attvals, $add_attr_to_tag $add_attr_to_tag, $message $message, $id $id, $mailbox $mailbox)
  • $tagname $tagname: String with the name of the tag.
  • $attary $attary: Array with all tag attributes.
  • $rm_attnames $rm_attnames: See description for sq_sanitize
  • $bad_attvals $bad_attvals: See description for sq_sanitize
  • $add_attr_to_tag $add_attr_to_tag: See description for sq_sanitize
  • $message $message: message object
  • $id $id: message id
  • $mailbox $mailbox: mailbox
sq_fixIE_idiocy (line 1090)

Translate all dangerous Unicode or Shift_JIS characters which are accepted by IE as regular characters.

  • return: Nothing, modifies a reference value.
  • author: Marc Groot Koerkamp.
attvalue sq_fixIE_idiocy (attvalue &$attvalue)
  • attvalue &$attvalue: The attribute value before dangerous characters are translated.
sq_fixstyle (line 1871)

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

  • return: string with edited content.
a sq_fixstyle ($message $body, $id $pos, $content $message, $mailbox $id,  $mailbox)
  • $message $body: the message object
  • $id $pos: the message id
  • $content $message: a string with whatever is between <style> and </style>
  • $mailbox $id: the message mailbox
  • $mailbox
sq_fix_url (line 1715)

This function filters url's

void sq_fix_url ($attvalue $attname, $message &$attvalue, $id $message, $mailbox $id, $sQuote $mailbox, [ $sQuote = '&quot;'])
  • $attvalue $attname: String with attribute value to filter
  • $message &$attvalue: message object
  • $id $message: message id
  • $mailbox $id: mailbox
  • $sQuote $mailbox: quoting characters around url's
  • $sQuote
sq_getnxtag (line 1283)

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 ($body $body, $offset $offset)
  • $body $body: String where to look for the next tag.
  • $offset $offset: Start looking from here.
sq_sanitize (line 2152)

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 ($body $body, $tag_list $tag_list, $rm_tags_with_content $rm_tags_with_content, $self_closing_tags $self_closing_tags, $force_tag_closing $force_tag_closing, $rm_attnames $rm_attnames, $bad_attvals $bad_attvals, $add_attr_to_tag $add_attr_to_tag, $message $message, $id $id, $recursively_called $mailbox, [ $recursively_called = FALSE])
  • $body $body: the string with HTML you wish to filter
  • $tag_list $tag_list: see description above
  • $rm_tags_with_content $rm_tags_with_content: see description above
  • $self_closing_tags $self_closing_tags: see description above
  • $force_tag_closing $force_tag_closing: see description above
  • $rm_attnames $rm_attnames: see description above
  • $bad_attvals $bad_attvals: see description above
  • $add_attr_to_tag $add_attr_to_tag: see description above
  • $message $message: message object
  • $id $id: message id
  • $recursively_called $mailbox: boolean flag for recursive calls into this function (optional; default FALSE)
  • $recursively_called
sq_skipspace (line 1212)

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 ($body $body, $offset $offset)
  • $body $body: the string
  • $offset $offset: the offset within the string where we should start looking for the next non-whitespace character.
sq_tagprint (line 1169)

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 ($tagname $tagname, $attary $attary, $tagtype $tagtype)
  • $tagname $tagname: the name of the tag.
  • $attary $attary: the array of attributes and their values
  • $tagtype $tagtype: The type of the tag (see in comments).
sq_unspace (line 1074)

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 (attvalue &$attvalue)
  • attvalue &$attvalue: The attribute value before extraneous spaces removed.
translateText (line 257)
void translateText ( &$body,  $wrap_at,  $charset)
  • &$body
  • $wrap_at
  • $charset

Documentation generated on Mon, 13 Jan 2020 04:24:57 +0100 by phpDocumentor 1.4.3