.

ConverterMimeHeader Class Reference
[Lib]

Converts text into mime encoded text. More...

Inheritance diagram for ConverterMimeHeader:
IConverter

List of all members.

Public Member Functions

  decode ($value, $params=false)
  encode ($value, $params=false)
  ENcode.

Detailed Description

Converts text into mime encoded text.

Attention:
supports encoding only!
Author:
Gerd Riesselmann

Definition at line 10 of file mimeheader.converter.php.


Member Function Documentation

ConverterMimeHeader::decode ( value,
params = false  
)

Implements IConverter.

Definition at line 57 of file mimeheader.converter.php.

00057                                                         {
00058                 return $value;          
00059         }       
ConverterMimeHeader::encode ( value,
params = false  
)

ENcode.

Takes optional charset as parameter

Implements IConverter.

Definition at line 14 of file mimeheader.converter.php.

00014                                                         {
00015                 if (!$params) {
00016                         $params = GyroLocale::get_charset();
00017                 }
00018                 
00019                 $ret = '';
00020                 $requires_escaping = false;
00021                 $l = strlen($value);
00022                 // First check if there are characters that must be converted
00023                 for ($i = 0; $i < $l; $i++) {
00024                         $c = ord(substr($value, $i, 1));
00025                         if ($c < 0x20 || $c > 0x7E) {
00026                                 $requires_escaping = true;
00027                                 break;
00028                         }
00029                 }
00030                 if ($requires_escaping) {
00031                         // Convert everything other then 0-9 and A-Z and a-z
00032                         for ($i = 0; $i < $l; $i++) {
00033                                 $c = ord(substr($value, $i, 1));
00034                                 if ($c == 0x20) {
00035                                         $c = '_'; // Space to _
00036                                 }
00037                                 elseif ( 
00038                                         ($c >= 0x30 && $c <= 0x39) || 
00039                                         ($c >= 0x41 && $c <= 0x5A) ||
00040                                         ($c >= 0x61 && $c <= 0x7A)
00041                                 ) {
00042                                         $c = chr($c); // 0-9, a-z and A-Z stay the same
00043                                 }
00044                                 else {
00045                                         $c = '=' . strtoupper(dechex($c)); // Encode the rest
00046                                 }
00047                                 $ret .= $c;
00048                         }
00049                         $ret = '=?' . $params . '?Q?' . $ret . '?=';
00050                 }
00051                 else {
00052                         $ret = $value;
00053                 }
00054                 return $ret;                    
00055         }

The documentation for this class was generated from the following file: