public function pub_getMailListInFolders($o) { $o['folder'] = base64_decode($o['folder']); $this->imapProxy->setAccount($o['account']); if (!$this->imapProxy->isConnected()) { return array('error' => true); } $query = array_key_exists_assign_default('query', $o, false); if ($query) { $res = $this->imapProxy->search(array('query' => $query)); } else { $o['query'] = 'in:"' . $o['folder'] . '"'; $res = $this->imapProxy->search($o); } return array('data' => $res, 'totalCount' => count($res) * 200, 'm' => count($res) * 200, 's' => 0); }
/** * * @param unknown $mid * @param unknown $p * @param unknown $partno * @param unknown $ret * @param unknown $withAttachmentsBody */ public function getMimePart($mid, $p, $partno, &$ret, $withAttachmentsBody) { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple // DECODE DATA $data = $partno ? $this->imapProxy->fetchbody($mid, $partno) : $this->imapProxy->body($mid); // simple // Any part may be encoded, even plain text messages, so check everything. if ($p->encoding == 4) { $data = quoted_printable_decode($data); } elseif ($p->encoding == 3) { $data = base64_decode($data); } // PARAMETERS // get all parameters, like charset, filenames of attachments, etc. $params = array(); if ($p->parameters) { foreach ($p->parameters as $x) { $params[strtolower($x->attribute)] = $x->value; } if (isset($p->id)) { if (preg_match('!^<(.*)>$!', $p->id, $m)) { $params['id'] = $m[1]; } else { $params['id'] = $p->id; } } } if ($p->dparameters) { foreach ($p->dparameters as $x) { $params[strtolower($x->attribute)] = $x->value; } } // ATTACHMENT // Any part with a filename is an attachment, // so an attached text file (type 0) is not mistaken as the message. if ($params['filename'] || $params['name']) { $filename = $params['filename'] ? $params['filename'] : $params['name']; if ($withAttachmentsBody) { // filename may be given as 'Filename' or 'Name' or both // filename may be encoded, so see imap_mime_header_decode() $ret['attachments'][$filename] = $data; // this is a problem if two files have same name } else { if ($p->bytes) { $size = $p->bytes; } else { $size = 0; } $partData = array('filename' => $filename, 'hfilename' => $this->imapProxy->decodeMimeStr($filename), 'size' => $size, 'partno' => $partno, 'type' => '', 'id' => array_key_exists_assign_default('id', $params, '-')); $ret['attachments'][] = $partData; } } // TEXT if ($p->type == 0 && $data) { // Messages may be split in different parts because of inline attachments, // so append parts together with blank row. if (strtolower($p->subtype) == 'plain') { $ret['plainmsg'] .= trim($data) . "\n\n"; } else { $ret['htmlmsg'] .= $data . "<br><br>"; } $ret['charset'] = $params['charset']; // assume all parts are same charset } elseif ($p->type == 2 && $data) { $ret['plainmsg'] .= $data . "\n\n"; } // SUBPART RECURSION if ($p->parts) { foreach ($p->parts as $partno0 => $p2) { $this->getMimePart($mid, $p2, $partno . '.' . ($partno0 + 1), $ret, $withAttachmentsBody); // 1.2, 1.2.1, etc. } } }
public function getMessageAttachment($o) { $folder = base64_decode($o['folder']); $message_no = $o['message_no']; $this->imapProxy->setAccount($o['account']); $this->imapProxy->open($folder); if (!$this->imapProxy->isConnected()) { return array('error' => true); } $o['filename'] = base64_decode($o['filename']); $outStruct = $this->imapProxy->getMimeFlatStruct($message_no); $outStruct = $outStruct['flat']; if ($o['partno'] == -1) { $tmpName = tempnam(sys_get_temp_dir(), 'zip') . "_folder.zip"; $archive = new PclZip($tmpName); $archDatas = array(); foreach ($outStruct as $partno => $part) { if ($filename = $this->getPartFilename($part)) { $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); } $archDatas[] = array(PCLZIP_ATT_FILE_NAME => $filename, PCLZIP_ATT_FILE_CONTENT => $data); } } $list = $archive->create($archDatas); if ($list == 0) { die("ERROR : '" . $archive->errorInfo(true) . "'"); } header('Content-type: application/zip'); $this->headerForDownload("folder.zip", filesize($tmpName)); print file_get_contents($tmpName); unlink($tmpName); die; } else { $part = $outStruct[$o['partno']]; $filename = $this->getPartFilename($part); $data = $this->imapProxy->fetchbody($message_no, $o['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); } if (false) { header('content-type: text/html; charset=utf-8'); db($filename); db($part); db($outStruct); db(urlencode($this->imapProxy->decodeMimeStr($filename))); db($data); die; } if (array_key_exists_assign_default('onlyView', $o, false)) { $this->headerForView($filename, $part['bytes']); } else { $this->headerForDownload($filename, $part['bytes']); } print $data; die; } }