Hoa central
QuotedPrintable.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Mail\Content\Encoder;
38 
39 use Hoa\Mail;
40 
50 class QuotedPrintable implements Encoder
51 {
59  public static function encode($string, $isHeaderValue = false)
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  }
117 
125  public static function decode($string, $isHeaderValue = false)
126  {
127  throw new Mail\Exception('Not implemented.', 0);
128  }
129 }
static decode($string, $isHeaderValue=false)
static encode($string, $isHeaderValue=false)