Hoa central
Static Public Member Functions | List of all members
Hoa\Mail\Content\Encoder\QuotedPrintable Class Reference
Inheritance diagram for Hoa\Mail\Content\Encoder\QuotedPrintable:

Static Public Member Functions

static encode ($string, $isHeaderValue=false)
 
static decode ($string, $isHeaderValue=false)
 

Detailed Description

Class .

Encode and decode a string as described in the RFC2045 Section 6.7 and RFC2047, Sections 4 and 5.

Definition at line 50 of file QuotedPrintable.php.

Member Function Documentation

static Hoa\Mail\Content\Encoder\QuotedPrintable::decode (   $string,
  $isHeaderValue = false 
)
static

Decode from quoted-printable format.

Parameters
string$stringString to decode.
bool$isHeaderValueWhether the string is a header value.
Returns
string

Implements Hoa\Mail\Content\Encoder\Encoder.

Definition at line 125 of file QuotedPrintable.php.

126  {
127  throw new Mail\Exception('Not implemented.', 0);
128  }
static Hoa\Mail\Content\Encoder\QuotedPrintable::encode (   $string,
  $isHeaderValue = false 
)
static

Encode into quoted-printable format.

Parameters
string$stringString to encode.
bool$isHeaderValueWhether the string is a header value.
Returns
string

Implements Hoa\Mail\Content\Encoder\Encoder.

Definition at line 59 of file QuotedPrintable.php.

60  {
61  $pre = null;
62  $post = null;
63 
64  if (true === $isHeaderValue) {
65  $pre = '=?utf-8?Q?';
66  $post = '?=';
67  }
68 
69  // RFC2045, Section 6.7, rules 1 and 2.
70  $string = preg_replace_callback(
71  // 0x00 to 0xff minus:
72  // (from rule 1)
73  // * 0x0a,
74  // * 0x0d,
75  // (from rule 2)
76  // * 0x21 to 0x3c,
77  // * 0x3e to 0x7e,
78  // (from rule 3)
79  // * 0x09,
80  // * 0x20.
81  '#[\x00-\x08\x0b\x0c\x0e-\x1f\x3d-\x3d\x7f-\xff]#',
82  function ($matches) {
83  $substring = $matches[0];
84  $out = null;
85 
86  for ($i = 0, $max = strlen($substring); $i < $max; ++$i) {
87  $out .= vsprintf('=%02X', ord($substring[$i]));
88  }
89 
90  return $out;
91  },
92  $string
93  );
94 
95  // RFC2045, Section 6.7, rule 3.
96  $string = preg_replace_callback(
97  '#([\x09\x20])' . CRLF . '#',
98  function ($matches) {
99  return vsprintf('=%02X', ord($matches[1])) . CRLF;
100  },
101  $string
102  );
103 
104  // RFC2045, Section 6.7, rule 4.
105  // CRLF is not encoded.
106 
107  // RFC2045, Section 6.7, rule 5.
108  $string = wordwrap(
109  $string,
110  75,
111  ' =' . CRLF,
112  false
113  );
114 
115  return $pre . $string . $post;
116  }

Here is the caller graph for this function:


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