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
string
decodeBody
(string $body, string $encoding)
-
string
$body: encoded message body
-
string
$encoding: used encoding
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
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)
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)
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.
void
find_ent_id
( $id, $message)
formatAttachments (line
431)
void
formatAttachments
( $message, $exclude_id, $mailbox, $id)
-
$message
-
$exclude_id
-
$mailbox
-
$id
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
void
getEntity
( $message, $ent_id)
getPriorityStr (line
221)
void
getPriorityStr
( $priority)
void
listEntities
( $message)
This is a wrapper function to call html sanitizing routines.
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
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()])
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)
This function changes the <body> tag into a <div> tag since we can't really have a body-within-body.
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.
void
sq_casenormalize
($val &$val)
-
$val
&$val: a value passed by-ref.
sq_check_save_extension (line
1027)
void
sq_check_save_extension
( $message)
This function converts cid: url's into the ones that can be viewed in the browser.
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
Translates entities into literal values so they can be checked.
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.
This function checks attribute values for entity-encoded values and returns them translated into 8-bit strings so we can run checks on them.
Nothing,
sq_defang
($attvalue &$attvalue)
-
$attvalue
&$attvalue: A string to run entity check against.
This function takes a PCRE-style regexp and tries to match it within the string.
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.
This function looks for the next character within a string. It's really just a glorified "strpos", except it catches if failures nicely.
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.
This function runs various checks against the 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.
attvalue
sq_fixIE_idiocy
(attvalue &$attvalue)
-
attvalue
&$attvalue: The attribute value before dangerous characters are translated.
This function edits the style definition to make them friendly and usable in SquirrelMail.
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
This function filters url's
void
sq_fix_url
($attvalue $attname, $message &$attvalue, $id $message, $mailbox $id, $sQuote $mailbox, [ $sQuote = '"'])
-
$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
This function looks for the next tag.
false
sq_getnxtag
($body $body, $offset $offset)
-
$body
$body: String where to look for the next tag.
-
$offset
$offset: Start looking from here.
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/
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
This function skips any whitespace from the current position within a string and to the next non-whitespace value.
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.
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.
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).
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".
attvalue
sq_unspace
(attvalue &$attvalue)
-
attvalue
&$attvalue: The attribute value before extraneous spaces removed.
void
translateText
( &$body, $wrap_at, $charset)