function EncodeHeaderText($s_text, $i_max_line = -1)
{
    global $sHTMLCharSet;
    //
    // RFCLINELEN is the RFC recommended maximum line length, but we don't know
    // what the front part of the line will be at this point.
    // So, we'll be conservative and reduce it.
    //
    if ($i_max_line == 0) {
        $i_max_line = RFCLINELEN - 15;
    }
    $s_charset = "";
    if (isset($sHTMLCharSet) && $sHTMLCharSet != "") {
        $s_charset = $sHTMLCharSet;
    } else {
        if (IsMailOptionSet("CharSet")) {
            $s_charset = GetMailOption("CharSet");
        }
    }
    if ($s_charset != "") {
        //
        // this is the for base64 encoding.
        // quoted printable is a better choice for human readability
        //
        //return ("=?".$s_charset."?B?".base64_encode($s_text)."?=");
        $s_prefix = "=?" . $s_charset . "?Q?";
        $s_suffix = "?=";
        //
        // pick a line length that allows a line split with the prefix or suffix added
        // to be within the RFC maximum recommended line length
        //
        return $s_prefix . QPEncode($s_text, $i_max_line - strlen($s_prefix)) . $s_suffix;
    } else {
        return $s_text;
    }
}
Beispiel #2
0
/**
 * 	\brief		Encode for cal export
 * 	\param		format		vcal or ical
 * 	\param 		string		string to encode
 * 	\return		string		string encoded
 * 	\remarks	string must be encoded in conf->file->character_set_client
 */
function format_cal($format,$string)
{
	global $conf;

	if ($conf->file->character_set_client == 'ISO-8859-1') $newstring=utf8_encode($string);
	else $newstring=$string;

	// Now newstring is always UTF8 string
	if ($format == 'vcal')
	{
		$newstring=QPEncode($newstring);
	}
	if ($format == 'ical')
	{
		// Replace new lines chars by '\n'
		$newstring=preg_replace('/'."\r\n".'/i',"\n",$newstring);
		$newstring=preg_replace('/'."\n\r".'/i',"\n",$newstring);
		$newstring=preg_replace('/'."\n".'/i','\n',$newstring);
		// Must not exceed 75 char. Cut with "\r\n"+Space
		$newstring=CalEncode($newstring);
	}

	return $newstring;
}