public function getMessageContent($message_no) { //header('content-type: text/html; charset=utf-8'); $rtn = array(); $head = $this->getHeader($message_no, true); $this->parseRecipient($head, 'From'); $this->parseRecipient($head, 'To'); $this->parseRecipient($head, 'Cc'); if (array_key_exists('Subject', $head)) { $head['Subject'][0] = $this->decodeMimeStr($head['Subject'][0]); } $outStruct = $this->getMimeFlatStruct($message_no); $attachments = array(); $type = 'unknown'; $charset = 'unknown'; $body_id = $outStruct['object']->findBody('html'); if (is_null($body_id)) { $body_id = $outStruct['object']->findBody(); } $data = $this->fetchbody($message_no, $body_id); $type = $outStruct['flat'][$body_id]['subtype']; $charset = $outStruct['flat'][$body_id]['charset']; foreach ($outStruct['flat'] as $partno => $part) { if ($part['type'] != 'text') { $filename = $part['name']; if ($filename) { if ($part['bytes']) { $size = $part['bytes']; } else { $size = 0; } $id = '-'; if (array_key_exists('id', $part)) { if (preg_match('!^<(.*)>$!', $part['id'], $m)) { $id = $m[1]; } else { $id = $part['id']; } } $attachments[] = array('filename' => $filename, 'hfilename' => $this->decodeMimeStr($filename), 'size' => $size, 'partno' => $partno, 'type' => $part['subtype'], 'id' => $id); } } } foreach ($attachments as &$f) { if ($f['filename']) { $f['type'] = strtolower(pathinfo($f['filename'], PATHINFO_EXTENSION)); } } $data = mimeDecoder::decode($type, $data, $charset, $rtn, $attachments, $head, $outStruct['flat']); $rtn['header'] = $head; $rtn['rawheader'] = $head['--rawheader']; $rtn['type'] = $type; $rtn['body'] = $data; $rtn['attachments'] = $attachments; return $rtn; }
public function getMessageContent($o) { header('content-type: text/html; charset=utf-8'); $folder = base64_decode($o['folder']); //$message_id = $o['message_id']; $message_no = $o['message_no']; $this->imapProxy->setAccount($o['account']); $this->imapProxy->open($folder); if (!$this->imapProxy->isConnected()) { return $res; } //$message_no = $this->imapProxy->msgno($message_no); //$struct = $this->getMimeMsg($mbox, $message_no,false); $head = $this->imapProxy->getHeader($message_no, true); $this->imapProxy->parseRecipient($head, 'From'); $this->imapProxy->parseRecipient($head, 'To'); $this->imapProxy->parseRecipient($head, 'Cc'); if (array_key_exists('Subject', $head)) { $head['Subject'][0] = $this->decodeMimeStr($head['Subject'][0]); } $outStruct = $this->getMimeFlatStruct($message_no); $attachments = array(); $bodyPartNo = false; $type = 'unknown'; $charset = 'unknown'; //db($outStruct); foreach ($outStruct as $partno => $part) { $part['subtype'] = strtoupper($part['subtype']); if ($part['type'] == 0) { $data = $this->imapProxy->fetchbody($message_no, $partno); if ($part['encoding'] == 4) { $data = quoted_printable_decode($data); } elseif ($part['encoding'] == 3) { $data = base64_decode($data); } elseif ($part['encoding'] == 2) { $data = imap_binary($data); } elseif ($part['encoding'] == 1) { $data = imap_8bit($data); } //db('--'); //db($part); //db($part['subtype']); //db($data); if ($data) { if ($part['subtype'] == 'PLAIN' && !$bodyPartNo) { $type = 'plain'; $bodyPartNo = $partno; $charset = array_key_exists_assign_default('charset', $part, 'unknown'); } elseif ($part['subtype'] == 'HTML') { $type = 'html'; $bodyPartNo = $partno; $charset = array_key_exists_assign_default('charset', $part, 'unknown'); } elseif ($part['subtype'] == 'CALENDAR') { $type = 'calendar'; $bodyPartNo = $partno; $charset = array_key_exists_assign_default('charset', $part, 'unknown'); } } } else { $filename = $part['params']['filename'] ? $part['params']['filename'] : $part['params']['name']; if ($filename) { if ($part['bytes']) { $size = $part['bytes']; } else { $size = 0; } $id = '-'; if (array_key_exists('id', $part)) { if (preg_match('!^<(.*)>$!', $part['id'], $m)) { $id = $m[1]; } else { $id = $part['id']; } } $attachments[] = array('filename' => $filename, 'hfilename' => $this->decodeMimeStr($filename), 'size' => $size, 'partno' => $partno, 'type' => $part['subtype'], 'id' => $id); } } } foreach ($attachments as &$f) { $f['attachUrlLink'] = $this->getAttachementURLLink($o, $f['partno']); if ($f['filename']) { $f['type'] = strtolower(pathinfo($f['filename'], PATHINFO_EXTENSION)); } } if (count($attachments) >= 2) { $attachments[] = array('filename' => 'all', 'hfilename' => 'all', 'type' => 'zip', 'size' => 1, 'partno' => -1, 'attachUrlLink' => $this->getAttachementURLLink($o, -1)); } $rtn = array(); $body = mimeDecoder::decode($type, $data, $charset, $rtn, $attachments, $head, $outStruct); //print $body; $rtn['header'] = $head; $rtn['rawheader'] = $head['--rawheader']; $rtn['type'] = $type; $rtn['body'] = $body; $rtn['attachments'] = $attachments; return $rtn; }