/functions/mime.php

Description

mime.php

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

Functions
buildAttachmentArray (line 516)

Generate attachments array for passing to templates.

  • since: 1.5.2
void buildAttachmentArray (object $message, array $exclude_id, string $mailbox, integer $id)
  • object $message: SquirrelMail message object
  • array $exclude_id: message parts that are not attachments.
  • string $mailbox: mailbox name
  • integer $id: message id
decodeBody (line 737)

Decodes encoded string (usually message body)

This function decodes a string (usually the message body) depending on the encoding type. Currently quoted-printable and base64 encodings are supported.

The decode_body hook was added to this function in 1.4.2/1.5.0. The $force_crlf parameter was added in 1.5.2.

  • return: The decoded string
  • since: 1.0
string decodeBody (string $string, string $encoding, [string $force_crlf = ''])
  • string $string: The encoded string
  • string $encoding: used encoding
  • string $force_crlf: Whether or not to force CRLF or LF line endings (or to leave as is). If given as "LF", line endings will all be converted to LF; if "CRLF", line endings will all be converted to CRLF. If given as an empty value, the global $force_crlf_default will be consulted (it can be specified in config/config_local.php). Otherwise, any other value will cause the string to be left alone. Note that this will be overridden to "LF" if not using at least PHP version 4.3.0. (OPTIONAL; default is empty - consult global default value)
decodeHeader (line 793)

Decodes headers

This function decodes strings that are encoded according to RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text). Patched by Christian Schmidt <christian@ostenfeld.dk> 23/03/2002

  • return: decoded header string
string decodeHeader (string $string, [boolean $utfencode = true], [boolean $htmlsafe = true], [boolean $decide = false])
  • string $string: header string that has to be made readable
  • boolean $utfencode: change message in order to be readable on user's charset. defaults to true
  • boolean $htmlsafe: preserve spaces and sanitize html special characters. defaults to true
  • boolean $decide: decide if string can be utfencoded. defaults to false
encodeHeader (line 942)

Encodes header

Function uses XTRA_CODE _encodeheader function, if such function exists.

Function uses Q encoding by default and encodes 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.

Function switches to B encoding and encodeHeaderBase64() function, if string is 8bit and multibyte character set supported by mbstring extension is used. It can cause E_USER_NOTICE errors, if interface is used with multibyte character set unsupported by mbstring extension.

  • return: quoted-printable encoded string
  • todo: make $mb_charsets system wide constant
string encodeHeader (string $string)
  • string $string: header string, that has to be encoded
encodeHeaderBase64 (line 1109)

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
  • todo: First header line can be wrapped to $iMaxLength - $HeaderFieldLength - 1
  • todo: Do we want to control max length of header?
  • todo: Do we want to control EOL (end-of-line) marker?
  • todo: Do we want to translate error message?
  • since: 1.5.1
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 1172)
void find_ent_id ( $id,  $message)
  • $id
  • $message
formatAttachments (line 671)

Displays attachment links and information

Since 1.3.0 function is not included in formatBody() call.

Since 1.0.2 uses attachment $type0/$type1 hook. Since 1.2.5 uses attachment $type0/* hook. Since 1.5.0 uses attachments_bottom hook. Since 1.5.2 uses templates and does *not* return a value.

void formatAttachments (object $message, array $exclude_id, string $mailbox, integer $id)
  • object $message: SquirrelMail message object
  • array $exclude_id: message parts that are not attachments.
  • string $mailbox: mailbox name
  • integer $id: message id
formatBody (line 357)

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.

Since 1.2.0 function uses message_body hook. Till 1.3.0 function included output of formatAttachments().

  • return: html formated message text
string formatBody (resource $imap_stream, object $message, array $color, integer $wrap_at, string $ent_num, integer $id, [string $mailbox = 'INBOX'])
  • resource $imap_stream: imap connection resource
  • object $message: squirrelmail message object
  • array $color: squirrelmail color theme array
  • integer $wrap_at: number of characters per line
  • string $ent_num: (since 1.3.0) message part id
  • integer $id: (since 1.3.0) message id
  • string $mailbox: (since 1.3.0) imap folder name
getEntity (line 287)
void getEntity ( $message,  $ent_id)
  • $message
  • $ent_id
getPriorityStr (line 259)
void getPriorityStr ( $priority)
  • $priority
listEntities (line 244)
void listEntities ( $message)
  • $message
magicHTML (line 2501)

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 $message, [$mailbox $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 $message
  • $mailbox $mailbox
mime_fetch_body (line 124)
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 193)
void mime_print_body_lines ( $imap_stream,  $id, [ $ent_id = 1],  $encoding, [ $rStream = 'php://stdout'], [ $force_crlf = ''])
  • $imap_stream
  • $id
  • $ent_id
  • $encoding
  • $rStream
  • $force_crlf
mime_structure (line 53)

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

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 680)
void sqimap_base64_decode ( &$string)
  • &$string
sq_body2div (line 2265)

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

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 1196)
void sq_check_save_extension ( $message)
  • $message
sq_cid2http (line 2201)

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

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

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

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

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

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)
  • $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
sq_fixIE_idiocy (line 1264)

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

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

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

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

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,  $mailbox)
  • $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
  • $mailbox
sq_skipspace (line 1386)

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

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

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 295)
void translateText ( &$body,  $wrap_at,  $charset)
  • &$body
  • $wrap_at
  • $charset

Documentation generated on Fri, 22 Aug 2014 04:18:47 +0200 by phpDocumentor 1.4.3