/functions/mime.php

Description

mime.php

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

Functions
decodeBody (line 651)

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

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

  • return: decoded header string
string decodeHeader (string $string, [boolean $utfencode = true], [boolean $htmlsave = 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 $htmlsave: preserve spaces and sanitize html special characters. defaults to true
  • boolean $decide: decide if string can be utfencoded. defaults to false
encodeHeader (line 841)

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

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 1070)
void find_ent_id ( $id,  $message)
  • $id
  • $message
formatAttachments (line 508)

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

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'], [boolean $clean = FALSE])
  • 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
  • boolean $clean: (since 1.5.1) Do not output stuff that's irrelevant for the printable version.
getEntity (line 275)
void getEntity ( $message,  $ent_id)
  • $message
  • $ent_id
getPriorityStr (line 247)
void getPriorityStr ( $priority)
  • $priority
listEntities (line 232)
void listEntities ( $message)
  • $message
magicHTML (line 2089)

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, mixed $message, [mixed $mailbox = 'INBOX'], [boolean $take_mailto_links = true])
  • boolean $take_mailto_links: When TRUE, converts mailto: links into internal SM compose links (optional; default = TRUE)
mime_fetch_body (line 120)
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 181)
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 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 2316)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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