/**
* Get a token as an encoded word for safe insertion into headers.
* @param string $token to encode
* @param int $firstLineOffset, optional
* @return string
*/
protected function getTokenAsEncodedWord($token, $firstLineOffset = 0)
{
//Adjust $firstLineOffset to account for space needed for syntax
$charsetDecl = $this->_charset;
if (isset($this->_lang))
{
$charsetDecl .= '*' . $this->_lang;
}
$encodingWrapperLength = strlen(
'=?' . $charsetDecl . '?' . $this->_encoder->getName() . '??='
);
if ($firstLineOffset >= 75) //Does this logic need to be here?
{
$firstLineOffset = 0;
}
$encodedTextLines = explode("\r\n",
$this->_encoder->encodeString(
$token, $firstLineOffset, 75 - $encodingWrapperLength
)
);
foreach ($encodedTextLines as $lineNum => $line)
{
$encodedTextLines[$lineNum] = '=?' . $charsetDecl .
'?' . $this->_encoder->getName() .
'?' . $line . '?=';
}
return implode("\r\n ", $encodedTextLines);
}