Example #1
0
 /**
  * Extract uuencoded attachment from a text/plain body. Some mail clients
  * embed attachments in the text body. This function will take them out and
  * retrn them in an array.
  *
  * @param <type> $body
  * @return <type>
  *
  */
 public function extract_uuencoded_attachments(&$body)
 {
     $body = str_replace("\r", '', $body);
     $regex = "/(begin ([0-7]{3}) (.+))\n(.+)\nend/Us";
     preg_match_all($regex, $body, $matches);
     $attachments = array();
     for ($i = 0; $i < count($matches[3]); $i++) {
         $boundary = $matches[1][$i];
         $fileperm = $matches[2][$i];
         $filename = $matches[3][$i];
         $size = strlen($matches[4][$i]);
         $mime = File::get_mime($matches[3][$i]);
         $ct = explode('/', $mime);
         $attachments[] = array('boundary' => $matches[1][$i], 'permissions' => $matches[2][$i], 'name' => $matches[3][$i], 'data' => $matches[4][$i], 'disposition' => 'ATTACHMENT', 'encoding' => '', 'type' => $ct[0], 'subtype' => $ct[1], 'size' => $size, 'human_size' => Number::format_size($size));
     }
     //remove it from the body.
     $body = preg_replace($regex, "", $body);
     //\GO::debug($body);
     return $attachments;
 }