public static function decode($body, $charset, &$o, &$attachments, $options = array()) { if ($charset == 'unknown') { $body = utf8_encode($body); //$charset='ISO-8859-1'; } else { //if ( (strtoupper($charset)!='UTF-8')){ $body = iconv(strtoupper($charset), 'UTF-8', $body); // //TRANSLIT } $o['hasInlineComponents'] = false; foreach ($attachments as &$f) { if (array_key_exists('id', $f) && $f['id'] != '-') { $body = preg_replace('!src=(?:"|\')cid:' . preg_quote($f['id'], '!') . '(?:"|\')!', 'src="' . $f['attachUrlLink'] . '"', $body); $o['hasInlineComponents'] = true; } } if (!akead('no_safe_image', $options, false)) { if (preg_match('!src=(?:"|\')([^\'"]*)(?:"|\')!', $body)) { $body = preg_replace('!src=(?:"|\')([^\'"]*)(?:"|\')!', 'src="" data-imgsafesrc="\\1"', $body); $o['hasInlineComponents'] = true; } } return $body; }
/** * * @param array $o * @throws InvalidArgumentException * @return multitype:NULL string |multitype:NULL |number * */ public function sendBasic(smMailMessage $smMailMessage, array $options) { $this->smMailMessage = $smMailMessage; //smMailMessage //$oPHPMailMessage->WordWrap = 50; $oPHPMailMessage = new PHPMailer(true); $oPHPMailMessage->SingleTo = akead('MailerSingleTo', $options, false); $oPHPMailMessage->CharSet = $this->charset; $oPHPMailMessage->CharSet_alternative = $this->charset_alternative; $this->setSMTPData($oPHPMailMessage, $options['account']); $oPHPMailMessage->ClearAllRecipients(); $this->feedAddress($oPHPMailMessage, 'to', $this->smMailMessage->to); $this->feedAddress($oPHPMailMessage, 'cc', $this->smMailMessage->cc); $this->feedAddress($oPHPMailMessage, 'bcc', $this->smMailMessage->bcc); $this->feedAddress($oPHPMailMessage, 'replyTo', $this->smMailMessage->replyTo); $oPHPMailMessage->From = $this->smMailMessage->from; $oPHPMailMessage->FromName = $this->smMailMessage->fromName; $oPHPMailMessage->Sender = $this->smMailMessage->sender; $oPHPMailMessage->Subject = $this->smMailMessage->subject; $this->setCustomHeader($oPHPMailMessage, $this->smMailMessage); if (count($this->smMailMessage->customheaders) > 0) { foreach ($this->smMailMessage->customheaders as $kc => $vc) { $oPHPMailMessage->AddCustomHeader($kc . ':' . $vc); } } $embededAttachments = array(); $oPHPMailMessage->ClearAttachments(); if (array_key_exists('attachments', $smMailMessage)) { foreach ($o['attachments'] as $k => $v) { $oPHPMailMessage->AddAttachment($v, basename($v)); } } $oPHPMailMessage->IsHTML(true); if (isset($this->smMailMessage->newTextBody)) { $oPHPMailMessage->Body = $oPHPMailMessage->AltBody = nl2br(htmlentities(utf8_decode($this->smMailMessage->newTextBody))); } else { $oPHPMailMessage->Body = $this->smMailMessage->HTMLBody; if ($oPHPMailMessage->Body == $oPHPMailMessage->AltBody or trim($oPHPMailMessage->AltBody == '')) { $oPHPMailMessage->AltBody = $this->smMailMessage->HtmlToTextBody(); } else { $oPHPMailMessage->AltBody = strip_tags($oPHPMailMessage->AltBody); } } if (isset($this->smMailMessage->plaintext)) { $oPHPMailMessage->IsHTML(false); $oPHPMailMessage->AltBody = ''; } else { $oPHPMailMessage->IsHTML(true); } $success = $oPHPMailMessage->send(); return array('success' => !!$success, 'mailStream' => !!$success ? preg_replace('~(*BSR_ANYCRLF)\\R~', "\r\n", $oPHPMailMessage->getSentMIMEMessage()) : null, 'error' => $oPHPMailMessage->ErrorInfo); }
protected function setSMTPData($mail, $account) { $this->transport = Swift_SmtpTransport::newInstance()->setHost($account['host'])->setPort($account['port']); $this->mailer = Swift_Mailer::newInstance($this->transport); $this->logger = new Swift_Plugins_Loggers_ArrayLogger(); $this->mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($this->logger)); if (akead('auth', $account, false)) { $this->transport->setUsername($account['user'])->setPassword($account['pass']); } if ($secure = akead('secure', $account, '')) { $this->transport->setEncryption($secure); } }
public function pub_sendMail($o) { header('Content-type:text/html'); $this->setAccount($o['account']); $this->imapProxy->open(); if (!$this->imapProxy->isConnected()) { return array(); } if (akead('is_draft', $o, false)) { return $this->imapProxy->saveDraft($o); } else { return $this->imapProxy->sendEmail($o); } }
public function searchContact($o) { $default = 'in:contacts'; $params = array(ZimbraSoapClient::SoapVarArray(array('offset' => akead('start', $o, 0), 'limit' => akead('limit', $o, 25), 'sortBy' => akead('sort', $o, 'name') . ucfirst(strtolower(akead('dir', $o, 'asc'))), 'query' => $o['query'] == '' ? $default : $o['query'], 'total' => 1, 'types' => 'contact'))); $res = $this->imapStream->call('zimbraMail', 'SearchRequest', $params, true); $arrResult = array_map(function ($contact) { ZimbraSoapClient::_mapAttr($contact['a'], '@n', '%'); return array('name' => $contact['a']['nom'], 'email' => $contact['a']['email']); }, akead('cn', $res['Envelope']['Body']['SearchResponse'], array())); return array('data' => $arrResult, 'totalCount' => $res['Envelope']['Body']['SearchResponse']['@more'] == 1 ? akead('start', $o, 0) + count($arrResult) + 1 : count($arrResult)); }
public function fetch_overviewWithCache($aID, $o) { $aMsgs = $this->fetch_overview(implode(',', $aID)); $aRet = array(); $aMID = array(); if ($aMsgs) { foreach ($aMsgs as $msg) { $oTmp = (object) array(); if ($msg['MESSAGE_ID']) { $oTmp->message_id = $msg['MESSAGE_ID']; $oTmp->subject = $msg['SUBJECT']; $oTmp->from = sprintf('"%s" <%s>', $msg['FROM'][0]['PERSONAL_NAME'], $msg['FROM'][0]['EMAIL']); $oTmp->to = sprintf('"%s" <%s>', $msg['TO'][0]['PERSONAL_NAME'], $msg['TO'][0]['EMAIL']); $oTmp->date = $msg['DATE']; $oTmp->size = $msg['SIZE']; $oTmp->uid = $msg['UID']; $oTmp->msgno = $msg['MSG_NUM']; $oTmp->recent = akead('recent', $msg['FLAGS'], false) ? 1 : 0; $oTmp->flagged = akead('flagged', $msg['FLAGS'], false) ? 1 : 0; $oTmp->answered = akead('answered', $msg['FLAGS'], false) ? 1 : 0; $oTmp->deleted = akead('deleted', $msg['FLAGS'], false) ? 1 : 0; $oTmp->seen = akead('\\seen', $msg['FLAGS'], false) ? 1 : 0; $oTmp->draft = akead('draft', $msg['FLAGS'], false) ? 1 : 0; $oTmp->udate = strtotime($msg['INTERNALDATE']); $msg = $oTmp; $msg->folder = $folder; $msg->msgid = $msg->uid; $msg->date = date('Y-m-d H:i:s', strtotime($msg->date)); $msg->account = $o['account']; $msg->folder = $o['folder']; $aMID[] = $msg->msgid; $aRet[] = $msg; } } $aMMGCache = $this->getMMGCache($aMID); foreach ($aRet as &$msg) { $this->getMsgWithCacheSupport($aMMGCache, $msg); } } return $aRet; }
public function addAddress($type, $email, $name = null) { if (is_object($email)) { $email = (array) $email; } elseif (is_string($email)) { if (strpos($email, ';') !== false) { $email = str_replace(';', ',', $email); } if (strpos($email, ',') !== false) { $email = explode(';', $email); } } if (is_array($email)) { if (array_key_exists('email', $email)) { $this->addAddress($type, $email['email'], akead('name', $email, null)); } else { foreach ($email as $k => $v) { if (is_object($v)) { $v = (array) $v; } $this->addAddress($type, $v['email'], akead('name', $v, null)); } } return $this; } else { $aAddress = array('email' => $email); if (!is_null($name)) { $aAddress['name'] = $name; } } $var = '_' . strtolower($type); array_unshift($this->{$var}, $aAddress); return $this; }
public function pub_getMessageAttachment($o) { $this->setAccount($o['account']); $folder = base64_decode($o['folder']); $message_no = $o['message_no']; $this->imapProxy->open($folder); if (!$this->imapProxy->isConnected()) { return array('error' => true); } if (preg_match('!^-1,!', $o['partno'])) { $outStruct = $this->imapProxy->getMimeFlatStruct($message_no); $outStruct = $outStruct['flat']; $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); $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']]; if (array_key_exists('filename', $o)) { $filename = $o['filename']; } else { $outStruct = $this->imapProxy->getMimeFlatStruct($message_no); $outStruct = $outStruct['flat']; $filename = $this->getPartFilename($part); } $data = $this->imapProxy->fetchbody($message_no, $o['partno']); 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; } $o['onlyView'] = 1; if (akead('onlyView', $o, false)) { $this->headerForView($filename, mb_strlen($data)); } else { $this->headerForDownload($filename, mb_strlen($data)); } print $data; die; } }
public static function makeMailEditorStruct($o) { $p = array(); $p['is_real'] = $o['is_real'] !== 'false'; $p['is_draft'] = !$p['is_real']; $p['subject'] = $o['subject']; $p['message_id'] = $o['message_id']; $p['ref'] = akead('ref', $o, null); $p['priority'] = akead('priority', $o, 'medium'); $p['from'] = akead('from', $o, $GLOBALS['conf']['imapMailBox']['accounts'][$o['account']]['email']); $p['sender'] = akead('sender', $o, $GLOBALS['conf']['imapMailBox']['accounts'][$o['account']]['email']); $p['replyTo'] = akead('replyTo', $o, $GLOBALS['conf']['imapMailBox']['accounts'][$o['account']]['email']); $p['fromName'] = akead('fromName', $o, $GLOBALS['conf']['imapMailBox']['accounts'][$o['account']]['name']); $p['HTMLBody'] = $o['body']; $p['PLAINBody'] = strip_tags(str_replace(array('<br>', '</br>'), array("\n", "\n"), $o['body'])); $p['to'] = json_decode(akead('to', $o, array()), true); $p['cc'] = json_decode(akead('cc', $o, array()), true); $p['bcc'] = json_decode(akead('bcc', $o, array()), true); //$p['attachmentBase' ] = $this->tmpAttachmentsPath; $p['attachments'] = json_decode(stripslashes(akead('attachments', $o, array())), true); return $p; }