85 $this->_charset = $charset;
86 if (isset($this->_encoder)) {
87 $this->_encoder->charsetChanged($charset);
112 $this->_lang =
$lang;
132 $this->_encoder = $encoder;
153 $this->_grammar = $grammar;
185 $this->_lineLength = $lineLength;
231 $this->_name = $name;
248 $phraseStr = $string;
250 if (!preg_match(
'/^'.$this->
getGrammar()->getDefinition(
'phrase').
'$/D', $phraseStr)) {
253 if (preg_match(
'/^'.$this->
getGrammar()->getDefinition(
'text').
'*$/D', $phraseStr)) {
254 $phraseStr = $this->
getGrammar()->escapeSpecials(
255 $phraseStr, array(
'"'), $this->
getGrammar()->getSpecials()
257 $phraseStr =
'"'.$phraseStr.
'"';
266 $phraseStr = $this->
encodeWords($header, $string, $usedLength);
288 foreach ($tokens as $token) {
292 $firstChar = substr($token, 0, 1);
293 switch ($firstChar) {
296 $value .= $firstChar;
297 $token = substr($token, 1);
300 if (-1 == $usedLength) {
301 $usedLength = strlen($header->
getFieldName().
': ') + strlen($value);
305 $header->setMaxLineLength(76);
323 return preg_match(
'~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $token);
339 foreach (preg_split(
'~(?=[\t ])~', $string) as $token) {
341 $encodedToken .= $token;
343 if (strlen($encodedToken) > 0) {
344 $tokens[] = $encodedToken;
350 if (strlen($encodedToken)) {
351 $tokens[] = $encodedToken;
369 if (isset($this->_lang)) {
370 $charsetDecl .=
'*'.$this->_lang;
372 $encodingWrapperLength = strlen(
373 '=?'.$charsetDecl.
'?'.$this->_encoder->getName().
'??='
376 if ($firstLineOffset >= 75) {
378 $firstLineOffset = 0;
381 $encodedTextLines = explode(
"\r\n",
382 $this->_encoder->encodeString(
383 $token, $firstLineOffset, 75 - $encodingWrapperLength, $this->_charset
387 if (strtolower($this->_charset) !==
'iso-2022-jp') {
389 foreach ($encodedTextLines as $lineNum => $line) {
390 $encodedTextLines[$lineNum] =
'=?'.$charsetDecl.
391 '?'.$this->_encoder->getName().
396 return implode(
"\r\n ", $encodedTextLines);
408 return preg_split(
'~(\r\n)~', $token, -1, PREG_SPLIT_DELIM_CAPTURE);
418 $this->_cachedValue = $value;
452 if (is_null($string)) {
459 foreach (preg_split(
'~(?=[ \t])~', $string) as $token) {
461 foreach ($newTokens as $newToken) {
462 $tokens[] = $newToken;
480 $headerLines = array();
481 $headerLines[] = $this->_name.
': ';
482 $currentLine = &$headerLines[$lineCount++];
485 foreach ($tokens as $i => $token) {
487 if ((
"\r\n" == $token) ||
488 ($i > 0 && strlen($currentLine.$token) > $this->_lineLength)
489 && 0 < strlen($currentLine)) {
491 $currentLine = &$headerLines[$lineCount++];
495 if (
"\r\n" != $token) {
496 $currentLine .= $token;
501 return implode(
"\r\n", $headerLines).
"\r\n";