Exemple #1
0
 private static function bodies2plain($bodies, $msgType)
 {
     $ret = '';
     // clear html if both html and plain exist
     if ($msgType == 'multipart/alternative') {
         foreach ($bodies as $k => $i) {
             if ($i['type'] == 'text/plain') {
                 $hasPlain = true;
             }
         }
         if ($hasPlain) {
             foreach ($bodies as $k => $i) {
                 if ($i['type'] == 'text/html') {
                     unset($bodies[$k]);
                 }
             }
         }
     }
     // condense bodies
     foreach ($bodies as $part) {
         // strip "=" at end of line
         if ($part['encoding'] == 'quoted-printable') {
             $part['body'] = quoted_printable_decode($part['body']);
         }
         // convert html to plain text
         if ($part['type'] == 'text/html') {
             // get html body element
             $txt = str::between($part['body'], '<body>', '</body>', $pos = 0, true);
             // improper html? just use the whole body part
             if (!strlen($txt)) {
                 $txt = $part['body'];
             }
             // clean up
             $txt = str::br2nl($txt);
             $txt = trim(str::condenseTags($txt));
             $txt = preg_replace('{[ \\t]+}', ' ', $txt);
             $ret .= $txt;
         } else {
             $ret .= $part['body'];
         }
     }
     return $ret;
 }