public static function TrySendEmail($ID, &$arFields, &$arErrors) { global $APPLICATION; if (!CModule::IncludeModule('subscribe')) { $arErrors[] = array('CODE' => self::ERR_CANT_LOAD_SUBSCRIBE); return false; } $ID = intval($ID); if ($ID <= 0 && isset($arFields['ID'])) { $ID = intval($arFields['ID']); } if ($ID <= 0 || !is_array($arFields)) { $arErrors[] = array('CODE' => self::ERR_INVALID_DATA); return false; } $typeID = isset($arFields['TYPE_ID']) ? intval($arFields['TYPE_ID']) : CCrmActivityType::Undefined; if ($typeID !== CCrmActivityType::Email) { $arErrors[] = array('CODE' => self::ERR_INVALID_DATA); return false; } $urn = CCrmActivity::PrepareUrn($arFields); if (!($urn !== '' && CCrmActivity::Update($ID, array('URN' => $urn), false, false))) { $arErrors[] = array('CODE' => self::ERR_CANT_UPDATE_ACTIVITY); return false; } $settings = isset($arFields['SETTINGS']) && is_array($arFields['SETTINGS']) ? $arFields['SETTINGS'] : array(); // Creating Email --> $crmEmail = CCrmMailHelper::ExtractEmail(COption::GetOptionString('crm', 'mail', '')); $from = isset($settings['MESSAGE_FROM']) ? trim(strval($settings['MESSAGE_FROM'])) : ''; if ($from === '') { if ($crmEmail !== '') { $from = $crmEmail; } else { $arErrors[] = array('CODE' => self::ERR_CANT_FIND_EMAIL_FROM); } } elseif (!check_email($from)) { $arErrors[] = array('CODE' => self::ERR_INVALID_EMAIL, 'DATA' => array('EMAIL' => $from)); } //Save user email in settings --> if ($from !== CUserOptions::GetOption('crm', 'activity_email_addresser', '')) { CUserOptions::SetOption('crm', 'activity_email_addresser', $from); } //<-- Save user email in settings $to = array(); $commData = isset($arFields['COMMUNICATIONS']) ? $arFields['COMMUNICATIONS'] : array(); foreach ($commData as &$commDatum) { $commType = isset($commDatum['TYPE']) ? strtoupper(strval($commDatum['TYPE'])) : ''; $commValue = isset($commDatum['VALUE']) ? strval($commDatum['VALUE']) : ''; if ($commType !== 'EMAIL' || $commValue === '') { continue; } if (!check_email($commValue)) { $arErrors[] = array('CODE' => self::ERR_INVALID_EMAIL, 'DATA' => array('EMAIL' => $commValue)); continue; } $to[] = strtolower(trim($commValue)); } unset($commDatum); if (count($to) == 0) { $arErrors[] = array('CODE' => self::ERR_CANT_FIND_EMAIL_TO); } if (!empty($arErrors)) { return false; } // Try to resolve posting charset --> $postingCharset = ''; $siteCharset = defined('LANG_CHARSET') ? LANG_CHARSET : (defined('SITE_CHARSET') ? SITE_CHARSET : 'windows-1251'); $arSupportedCharset = explode(',', COption::GetOptionString('subscribe', 'posting_charset')); if (count($arSupportedCharset) === 0) { $postingCharset = $siteCharset; } else { foreach ($arSupportedCharset as $curCharset) { if (strcasecmp($curCharset, $siteCharset) === 0) { $postingCharset = $curCharset; break; } } if ($postingCharset === '') { $postingCharset = $arSupportedCharset[0]; } } //<-- Try to resolve posting charset $subject = isset($arFields['SUBJECT']) ? $arFields['SUBJECT'] : ''; $description = isset($arFields['DESCRIPTION']) ? $arFields['DESCRIPTION'] : ''; $descriptionType = isset($arFields['DESCRIPTION_TYPE']) ? intval($arFields['DESCRIPTION_TYPE']) : CCrmContentType::PlainText; $descriptionHtml = ''; if ($descriptionType === CCrmContentType::Html) { $descriptionHtml = $description; } elseif ($descriptionType === CCrmContentType::BBCode) { $parser = new CTextParser(); $descriptionHtml = $parser->convertText($description); } elseif ($descriptionType === CCrmContentType::PlainText) { $descriptionHtml = htmlspecialcharsbx($description); } $postingData = array('STATUS' => 'D', 'FROM_FIELD' => $from, 'TO_FIELD' => $from, 'BCC_FIELD' => implode(',', $to), 'SUBJECT' => $subject, 'BODY_TYPE' => 'html', 'BODY' => $descriptionHtml, 'DIRECT_SEND' => 'Y', 'SUBSCR_FORMAT' => 'html', 'CHARSET' => $postingCharset); CCrmActivity::InjectUrnInMessage($postingData, $urn, CCrmEMailCodeAllocation::GetCurrent()); $posting = new CPosting(); $postingID = $posting->Add($postingData); if ($postingID === false) { $arErrors[] = array('CODE' => self::ERR_CANT_ADD_POSTING, 'MESSAGE' => $posting->LAST_ERROR); return false; } $arUpdateFields = array('COMPLETED' => 'Y', 'ASSOCIATED_ENTITY_ID' => $postingID, 'SETTINGS' => $settings); $fromEmail = strtolower(trim(CCrmMailHelper::ExtractEmail($from))); if ($crmEmail !== '' && $fromEmail !== $crmEmail) { $arUpdateFields['SETTINGS']['MESSAGE_HEADERS'] = array('Reply-To' => "<{$fromEmail}>, <{$crmEmail}>"); } $arUpdateFields['SETTINGS']['IS_MESSAGE_SENT'] = true; if (!CCrmActivity::Update($ID, $arUpdateFields, false, false)) { $arErrors[] = array('CODE' => self::ERR_CANT_UPDATE_ACTIVITY); return false; } // <-- Creating Email // Attaching files --> $storageTypeID = isset($arFields['STORAGE_TYPE_ID']) ? intval($arFields['STORAGE_TYPE_ID']) : StorageType::Undefined; $storageElementsID = isset($arFields['STORAGE_ELEMENT_IDS']) && is_array($arFields['STORAGE_ELEMENT_IDS']) ? $arFields['STORAGE_ELEMENT_IDS'] : array(); $arRawFiles = StorageManager::makeFileArray($storageElementsID, $storageTypeID); foreach ($arRawFiles as &$arRawFile) { if (!$posting->SaveFile($postingID, $arRawFile)) { $arErrors[] = array('CODE' => self::ERR_CANT_SAVE_POSTING_FILE, 'MESSAGE' => $posting->LAST_ERROR); return false; } } unset($arRawFile); // <-- Attaching files // Sending Email --> if ($posting->ChangeStatus($postingID, 'P')) { $rsAgents = CAgent::GetList(array('ID' => 'DESC'), array('MODULE_ID' => 'subscribe', 'NAME' => 'CPosting::AutoSend(' . $postingID . ',%')); if (!$rsAgents->Fetch()) { CAgent::AddAgent('CPosting::AutoSend(' . $postingID . ',true);', 'subscribe', 'N', 0); } } // Try add event to entity $CCrmEvent = new CCrmEvent(); $ownerID = isset($arFields['OWNER_ID']) ? intval($arFields['OWNER_ID']) : 0; $ownerTypeID = isset($arFields['OWNER_TYPE_ID']) ? intval($arFields['OWNER_TYPE_ID']) : 0; if ($ownerID > 0 && $ownerTypeID > 0) { $eventText = ''; $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_SUBJECT') . ': ' . $subject . "\n\r"; $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_FROM') . ': ' . $from . "\n\r"; $eventText .= GetMessage('CRM_ACTIVITY_EMAIL_TO') . ': ' . implode(',', $to) . "\n\r\n\r"; $eventText .= $description; // Register event only for owner $CCrmEvent->Add(array('ENTITY' => array($ownerID => array('ENTITY_TYPE' => CCrmOwnerType::ResolveName($ownerTypeID), 'ENTITY_ID' => $ownerID)), 'EVENT_ID' => 'MESSAGE', 'EVENT_TEXT_1' => $eventText, 'FILES' => $arRawFiles)); } // <-- Sending Email return true; }
} $DB->Commit(); break; case "stop": $cPosting = new CPosting(); $cPosting->ChangeStatus($ID, "W"); $rsAgents = CAgent::GetList(array("ID" => "DESC"), array("MODULE_ID" => "subscribe", "NAME" => "CPosting::AutoSend(" . $ID . ",%")); while ($arAgent = $rsAgents->Fetch()) { CAgent::Delete($arAgent["ID"]); } break; } } } $lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "id", "align" => "right", "default" => true), array("id" => "TIMESTAMP_X", "content" => GetMessage("post_updated"), "sort" => "timestamp", "default" => true), array("id" => "SUBJECT", "content" => GetMessage("post_subj"), "sort" => "subject", "default" => true), array("id" => "BODY_TYPE", "content" => GetMessage("post_body_type"), "sort" => "body_type", "default" => true), array("id" => "STATUS", "content" => GetMessage("post_stat"), "sort" => "status", "default" => true), array("id" => "DATE_SENT", "content" => GetMessage("post_sent"), "sort" => "date_sent", "default" => true), array("id" => "SENT_TO", "content" => GetMessage("post_report"), "sort" => false, "default" => false), array("id" => "FROM_FIELD", "content" => GetMessage("post_from"), "sort" => "from_field", "default" => false), array("id" => "TO_FIELD", "content" => GetMessage("post_to"), "sort" => "to_field", "default" => false))); $cData = new CPosting(); $rsData = $cData->GetList(array($by => $order), $arFilter); $rsData = new CAdminResult($rsData, $sTableID); $rsData->NavStart(); $lAdmin->NavText($rsData->GetNavPrint(GetMessage("post_nav"))); while ($arRes = $rsData->NavNext(true, "f_")) { $row =& $lAdmin->AddRow($f_ID, $arRes); $row->AddViewField("SUBJECT", '<a href="posting_edit.php?ID=' . $f_ID . '&lang=' . LANG . '" title="' . GetMessage("post_act_edit") . '">' . $f_SUBJECT . '</a>'); $row->AddInputField("SUBJECT", array("size" => 20)); $row->AddSelectField("BODY_TYPE", array("text" => GetMessage("POST_TEXT"), "html" => GetMessage("POST_HTML"))); $strStatus = ""; switch ($f_STATUS) { case "S": $strStatus = '[S] ' . GetMessage("POST_STATUS_SENT"); break; case "P":
function AddPosting($arRubric) { global $DB, $USER, $MESS; if (!is_object($USER)) { $USER = new CUser(); } //Include language file for template.php $rsSite = CSite::GetByID($arRubric["SITE_ID"]); $arSite = $rsSite->Fetch(); $rsLang = CLanguage::GetByID($arSite["LANGUAGE_ID"]); $arLang = $rsLang->Fetch(); $arFields = false; if (CPostingTemplate::IsExists($arRubric["TEMPLATE"])) { $strFileName = $_SERVER["DOCUMENT_ROOT"] . "/" . $arRubric["TEMPLATE"] . "/lang/" . $arSite["LANGUAGE_ID"] . "/template.php"; if (file_exists($strFileName)) { include $strFileName; } //Execute template $strFileName = $_SERVER["DOCUMENT_ROOT"] . "/" . $arRubric["TEMPLATE"] . "/template.php"; if (file_exists($strFileName)) { ob_start(); $arFields = @(include $strFileName); $strBody = ob_get_contents(); ob_end_clean(); } } $ID = false; //If there was an array returned then add posting if (is_array($arFields)) { $arFields["BODY"] = $strBody; $cPosting = new CPosting(); $arFields["AUTO_SEND_TIME"] = $arRubric["END_TIME"]; $arFields["RUB_ID"] = array($arRubric["ID"]); $arFields["MSG_CHARSET"] = $arLang["CHARSET"]; $ID = $cPosting->Add($arFields); if ($ID) { if (array_key_exists("FILES", $arFields)) { foreach ($arFields["FILES"] as $arFile) { $cPosting->SaveFile($ID, $arFile); } } if (!array_key_exists("DO_NOT_SEND", $arFields) || $arFields["DO_NOT_SEND"] != "Y") { $cPosting->ChangeStatus($ID, "P"); if (COption::GetOptionString("subscribe", "subscribe_auto_method") !== "cron") { CAgent::AddAgent("CPosting::AutoSend(" . $ID . ",true,\"" . $arRubric["LID"] . "\");", "subscribe", "N", 0, $arRubric["END_TIME"], "Y", $arRubric["END_TIME"]); } } } } //Update last execution time mark $strSql = "UPDATE b_list_rubric SET LAST_EXECUTED=" . $DB->CharToDateFunction($arRubric["END_TIME"]) . " WHERE ID=" . intval($arRubric["ID"]); $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); return $ID; }
COption::SetOptionString("subscribe", "posting_use_editor", "Y"); COption::SetOptionString("subscribe", "attach_images", "Y"); $APPLICATION->SetGroupRight("subscribe", WIZARD_PORTAL_ADMINISTRATION_GROUP, "W"); } //Copy template CopyDirFiles(WIZARD_SERVICE_ABSOLUTE_PATH . "/templates/" . LANGUAGE_ID . "/", $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/subscribe/templates/", $rewrite = false, $recursive = true); $officialIBlockID = ""; if (CModule::IncludeModule("iblock")) { $dbIBlock = CIBlock::GetList(array(), array("CODE" => "official_news")); if ($arIBlock = $dbIBlock->Fetch()) { $officialIBlockID = $arIBlock["ID"]; } } CWizardUtil::ReplaceMacros($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/subscribe/templates/official/template.php", array("IBLOCK_ID" => $officialIBlockID, "SITE_ID" => WIZARD_SITE_ID)); $rsRubric = CRubric::GetList(array(), array("NAME" => GetMessage("SUBSCRIBE_OFFICIAL_INFORMATION"), "LID" => WIZARD_SITE_ID)); if (!$rsRubric->Fetch()) { $arFields = array("ACTIVE" => "Y", "NAME" => GetMessage("SUBSCRIBE_OFFICIAL_INFORMATION"), "SORT" => 100, "DESCRIPTION" => "", "LID" => WIZARD_SITE_ID, "AUTO" => "Y", "DAYS_OF_MONTH" => "", "DAYS_OF_WEEK" => "7", "TIMES_OF_DAY" => "05:00", "TEMPLATE" => substr(BX_PERSONAL_ROOT, 1) . "/php_interface/subscribe/templates/official", "VISIBLE" => "Y", "FROM_FIELD" => COption::GetOptionString("main", "email_from", "admin@" . $_SERVER["SERVER_NAME"]), "LAST_EXECUTED" => ConvertTimeStamp(false, "FULL")); $obRubric = new CRubric(); $ID = $obRubric->Add($arFields); } $rsRubric = CRubric::GetList(array(), array("NAME" => GetMessage("SUBSCRIBE_NEWS_LIFE"), "LID" => WIZARD_SITE_ID)); if (!$rsRubric->Fetch()) { $arFields = array("ACTIVE" => "Y", "NAME" => GetMessage("SUBSCRIBE_NEWS_LIFE"), "SORT" => 200, "DESCRIPTION" => "", "LID" => WIZARD_SITE_ID, "AUTO" => "N"); $obRubric = new CRubric(); $ID = $obRubric->Add($arFields); if ($ID) { $arFields = array("FROM_FIELD" => COption::GetOptionString("main", "email_from", "admin@" . $_SERVER["SERVER_NAME"]), "TO_FIELD" => COption::GetOptionString("main", "email_from", "admin@" . $_SERVER["SERVER_NAME"]), "EMAIL_FILTER" => "%%", "SUBJECT" => GetMessage("SUBSCRIBE_POSTING_SUBJECT"), "BODY_TYPE" => "html", "BODY" => GetMessage("SUBSCRIBE_POSTING_BODY"), "DIRECT_SEND" => "Y", "CHARSET" => LANG_CHARSET, "SUBSCR_FORMAT" => "text", "RUB_ID" => array($ID), "STATUS" => "D"); $obPosting = new CPosting(); $obPosting->Add($arFields); } }
function SendMessage($ID, $timeout = 0, $maxcount = 0, $check_charset = false) { global $DB, $APPLICATION; $eol = CEvent::GetMailEOL(); $ID = intval($ID); $timeout = intval($timeout); $start_time = getmicrotime(); @set_time_limit(0); $this->LAST_ERROR = ""; $post = $this->GetByID($ID); if (!($post_arr = $post->Fetch())) { $this->LAST_ERROR .= GetMessage("class_post_err_notfound"); return false; } if ($post_arr["STATUS"] != "P") { $this->LAST_ERROR .= GetMessage("class_post_err_status") . "<br>"; return false; } if ($check_charset && strlen($post_arr["MSG_CHARSET"]) > 0 && strtoupper($post_arr["MSG_CHARSET"]) != strtoupper(LANG_CHARSET)) { return "CONTINUE"; } if (CPosting::Lock($ID) === false) { if ($e = $APPLICATION->GetException()) { $this->LAST_ERROR .= GetMessage("class_post_err_lock") . "<br>" . $e->GetString(); if (strpos($this->LAST_ERROR, "PLS-00201") !== false && strpos($this->LAST_ERROR, "'DBMS_LOCK'") !== false) { $this->LAST_ERROR .= "<br>" . GetMessage("class_post_err_lock_advice"); } $APPLICATION->ResetException(); return false; } else { return "CONTINUE"; } } if ($post_arr["VERSION"] != '2') { if (is_string($post_arr["BCC_TO_SEND"]) && strlen($post_arr["BCC_TO_SEND"]) > 0) { $a = explode(",", $post_arr["BCC_TO_SEND"]); foreach ($a as $e) { $DB->Query("INSERT INTO b_posting_email (POSTING_ID, STATUS, EMAIL) VALUES (" . $ID . ", 'Y', '" . $DB->ForSQL($e) . "')"); } } if (is_string($post_arr["ERROR_EMAIL"]) && strlen($post_arr["ERROR_EMAIL"]) > 0) { $a = explode(",", $post_arr["ERROR_EMAIL"]); foreach ($a as $e) { $DB->Query("INSERT INTO b_posting_email (POSTING_ID, STATUS, EMAIL) VALUES (" . $ID . ", 'E', '" . $DB->ForSQL($e) . "')"); } } if (is_string($post_arr["SENT_BCC"]) && strlen($post_arr["SENT_BCC"]) > 0) { $a = explode(",", $post_arr["SENT_BCC"]); foreach ($a as $e) { $DB->Query("INSERT INTO b_posting_email (POSTING_ID, STATUS, EMAIL) VALUES (" . $ID . ", 'N', '" . $DB->ForSQL($e) . "')"); } } $DB->Query("UPDATE b_posting SET VERSION='2', BCC_TO_SEND=null, ERROR_EMAIL=null, SENT_BCC=null WHERE ID=" . $ID); } if (strlen($post_arr["CHARSET"]) > 0) { $from_charset = $post_arr["MSG_CHARSET"] ? $post_arr["MSG_CHARSET"] : SITE_CHARSET; $post_arr["BODY"] = $APPLICATION->ConvertCharset($post_arr["BODY"], $from_charset, $post_arr["CHARSET"]); $post_arr["SUBJECT"] = $APPLICATION->ConvertCharset($post_arr["SUBJECT"], $from_charset, $post_arr["CHARSET"]); $post_arr["FROM_FIELD"] = $APPLICATION->ConvertCharset($post_arr["FROM_FIELD"], $from_charset, $post_arr["CHARSET"]); } //Preparing message header, text, subject $sBody = str_replace("\r\n", "\n", $post_arr["BODY"]); if (COption::GetOptionString("main", "CONVERT_UNIX_NEWLINE_2_WINDOWS", "N") == "Y") { $sBody = str_replace("\n", "\r\n", $sBody); } if (COption::GetOptionString("subscribe", "allow_8bit_chars") != "Y") { $sSubject = CMailTools::EncodeSubject($post_arr["SUBJECT"], $post_arr["CHARSET"]); $sFrom = CMailTools::EncodeHeaderFrom($post_arr["FROM_FIELD"], $post_arr["CHARSET"]); } else { $sSubject = $post_arr["SUBJECT"]; $sFrom = $post_arr["FROM_FIELD"]; } if ($post_arr["BODY_TYPE"] == "html") { //URN2URI $tools = new CMailTools(); $sBody = $tools->ReplaceHrefs($sBody); } $bHasAttachments = false; if ($post_arr["BODY_TYPE"] == "html" && COption::GetOptionString("subscribe", "attach_images") == "Y") { //MIME with attachments $tools = new CMailTools(); $sBody = $tools->ReplaceImages($sBody); if (count($tools->aMatches) > 0) { $bHasAttachments = true; $sBoundary = "----------" . uniqid(""); $sHeader = 'From: ' . $sFrom . $eol . 'X-Bitrix-Posting: ' . $post_arr["ID"] . $eol . 'MIME-Version: 1.0' . $eol . 'Content-Type: multipart/related; boundary="' . $sBoundary . '"' . $eol . 'Content-Transfer-Encoding: 8bit'; $sBody = "--" . $sBoundary . $eol . "Content-Type: " . ($post_arr["BODY_TYPE"] == "html" ? "text/html" : "text/plain") . ($post_arr["CHARSET"] != "" ? "; charset=" . $post_arr["CHARSET"] : "") . $eol . "Content-Transfer-Encoding: 8bit" . $eol . $eol . $sBody . $eol; foreach ($tools->aMatches as $attachment) { $aImage = CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $attachment["SRC"]); if ($aImage === false) { continue; } $filename = $_SERVER["DOCUMENT_ROOT"] . $attachment["SRC"]; $handle = fopen($filename, "rb"); $file = fread($handle, filesize($filename)); fclose($handle); $sBody .= $eol . "--" . $sBoundary . $eol . "Content-Type: " . (function_exists("image_type_to_mime_type") ? image_type_to_mime_type($aImage[2]) : CMailTools::ImageTypeToMimeType($aImage[2])) . "; name=\"" . $attachment["DEST"] . "\"" . $eol . "Content-Transfer-Encoding: base64" . $eol . "Content-ID: <" . $attachment["ID"] . ">" . $eol . $eol . chunk_split(base64_encode($file), 72, $eol); } } } $rsFile = CPosting::GetFileList($ID); $arFile = $rsFile->Fetch(); if ($arFile) { if (!$bHasAttachments) { $bHasAttachments = true; $sBoundary = "----------" . uniqid(""); $sHeader = "From: " . $sFrom . $eol . 'X-Bitrix-Posting: ' . $post_arr["ID"] . $eol . "MIME-Version: 1.0" . $eol . "Content-Type: multipart/related; boundary=\"" . $sBoundary . "\"" . $eol . "Content-Transfer-Encoding: 8bit"; $sBody = "--" . $sBoundary . $eol . "Content-Type: " . ($post_arr["BODY_TYPE"] == "html" ? "text/html" : "text/plain") . ($post_arr["CHARSET"] != "" ? "; charset=" . $post_arr["CHARSET"] : "") . $eol . "Content-Transfer-Encoding: 8bit" . $eol . $eol . $sBody . $eol; } do { if (strlen($post_arr["CHARSET"]) > 0) { $from_charset = $post_arr["MSG_CHARSET"] ? $post_arr["MSG_CHARSET"] : SITE_CHARSET; $file_name = $APPLICATION->ConvertCharset($arFile["ORIGINAL_NAME"], $from_charset, $post_arr["CHARSET"]); } else { $file_name = $arFile["ORIGINAL_NAME"]; } $sBody .= $eol . "--" . $sBoundary . $eol . "Content-Type: " . $arFile["CONTENT_TYPE"] . "; name=\"" . $file_name . "\"" . $eol . "Content-Transfer-Encoding: base64" . $eol . "Content-Disposition: attachment; filename=\"" . CMailTools::EncodeHeaderFrom($file_name, $post_arr["CHARSET"]) . "\"" . $eol . $eol; $arTempFile = CFile::MakeFileArray($arFile["ID"]); $sBody .= chunk_split(base64_encode(file_get_contents($arTempFile["tmp_name"])), 72, $eol); } while ($arFile = $rsFile->Fetch()); } if ($bHasAttachments) { $sBody .= $eol . "--" . $sBoundary . "--" . $eol; } else { //plain message without MIME $sHeader = "From: " . $sFrom . $eol . 'X-Bitrix-Posting: ' . $post_arr["ID"] . $eol . "MIME-Version: 1.0" . $eol . "Content-Type: " . ($post_arr["BODY_TYPE"] == "html" ? "text/html" : "text/plain") . ($post_arr["CHARSET"] != "" ? "; charset=" . $post_arr["CHARSET"] : "") . $eol . "Content-Transfer-Encoding: 8bit"; } $mail_additional_parameters = trim(COption::GetOptionString("subscribe", "mail_additional_parameters")); if ($post_arr["DIRECT_SEND"] == "Y") { //personal delivery $arEvents = array(); $rsEvents = GetModuleEvents("subscribe", "BeforePostingSendMail"); while ($arEvent = $rsEvents->Fetch()) { $arEvents[] = $arEvent; } $rsEmails = $DB->Query($DB->TopSql("\n\t\t\t\tSELECT *\n\t\t\t\tFROM b_posting_email\n\t\t\t\tWHERE POSTING_ID = " . $ID . " AND STATUS='Y'\n\t\t\t", $maxcount)); while ($arEmail = $rsEmails->Fetch()) { //Event part $arFields = array("POSTING_ID" => $ID, "EMAIL" => $arEmail["EMAIL"], "SUBJECT" => $sSubject, "BODY" => $sBody, "HEADER" => $sHeader, "EMAIL_EX" => $arEmail); foreach ($arEvents as $arEvent) { $arFields = ExecuteModuleEventEx($arEvent, array($arFields)); } //Sending if (is_array($arFields)) { $result = bxmail($arFields["EMAIL"], $arFields["SUBJECT"], $arFields["BODY"], $arFields["HEADER"], $mail_additional_parameters); } else { $result = $arFields !== false; } //Result check and iteration if ($result) { $DB->Query("UPDATE b_posting_email SET STATUS='N' WHERE ID = " . $arEmail["ID"]); } else { $DB->Query("UPDATE b_posting_email SET STATUS='E' WHERE ID = " . $arEmail["ID"]); } if ($timeout > 0 && getmicrotime() - $start_time >= $timeout) { break; } self::$current_emails_per_hit++; } } else { //BCC delivery $rsEmails = $DB->Query($DB->TopSql("\n\t\t\t\tSELECT *\n\t\t\t\tFROM b_posting_email\n\t\t\t\tWHERE POSTING_ID = " . $ID . " AND STATUS='Y'\n\t\t\t", COption::GetOptionString("subscribe", "max_bcc_count"))); $aStep = array(); while ($arEmail = $rsEmails->Fetch()) { $aStep[$arEmail["ID"]] = $arEmail["EMAIL"]; } if (count($aStep) > 0) { $BCC = implode(",", $aStep); $sHeaderStep = $sHeader . $eol . "Bcc: " . $BCC; $result = bxmail($post_arr["TO_FIELD"], $sSubject, $sBody, $sHeaderStep, $mail_additional_parameters); if ($result) { $DB->Query("UPDATE b_posting_email SET STATUS='N' WHERE ID in (" . implode(", ", array_keys($aStep)) . ")"); } else { $DB->Query("UPDATE b_posting_email SET STATUS='E' WHERE ID in (" . implode(", ", array_keys($aStep)) . ")"); $this->LAST_ERROR .= GetMessage("class_post_err_mail") . "<br>"; } } } //set status and delivered and error emails $arStatuses = $this->GetEmailStatuses($ID); if (!array_key_exists("Y", $arStatuses)) { $STATUS = array_key_exists("E", $arStatuses) ? "E" : "S"; $DATE = $DB->GetNowFunction(); } else { $STATUS = "P"; $DATE = "null"; } CPosting::UnLock($ID); $DB->Query("UPDATE b_posting SET STATUS='" . $STATUS . "', DATE_SENT=" . $DATE . " WHERE ID=" . $ID); return $STATUS == "P" ? "CONTINUE" : true; }
define("HELP_FILE", "add_issue.php"); IncludeModuleLangFile(__FILE__); $POST_RIGHT = $APPLICATION->GetGroupRight("subscribe"); if ($POST_RIGHT == "D") { $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } $aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("post_posting_tab"), "ICON" => "main_user_edit", "TITLE" => GetMessage("post_posting_tab_title")), array("DIV" => "edit2", "TAB" => GetMessage("post_subscr_tab"), "ICON" => "main_user_edit", "TITLE" => GetMessage("post_subscr_tab_title")), array("DIV" => "edit3", "TAB" => GetMessage("post_attachments"), "ICON" => "main_user_edit", "TITLE" => GetMessage("post_attachments_title")), array("DIV" => "edit4", "TAB" => GetMessage("post_params_tab"), "ICON" => "main_user_edit", "TITLE" => GetMessage("post_params_tab_title"))); $tabControl = new CAdminTabControl("tabControl", $aTabs); CModule::IncludeModule("fileman"); $ID = intval($ID); // Id of the edited record $bCopy = $action == "copy"; $message = null; $bVarsFromForm = false; if ($REQUEST_METHOD == "POST" && $save . $apply . $Send . $Resend . $Continue != "" && $POST_RIGHT == "W" && check_bitrix_sessid()) { $posting = new CPosting(); $arFields = array("FROM_FIELD" => $_REQUEST["FROM_FIELD"], "TO_FIELD" => $_REQUEST["TO_FIELD"], "BCC_FIELD" => $_REQUEST["BCC_FIELD"], "EMAIL_FILTER" => $_REQUEST["EMAIL_FILTER"], "SUBJECT" => $_REQUEST["SUBJECT"], "BODY_TYPE" => $_REQUEST["BODY_TYPE"] != "html" ? "text" : "html", "BODY" => $_REQUEST["BODY"], "DIRECT_SEND" => $_REQUEST["DIRECT_SEND"] != "Y" ? "N" : "Y", "CHARSET" => $_REQUEST["CHARSET"], "SUBSCR_FORMAT" => $_REQUEST["SUBSCR_FORMAT"] != "html" && $_REQUEST["SUBSCR_FORMAT"] != "text" ? false : $_REQUEST["SUBSCR_FORMAT"], "RUB_ID" => $_REQUEST["RUB_ID"], "GROUP_ID" => $_REQUEST["GROUP_ID"], "AUTO_SEND_TIME" => $_REQUEST["AUTO_SEND_FLAG"] != "Y" ? false : $_REQUEST["AUTO_SEND_TIME"]); if ($STATUS != "") { if ($STATUS != "S" && $STATUS != "E" && $STATUS != "P" && $STATUS != "W") { $STATUS = "D"; } } if ($ID > 0) { $res = $posting->Update($ID, $arFields); if (strlen($Resend) > 0) { $STATUS = "W"; } if ($res && $STATUS != "") { $res = $posting->ChangeStatus($ID, $STATUS); } } else {
$postingCharset = $siteCharset; } else { foreach ($arSupportedCharset as $curCharset) { if (strcasecmp($curCharset, $siteCharset) === 0) { $postingCharset = $curCharset; break; } } if ($postingCharset === '') { $postingCharset = $arSupportedCharset[0]; } } //<-- Try to resolve posting charset $postingData = array('STATUS' => 'D', 'FROM_FIELD' => $from, 'TO_FIELD' => $from, 'BCC_FIELD' => implode(',', $to), 'SUBJECT' => $subject, 'BODY_TYPE' => 'html', 'BODY' => $messageHtml !== '' ? $messageHtml : GetMessage('CRM_EMAIL_ACTION_DEFAULT_DESCRIPTION'), 'DIRECT_SEND' => 'Y', 'SUBSCR_FORMAT' => 'html', 'CHARSET' => $postingCharset); CCrmActivity::InjectUrnInMessage($postingData, $urn, CCrmEMailCodeAllocation::GetCurrent()); $posting = new CPosting(); $postingID = $posting->Add($postingData); if ($postingID === false) { $arErrors[] = GetMessage('CRM_ACTIVITY_COULD_NOT_CREATE_POSTING'); $arErrors[] = $posting->LAST_ERROR; } else { // Attaching files --> $arRawFiles = isset($arFields['STORAGE_ELEMENT_IDS']) && !empty($arFields['STORAGE_ELEMENT_IDS']) ? \Bitrix\Crm\Integration\StorageManager::makeFileArray($arFields['STORAGE_ELEMENT_IDS'], $storageTypeID) : array(); foreach ($arRawFiles as &$arRawFile) { if (isset($arRawFile['ORIGINAL_NAME'])) { $arRawFile['name'] = $arRawFile['ORIGINAL_NAME']; } if (!$posting->SaveFile($postingID, $arRawFile)) { $arErrors[] = GetMessage('CRM_ACTIVITY_COULD_NOT_SAVE_POSTING_FILE', array('#FILE_NAME#' => $arRawFile['ORIGINAL_NAME'])); $arErrors[] = $posting->LAST_ERROR; break;
<?php require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/subscribe/include.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/subscribe/prolog.php"; define("HELP_FILE", "add_issue.php"); IncludeModuleLangFile(__FILE__); $POST_RIGHT = $APPLICATION->GetGroupRight("subscribe"); if ($POST_RIGHT == "D") { $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } $rsFile = CPosting::GetFileList($POSTING_ID, $FILE_ID); if ($arFile = $rsFile->Fetch()) { CFile::ViewByUser($arFile, array("force_download" => true)); } else { require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_admin_after.php"; echo ShowError(GetMessage("POST_ERROR_ATTACH_NOT_FOUND")); require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/epilog_admin.php"; }
} else { foreach ($arSupportedCharset as $curCharset) { if (strcasecmp($curCharset, $siteCharset) === 0) { $postingCharset = $curCharset; break; } } if ($postingCharset === '') { $postingCharset = $arSupportedCharset[0]; } } //<-- Try to resolve posting charset //Creating Email --> $postingData = array('STATUS' => 'D', 'FROM_FIELD' => $from, 'TO_FIELD' => $from, 'BCC_FIELD' => implode(',', $to), 'SUBJECT' => $subject, 'BODY_TYPE' => 'html', 'BODY' => htmlspecialcharsbx($descr), 'DIRECT_SEND' => 'Y', 'SUBSCR_FORMAT' => 'html', 'CHARSET' => $postingCharset); CCrmActivity::InjectUrnInMessage($postingData, $urn, CCrmEMailCodeAllocation::GetCurrent()); $posting = new CPosting(); $postingID = $posting->Add($postingData); if ($postingID > 0) { $updateFields = array('ASSOCIATED_ENTITY_ID' => $postingID); $fromEmail = strtolower(trim(CCrmMailHelper::ExtractEmail($from))); if ($crmEmail !== '' && $fromEmail !== $crmEmail) { $updateFields['SETTINGS'] = array('MESSAGE_HEADERS' => array('Reply-To' => "<{$fromEmail}>, <{$crmEmail}>")); } CCrmActivity::Update($ID, $updateFields, false, false); } // <-- Creating Email // Attaching files --> $rawFiles = isset($fields['STORAGE_ELEMENT_IDS']) ? StorageManager::makeFileArray($fields['STORAGE_ELEMENT_IDS'], $storageTypeID) : array(); foreach ($rawFiles as &$rawFile) { $posting->SaveFile($postingID, $rawFile); }
if (count($arSupportedCharset) === 0) { $postingCharset = $siteCharset; } else { foreach ($arSupportedCharset as $curCharset) { if (strcasecmp($curCharset, $siteCharset) === 0) { $postingCharset = $curCharset; break; } } if ($postingCharset === '') { $postingCharset = $arSupportedCharset[0]; } } //<-- Try to resolve posting charset if (!empty($arFmUserList) && !empty($sEmailFrom)) { $CPosting = new CPosting(); $arFields = array('STATUS' => 'D', 'FROM_FIELD' => $sEmailFrom, 'TO_FIELD' => $sEmailFrom, 'BCC_FIELD' => implode(',', $arFmUserList), 'SUBJECT' => $_POST['TITLE'], 'BODY_TYPE' => 'html', 'BODY' => $_POST['COMMENTS'], 'DIRECT_SEND' => 'Y', 'SUBSCR_FORMAT' => 'html', 'CHARSET' => $postingCharset); $SID = $CPosting->Add($arFields); if (!empty($_FILES['ATTACH'])) { $arAttachs = array(); foreach ($_FILES['ATTACH'] as $type => $ar) { foreach ($ar as $key => $value) { $arAttachs[$key][$type] = $value; } } foreach ($arAttachs as $k => $arAttach) { // Fix for issue #29769 if ($arAttach['error'] == 0 && isset($arAttach['tmp_name']) && strlen($arAttach['tmp_name']) > 0 && is_uploaded_file($arAttach['tmp_name'])) { $CPosting->SaveFile($SID, $arAttach); } }
if ($SUBSCR_ID <= 0) { continue; } switch ($_REQUEST['action']) { case "sudelete": CSubscription::Delete($SUBSCR_ID); break; case "inactive": $oSubscription = new CSubscription(); $oSubscription->Update($SUBSCR_ID, array("ACTIVE" => "N")); break; } } } $lAdmin->AddHeaders(array(array("id" => "EMAIL", "content" => GetMessage("POST_EMAIL"), "default" => true), array("id" => "SUBSCRIPTION_ID", "content" => GetMessage("POST_SUBSCRIPTION_ID"), "default" => true, "align" => "right"), array("id" => "USER_ID", "content" => GetMessage("POST_USER_ID"), "default" => true, "align" => "right"))); $cData = new CPosting(); $rsData = $cData->GetEmailsByStatus($ID, $find_status_id); $rsData = new CAdminResult($rsData, $sTableID); $rsData->NavStart(); $lAdmin->NavText($rsData->GetNavPrint("")); while ($arRes = $rsData->NavNext(true, "f_")) { $row =& $lAdmin->AddRow($f_EMAIL, $arRes); if ($f_SUBSCRIPTION_ID > 0) { $rs = CSubscription::GetByID($f_SUBSCRIPTION_ID); $ar = $rs->Fetch(); if (!$ar) { $row->AddViewField("SUBSCRIPTION_ID", $f_SUBSCRIPTION_ID . ' (' . GetMessage("POST_SUBSCR_DELETED") . ')'); } elseif ($ar["ACTIVE"] == "N") { $row->AddViewField("SUBSCRIPTION_ID", '<a target="_blank" href="subscr_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $f_SUBSCRIPTION_ID . '">' . $f_SUBSCRIPTION_ID . '</a> (' . GetMessage("POST_SUBSCR_INACTIVE") . ')'); } else { $row->AddViewField("SUBSCRIPTION_ID", '<a target="_blank" href="subscr_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $f_SUBSCRIPTION_ID . '">' . $f_SUBSCRIPTION_ID . '</a>');