File/nasmail/functions/mime.php

Description

Copyright (c) 1999-2006 The SquirrelMail Project Team Copyright (c) 2006-2008 The NaSMail Project This file is part of NaSMail webmail interface.

This script stores functions necessary to detect and decode MIME messages.

This script contains modifications ported from SquirrelMail 1.4.9+. See commits tagged with SM-PATCH keyword. Modifications are copyrighted by the SquirrelMail Project Team. Copyright (c) 2007 The SquirrelMail Project Team

Includes
 include_once (SM_PATH.'functions/imap.php') (line 19)

The typical includes...

 include_once (SM_PATH.'functions/htmlfilter.php') (line 21)
 include_once (SM_PATH.'functions/attachment_common.php') (line 20)
Functions
decodeBody (line 639)

Decodes encoded message body

This function decodes the body depending on the encoding type. Currently quoted-printable and base64 encodings are supported.

Function executes decode_body hook.

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

Decodes MIME headers

This function decodes strings that are encoded according to RFC2047 (MIME Part Three: Message Header Extensions for Non-ASCII Text).

Function is not fully compatible with SquirrelMail decodeHeader() function. It should act same way only in SquirrelMail decoding environment. In SquirrelMail message composition uses fourth option. This option is not needed in utf-8 only environment and can be combined with second function argument. Modifications reduce number of function operation modes and simplifies testing.

  • return: decoded header string
  • todo: plain text decoding has some differences in space sanitizing
string decodeHeader (string $string, [boolean $utfencode = true], [boolean $htmlsave = true])
  • string $string: string header string
  • boolean $utfencode: utfencode controls conversion to utf-8
  • boolean $htmlsave: htmlsave controls html sanitizing
encodeHeader (line 800)

Encodes header

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

Function switches to encodeHeaderBase64() with multibyte character set is used and PHP mbstring extension supports it. Q encoding is used as fallback encoding and when text is not 8bit.

WARNING: Function does not fold header. Encoded string is divided into atoms that are suitable for folding.

  • return: Encoded string
  • todo: Add iso646 (not us-ascii) support. Low priority. Code usually uses only utf-8.
string encodeHeader (string $string, [string $charset = 'utf-8'])
  • string $string: string Text that must be encoded
  • string $charset: charset Used character set
encodeHeaderBase64 (line 927)

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)

WARNING: Function does not fold header. Encoded string is divided into atoms that are suitable for folding.

  • return: string encoded according to rfc2047 B encoding formating rules
string encodeHeaderBase64 (string $string, string $charset)
  • string $string: string header string that must be encoded
  • string $charset: charset character set. Must be supported by mbstring extension. Use sq_mb_list_encodings() to detect supported charsets.
find_ent_id (line 996)

This function trys to locate the entity_id of a specific mime element

string find_ent_id (string $id, object Message $message)
  • string $id: id Message part ID
  • object Message $message: message Message object
formatAttachments (line 456)

Format attachment block

string formatAttachments (object Message $message, array $exclude_id, string $mailbox, int $id)
  • array $exclude_id
  • int $id
  • object Message $message: message
  • string $mailbox: mailbox Mailbox name
formatBody (line 343)

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.

string formatBody (stream $imap_stream, object Message $message, array $color, int $wrap_at, string $ent_num, int $id, [string $mailbox = 'INBOX'], [boolean $clean = false])
  • object Message $message
  • string $ent_num
  • int $id
  • boolean $clean
  • stream $imap_stream: imap_stream IMAP connection resource
  • array $color: color Color theme
  • int $wrap_at: wrap_at Max number of characters per line
  • string $mailbox: mailbox Mailbox
getEntity (line 275)

returns a $message object for a particular entity id

object Message getEntity (object Message $message, string $ent_id)
getPriorityStr (line 241)

Converts priority to human readable string

  • return: Human readable priority string
string getPriorityStr (int $priority)
  • int $priority: priority Priority level
listEntities (line 220)

Prints message entities

This is here for debugging purposes. It will print out a list of all the entity IDs that are in the $message object.

object Message listEntities (object Message $message)
mime_fetch_body (line 110)

This starts the parsing of a particular structure. It is called recursively, so it can be passed different structures. It returns an object of type $message.

First, it checks to see if it is a multipart message. If it is, then it handles that as it sees is necessary. If it is just a regular entity, then it parses it and adds the necessary header information (by calling out to mime_get_elements()

string mime_fetch_body (stream $imap_stream, int $id, [string $ent_id = 1], [int $fetch_size = 0])
  • stream $imap_stream: imap_stream IMAP connection resource
  • int $id: id Message ID
  • string $ent_id: ent_id Message part ID
  • int $fetch_size: fetch_size fetched size
mime_print_body_lines (line 179)
void mime_print_body_lines (stream $imap_stream, int $id, [string $ent_id = 1], string $encoding, [resource|string $rStream = 'php://stdout'])
  • resource|string $rStream: (since 1.1 (sm-1.4.10))
  • stream $imap_stream: imap_stream IMAP connection resource
  • int $id: id Message id
  • string $ent_id: ent_id Message part ID
  • string $encoding: encoding message part encoding
mime_structure (line 37)

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.

object Message mime_structure (string $bodystructure, [array $flags = array()])
  • string $bodystructure: bodystructure
  • array $flags: flags
SendDownloadHeaders (line 1047)

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, [integer $filesize = 0])
  • string $type0: type0 first half of mime type
  • string $type1: type1 second half of mime type
  • string $filename: filename filename to tell the browser for downloaded file
  • boolean $force: force whether to force the download dialog to pop
  • integer $filesize: filesize send the Content-Header and length to the browser
sqimap_base64_decode (line 604)

Decodes base64 string

string sqimap_base64_decode (string &$string)
  • string &$string: string
sq_check_save_extension (line 1026)

Checks, if message contains image attachment

boolean sq_check_save_extension (object Message $message)
translateText (line 286)

translateText

void translateText (string &$body, int $wrap_at, string $charset)
  • string &$body: body Text
  • int $wrap_at: wrap_at max number of symbols
  • string $charset: charset character set used in $body

Documentation generated on Sun, 22 Nov 2009 17:36:42 +0200 by phpDocumentor 1.4.3