case 'message': $account =& Account::LoadFromDb($accountId); if (!$account) { printErrorAndExit('', $xmlRes, 2); } $message =& CreateMessage($account, $xmlObj); $processor =& new MailProcessor($account); $folders =& $processor->GetFolders(); $folder =& $folders->GetFolderByType(FOLDERTYPE_SentItems); $message->OriginalMailMessage = $message->ToMailString(true); $message->Flags |= MESSAGEFLAGS_Seen; $from =& $message->GetFrom(); $result = true; $needToDelete = $message->IdMsg != -1; $idtoDelete = $message->IdMsg; if (CSmtp::SendMail($account, $message, null, null)) { $messageNode =& $xmlObj->XmlRoot->GetChildNodeByTagName('message'); $attachmentsNode =& $messageNode->GetChildNodeByTagName('attachments'); if ($attachmentsNode != null) { $filesArray = array(); foreach (array_keys($attachmentsNode->Children) as $key) { $attachNode =& $attachmentsNode->Children[$key]; $tempName = $attachNode->GetChildValueByTagName('temp_name'); if ($tempName) { $filesArray[] = $tempName; } } if (count($filesArray) > 0) { $fs =& new FileSystem(INI_DIR . '/temp', $account->Email, $account->Id); $fs->DeleteTempFilesByArray($filesArray, $_SESSION['attachtempdir']); unset($fs);
function DoSendMessage() { $_dbStorage = $_settings = $_xmlObj = $_xmlRes = $_accountId = null; $this->_initFuncArgs($_dbStorage, $_settings, $_xmlObj, $_xmlRes, $_accountId); $_account =& CXmlProcessing::AccountCheckAndLoad($_xmlRes, $_accountId, false, false); $_message =& CXmlProcessing::CreateMessage($_account, $_xmlObj, $_xmlRes); /* custom class */ wm_Custom::StaticUseMethod('ChangeMessageBeforeSend', array(&$_message)); $_processor = new MailProcessor($_account); $_folders =& $_processor->GetFolders(); $_folder =& $_folders->GetFolderByType(FOLDERTYPE_SentItems); $_message->OriginalMailMessage = $_message->ToMailString(true); $_message->Flags |= MESSAGEFLAGS_Seen; $_from =& $_message->GetFrom(); $_result = true; $_needToDelete = $_message->IdMsg != -1; $_idtoDelete = $_message->IdMsg; if (CSmtp::SendMail($_settings, $_account, $_message, null, null)) { $_messageNode =& $_xmlObj->XmlRoot->GetChildNodeByTagName('message'); $_attachmentsNode =& $_messageNode->GetChildNodeByTagName('attachments'); $bSaveInSent = isset($_messageNode->Attributes['save_mail']) && 1 === (int) $_messageNode->Attributes['save_mail']; if ($_processor->DbStorage->Connect()) { $_draftsFolder = null; if ($_needToDelete) { $_draftsFolder =& $_folders->GetFolderByType(FOLDERTYPE_Drafts); if ($_draftsFolder) { if (!$_processor->SaveMessage($_message, $_folder, $_draftsFolder, !$bSaveInSent)) { $_needToDelete = false; } } } else { if ($bSaveInSent) { if (!$_processor->SaveMessage($_message, $_folder)) { $_needToDelete = false; } } } /* suggestion */ $_mNode =& $_xmlObj->XmlRoot->GetChildNodeByTagName('message'); $_hNode =& $_mNode->GetChildNodeByTagName('headers'); $_gNode =& $_hNode->GetChildNodeByTagName('groups'); $_toNode =& $_hNode->GetChildNodeByTagName('to'); $_ccNode =& $_hNode->GetChildNodeByTagName('cc'); $_bccNode =& $_hNode->GetChildNodeByTagName('bcc'); $_emailsString = ''; $_gids = array(); if ($_gNode != null && $_gNode->Value != null) { if (count($_gNode->Children) > 0) { $_gKeys = array_keys($_gNode->Children); foreach ($_gKeys as $_key) { $_oneGNode =& $_gNode->Children[$_key]; $_gids[] = isset($_oneGNode->Attributes['id']) ? (int) $_oneGNode->Attributes['id'] : -1; unset($_oneGNode); } } } if ($_toNode != null && $_toNode->Value != null) { $_emailsString .= ConvertUtils::WMBackHtmlSpecialChars($_toNode->Value) . ', '; } if ($_ccNode != null && $_ccNode->Value != null) { $_emailsString .= ConvertUtils::WMBackHtmlSpecialChars($_ccNode->Value) . ', '; } if ($_bccNode != null && $_bccNode->Value != null) { $_emailsString .= ConvertUtils::WMBackHtmlSpecialChars($_bccNode->Value); } $_emailsString = trim(trim($_emailsString), ','); $_emailsCollection = new EmailAddressCollection($_emailsString); $_arrEmails = array(); for ($_z = 0, $_lc = $_emailsCollection->Count(); $_z < $_lc; $_z++) { $_emailObj =& $_emailsCollection->Get($_z); if ($_emailObj && trim($_emailObj->Email)) { $_arrEmails[$_emailObj->Email] = trim($_emailObj->DisplayName); } } /* reply */ if (USE_DB) { CXmlProcessing::ReplySetFlag($_mNode, $_processor); } /* update group frequency */ if (USE_DB) { $_processor->DbStorage->UpdateGroupsFrequency($_gids); $_processor->DbStorage->UpdateSuggestTable($_account, $_arrEmails); } /* end suggestion */ if ($_needToDelete && $_draftsFolder) { $_messageIdSet = array($_idtoDelete); if ($_account->MailProtocol == MAILPROTOCOL_IMAP4) { if ($_processor->PurgeFolder($_draftsFolder) && USE_DB) { $_processor->DbStorage->DeleteMessages($_messageIdSet, false, $_draftsFolder); } } else { if (USE_DB) { $_processor->DbStorage->DeleteMessages($_messageIdSet, false, $_draftsFolder); } } } if (USE_DB) { $_processor->DbStorage->UpdateMailboxSize(); } } $_result = true; } else { $_result = false; } if ($_result) { $_updateNode = new XmlDomNode('update'); $_updateNode->AppendAttribute('value', 'send_message'); $_xmlRes->XmlRoot->AppendChild($_updateNode); } else { //CXmlProcessing::PrintErrorAndExit(getGlobalError(), $_xmlRes); CXmlProcessing::PrintErrorAndExit(PROC_CANT_SEND_MSG, $_xmlRes); } }
/** * @param WebMailMessage $message * @param string $from optional * @param string $to optional * @return bool */ function SendMail(&$message, $from = null, $to = null) { return CSmtp::SendMail($this->_account, $message, $from, $to); }
/** * @param Account $account * @param array $to * @param string $subject * @param string $bodyText * @param bool $isBodyHtml = false * @param array $attachmentsFileName = array() * @return bool */ protected function _SendMessage($account, $to, $subject, $bodyText, $isBodyHtml = false, $attachmentsFileName = array()) { require_once WM_ROOTPATH . 'common/class_settings.php'; require_once WM_ROOTPATH . 'common/class_account.php'; require_once WM_ROOTPATH . 'common/class_webmailmessages.php'; require_once WM_ROOTPATH . 'common/class_smtp.php'; $settings =& Settings::CreateInstance(); if (!$settings || !$settings->isLoad) { throw new WebMailModelException('settings error'); } if (!$settings->IncludeLang()) { throw new WebMailModelException('lang error'); } $message = new WebMailMessage(); $GLOBALS[MailDefaultCharset] = $account->GetUserCharset(); $GLOBALS[MailInputCharset] = $account->GetUserCharset(); $GLOBALS[MailOutputCharset] = $account->GetDefaultOutCharset(); $message->Headers->SetHeaderByName(MIMEConst_MimeVersion, '1.0'); $message->Headers->SetHeaderByName(MIMEConst_XMailer, XMAILERHEADERVALUE); $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; if (null !== $ip) { $message->Headers->SetHeaderByName(MIMEConst_XOriginatingIp, $ip); } $message->IdMsg = -1; $message->Uid = -1; $_serverAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['SERVER_NAME'] : 'cantgetservername'; $message->Headers->SetHeaderByName(MIMEConst_MessageID, '<' . substr(session_id(), 0, 7) . '.' . md5(time()) . '@' . $_serverAddr . '>'); $message->SetFromAsString($account->GetFriendlyEmail()); $message->SetToAsString(implode(', ', $to)); $message->SetSubject($subject); $message->SetDate(new CDateTime(time())); if ($isBodyHtml) { $message->TextBodies->HtmlTextBodyPart = ConvertUtils::AddHtmlTagToHtmlBody(str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($bodyText)))); } else { $message->TextBodies->PlainTextBodyPart = str_replace("\n", CRLF, str_replace("\r", '', ConvertUtils::WMBackHtmlNewCode($bodyText))); } if (count($attachmentsFileName) > 0) { foreach ($attachmentsFileName as $attachmentFileName) { $message->Attachments->AddFromFile($attachmentFileName, basename($attachmentFileName), ConvertUtils::GetContentTypeFromFileName(basename($attachmentFileName))); } } $message->OriginalMailMessage = $message->ToMailString(true); $message->Flags |= MESSAGEFLAGS_Seen; return CSmtp::SendMail($settings, $account, $message, $account->GetFriendlyEmail(), implode(', ', $to)); }