Class Swift_Message_Encoder

Description

Encodes strings in a variety of formats and detects some encoding formats

Located in /Swift/Message/Encoder.php (line 20)


	
			
Class Constant Summary
 CHEAP_ADDRESS_RE = '(?#Start of dot-atom )[-!#\$%&\'\*\+\/=\?\^_`{}\|~0-9A-Za-z]+(?:\.[-!#\$%&\'\*\+\/=\?\^_`{}\|~0-9A-Za-z]+)*(?# End of dot-atom)(?:@(?#Start of domain)[-0-9A-Za-z]+(?:\.[-0-9A-Za-z]+)*(?#End of domain))?'
Variable Summary
Method Summary
static Message_Encoder instance ()
array addressChunk (string $input)
string base64Encode (string $data, [int $chunk = 76], [int $init_chunk = 0], [boolean $headers = false], [string $le = "\r\n"])
Swift_Cache_OutputStream base64EncodeFile ( $file, [int $chunk = 76], [string $le = "\r\n"])
string encode7Bit (string $data, [int $chunk = 76], [string $le = "\r\n"])
Swift_Cache_OutputStream encode7BitFile ( $file, [int $chunk = 76], [string $le = "\r\n"])
string encode7BitPrintable (string $data)
string encode8Bit (string $data, [int $chunk = 76], [string $le = "\r\n"])
Swift_Cache_OutputStream encode8BitFile ( $file, [int $chunk = 76], [string $le = "\r\n"])
string fixLE (string $data,  $le)
void getHcf ( $value,  $factor)
string header7BitEncode (string $data, [int $chunk = 76], [int $init_chunk = 0], [string $le = "\r\n"])
boolean is7BitAscii (string $data)
boolean is7BitPrintable (string $data)
boolean isHeaderSafe (string $data)
boolean isUTF8 (string $data)
string QPEncode (string $data, [int $chunk = 76], [int $init_chunk = 0], [boolean $headers = false], [string $le = "\r\n"])
Swift_Cache_OutputStream QPEncodeFile ( $file, [int $chunk = 76], [string $le = "\r\n"])
array quoteChunk (string $input)
string rawBase64Encode (The $string)
string rawQPEncode (string $string, [boolean $bin = false])
string rfc2047Encode (string $str, [string $charset = "iso-8859-1"], [string $language = "en-us"], [int $chunk = 76], [int $le = "\r\n"], string 5)
Variables
static Swift_Message_Encoder $instance = null (line 32)

A singleton of this class

  • access: protected
Methods
static method instance (line 38)

Retreive an instance of the encoder as a singleton.

New instances are never ever needed since it's monostatic.

  • access: public
static Message_Encoder instance ()
addressChunk (line 53)

Break a string apart at every occurence of <add@ress> and return an array This method does NOT remove any characters like a preg_split() would do.

Elements matching an address start with "a" followed by the numeric index

  • access: public
array addressChunk (string $input)
  • string $input: The input string to separate
base64Encode (line 95)

Return the base64 encoded version of the string

  • access: public
string base64Encode (string $data, [int $chunk = 76], int $init_chunk, [boolean $headers = false], [string $le = "\r\n"])
  • string $data: The input string to encode
  • int $chunk: The maximum length of each line of output (inc CRLF)
  • int $init_chunk: The maximum length of the first line in the output (for headers)
  • boolean $headers: Whether email addresses between < and > chars should be preserved or not
  • string $le: The line ending
base64EncodeFile (line 152)

Return the base64 encoded version of a file

  • access: public
  • throws: Swift_FileException If the file cannot be read
Swift_Cache_OutputStream base64EncodeFile ( $file, [int $chunk = 76], [string $le = "\r\n"])
  • Swift_File $file: The file input stream
  • int $chunk: Max line length
  • string $le: The line ending
encode7Bit (line 286)

Encode a string as 7bit ascii

  • access: public
string encode7Bit (string $data, [int $chunk = 76], [string $le = "\r\n"])
  • string $data: Input data to encode
  • int $chunk: Max line length
  • string $le: The line ending
encode7BitFile (line 298)

Return a 7bit string from a file

  • access: public
  • throws: Swift_FileException If the file cannot be read
Swift_Cache_OutputStream encode7BitFile ( $file, [int $chunk = 76], [string $le = "\r\n"])
  • Swift_File $file: The file stream to read from
  • int $chunk: The max line length
  • string $le: The line ending
encode7BitPrintable (line 365)

Strip out any characters which are not in the ASCII 7bit printable range

  • access: public
string encode7BitPrintable (string $data)
  • string $data: The string to clean
encode8Bit (line 314)

Return the 8bit encoded form of a string (unchanged there-abouts)

  • access: public
string encode8Bit (string $data, [int $chunk = 76], [string $le = "\r\n"])
  • string $data: Input data to encode
  • int $chunk: Maximum line length
  • string $le: The line ending
encode8BitFile (line 326)

Return a 8bit string from a file

  • access: public
  • throws: Swift_FileException If the file cannot be read
Swift_Cache_OutputStream encode8BitFile ( $file, [int $chunk = 76], [string $le = "\r\n"])
  • Swift_File $file: The file stream to read from
  • int $chunk: Max line length (including CRLF)
  • string $le: The line ending
fixLE (line 445)

Fixes line endings to be whatever is specified by the user

SMTP requires the CRLF be used, but using sendmail in -t mode uses LF This method also escapes dots on a start of line to avoid injection

  • access: protected
string fixLE (string $data,  $le)
  • string $data: The data to fix
  • $le
getHcf (line 451)
  • access: protected
void getHcf ( $value,  $factor)
  • $value
  • $factor
header7BitEncode (line 344)

Keeps lines longer than 76 characters trimmed down to size

This currently does not convert other string encodings into 7bit

  • access: public
string header7BitEncode (string $data, [int $chunk = 76], int $init_chunk, [string $le = "\r\n"])
  • string $data: The data to make safe for headers (defaults to RFC 2822 standards)
  • int $chunk: maximum length of lines returned
  • int $init_chunk: The maximum length of the first line
  • string $le: The Line ending
is7BitAscii (line 413)

If the characters fall exclusively in the 7bit ascii range, return true

  • access: public
boolean is7BitAscii (string $data)
  • string $data: Input to check
is7BitPrintable (line 395)

This function checks for 7bit *printable* characters

which excludes \r \n \t etc and so, is safe for use in mail headers Actual permitted chars [\ !"#\$%&'\(\)\*\+,-\.\/0123456789:;<=>\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]\^_`abcdefghijklmnopqrstuvwxyz{\|}~] Ranges \x00-\x1F are printer control sequences \x7F is the ascii delete character

  • access: public
boolean is7BitPrintable (string $data)
  • string $data: Data to check against
isHeaderSafe (line 404)

Check that a string does not contain any evil characters for headers.

  • access: public
boolean isHeaderSafe (string $data)
  • string $data: The string to check
isUTF8 (line 374)

Detect if a string contains multi-byte non-ascii chars that fall in the UTF-8 ranges

  • access: public
boolean isUTF8 (string $data)
  • string $data: Data to detect UTF-8 sequences in
QPEncode (line 180)

Return the quoted printable version of the input string

  • access: public
string QPEncode (string $data, [int $chunk = 76], int $init_chunk, [boolean $headers = false], [string $le = "\r\n"])
  • string $data: The input string to encode
  • int $chunk: The maximum length of each line of output (inc CRLF)
  • int $init_chunk: The maximum length of the first line in the output (for headers)
  • boolean $headers: Whether email addresses between < and > chars should be preserved or not
  • string $le: The line ending
QPEncodeFile (line 267)

Return a file as a quoted printable encoded string

  • access: public
  • throws: Swift_FileException If the file cannot be read
Swift_Cache_OutputStream QPEncodeFile ( $file, [int $chunk = 76], [string $le = "\r\n"])
  • Swift_File $file: The file to encode
  • int $chunk: Max line length
  • string $le: The line ending
quoteChunk (line 73)

Break a string apart at every occurence of <xxxyyy> and return an array This method does NOT remove any characters like a preg_split() would do.

Elements matching a quoted string start with "a" followed by the numeric index

  • access: public
array quoteChunk (string $input)
  • string $input: The input string to separate
rawBase64Encode (line 140)

Return the base64 encoded version of a string with no breaks

  • access: public
string rawBase64Encode (The $string)
  • The $string: input string to encode
rawQPEncode (line 232)

Return the QP encoded version of a string with no breaks

  • access: public
string rawQPEncode (string $string, [boolean $bin = false])
  • string $string: The input to encode
  • boolean $bin: True if the data we're encoding is binary
rfc2047Encode (line 427)

Encode a string for RFC 2047 compatability (url-encode)

  • access: public
string rfc2047Encode (string $str, [string $charset = "iso-8859-1"], [string $language = "en-us"], [int $chunk = 76], [int $le = "\r\n"], string 5)
  • string 5: The line ending
  • string $str: The input for encoding
  • string $charset: The charset used
  • string $language: The language used
  • int $chunk: The maximum line length
  • int $le: The maximum length of the first line
Class Constants
CHEAP_ADDRESS_RE = '(?#Start of dot-atom
)[-!#\$%&\'\*\+\/=\?\^_`{}\|~0-9A-Za-z]+(?:\.[-!#\$%&\'\*\+\/=\?\^_`{}\|~0-9A-Za-z]+)*(?#
End of dot-atom)(?:@(?#Start of domain)[-0-9A-Za-z]+(?:\.[-0-9A-Za-z]+)*(?#End of domain))?'
(line 25)

A regular expression which matches valid e-mail addresses (including some unlikely ones)

Documentation generated on Wed, 26 Mar 2008 20:33:07 +1100 by phpDocumentor 1.3.1