23a24 > var $boundary; 128c129 < $this->attachments=$this->user_id=$this->headers=$this->body=$this->raw_msg=$this->msg_id=$this->reply_to_msg_id=$this->from_email=$this->from_name=$this->ip=null; --- > $this->attachments=$this->user_id=$this->headers=$this->body=$this->raw_msg=$this->msg_id=$this->reply_to_msg_id=$this->from_email=$this->from_name=$this->ip=$this->boundary=null; 157a159,165 > function check_boundary($v) > { > if (preg_match('/boundary="([^"]+)"/', $v, $matches)) { > $this->boundary=$matches[1]; > } > } > 165a174,176 > > $this->check_boundary($v); > 224a236 > 291a304 > 293a307,412 > > function skip_to_next_line(&$s) { > if($next_line = strpos($this->body, "\n", $s) ) { > $s = $next_line+1; > } > } > > function get_next_line(&$s) { > $line=''; > if($next_line = strpos($this->body, "\n", $s) ) { > $line=substr($this->body, $s, $next_line - $s); > $line = str_replace("\r", "", $line); > $s = $next_line+1; > } else { > # eof > $line=substr($this->body, $s); > $s += strlen($line); > } > return ($line); > } > > function process_content_header($line, &$content_type, &$content_transfer, &$filename) { > > $hk = substr($line, 0, ($p = strpos($line, ':'))); > // Skip non-valid header lines > if (empty($hk) || (isset($line[++$p]) && $line[$p] != ' ' && $line[$p] != "\t")) { > return; > } > > $hk = strtolower(trim($hk)); > if ($hk == 'content-transfer-encoding') { > $content_transfer = trim(substr($line, $p)); > } elseif ($hk == 'content-type') { > $content_type = trim(substr($line, $p)); > } > # Match for content-disposition and content-type case > if (preg_match('/name="([^"]+)"/', $line, $matches)) { > $filename=$matches[1]; > } > > } > > function parse_mime_attachments() { > > $s = 0; > $text_body=''; > > while (($s = strpos($this->body, $this->boundary, $s)) !== false) { > > $content_type = $content_transfer = $filename = null; > $this->skip_to_next_line($s); > > $line=$this->get_next_line($s); > # Retrieve all lines until no more continuation lines or blank > do { > $next_line=$this->get_next_line($s); > if (($next_line != '') && ($next_line[0] == "\t")) { > # Continuation line > $line .= $next_line; > } else { > # new header line, process previous completed line > $this->process_content_header($line, $content_type, $content_transfer, $filename); > $line = $next_line; > } > > } while ($next_line != ''); > > > $have_text_body=false; > # Have processed headers at this point > # if it's text/plain or text/html put into main message headers > if (isset($content_type)) { > if (strpos($content_type, 'text/plain') !== false) { > $this->headers['content-type'] = $content_type; > $this->headers['content-transfer-encoding'] = $content_transfer; > $have_text_body=true; > } elseif (strpos($content_type, 'text/html') !== false) { > if (!isset($this->headers['content-type'])) { > # Give priority to text/plain > $this->headers['content-type'] = $content_type; > $this->headers['content-transfer-encoding'] = $content_transfer; > $have_text_body=true; > } > } > } > > $eom = strpos($this->body, $this->boundary, $s); > if ($have_text_body) { > $text_body = substr($this->body, $s, $eom-$s); > $s=$eom; > } > if (isset($filename)) { > $data = substr($this->body, $s, $eom-$s); > $data = str_replace("\r", "", $data); > $this->attachments[$filename] = base64_decode($data); > $s=$eom; > } > > > > } > $this->body = $text_body; // Replace multipart mime by the text body > } > > > 295a415,419 > if (isset($this->boundary)) { > $this->parse_mime_attachments(); > return; > } > 358a483 >