* Decompress compressed RTF. Logic taken from Horde.
*/
protectedfunction_decompressRTF($data,$size)
{
$in=$out=$flags=$flag_count=0;
$uncomp='';
$preload="{\\rtf1\\ansi\\mac\\deff0\\deftab720{\\fonttbl;}{\\f0\\fnil \\froman \\fswiss \\fmodern \\fscript \\fdecor MS Sans SerifSymbolArialTimes New RomanCourier{\\colortbl\\red0\\green0\\blue0\n\r\\par \\pard\\plain\\f0\\fs20\\b\\i\\u\\tab\\tx";
$length_preload=strlen($preload);
for($cnt=0;$cnt<$length_preload;$cnt++){
$uncomp.=$preload[$cnt];
++$out;
}
while($out<($size+$length_preload)){
if(($flag_count++%8)==0){
$flags=ord($data[$in++]);
}
else{
$flags=$flags>>1;
}
if(($flags&1)!=0){
$offset=ord($data[$in++]);
$length=ord($data[$in++]);
$offset=($offset<<4)|($length>>4);
$length=($length&0xF)+2;
$offset=((int)($out/4096))*4096+$offset;
if($offset>=$out){
$offset-=4096;
}
$end=$offset+$length;
while($offset<$end){
$uncomp.=$uncomp[$offset++];
++$out;
}
}
else{
$uncomp.=$data[$in++];
++$out;
}
}
returnsubstr($uncomp,$length_preload);
}
/**
* Parse RTF data and return the best plaintext representation we can.