/** * @return EmailAddressCollection */ function &GetAllRecipients($onlyTo = false, $addReply = false) { $emails = array(); $allRecipients = new EmailAddressCollection(); $toAddr =& $this->GetTo(); foreach (array_keys($toAddr->Instance()) as $key) { $temp = $toAddr->Get($key); if ($temp && !in_array($temp->Email, $emails)) { $emails[] = $temp->Email; $allRecipients->AddEmailAddress($temp); } unset($temp); } if ($allRecipients->Count() > 0 && $onlyTo) { return $allRecipients; } $toCc =& $this->GetCc(); foreach (array_keys($toCc->Instance()) as $key) { $temp = $toCc->Get($key); if ($temp && !in_array($temp->Email, $emails)) { $emails[] = $temp->Email; $allRecipients->AddEmailAddress($temp); } unset($temp); } $toBcc =& $this->GetBcc(); foreach (array_keys($toBcc->Instance()) as $key) { $temp = $toBcc->Get($key); if ($temp && !in_array($temp->Email, $emails)) { $emails[] = $temp->Email; $allRecipients->AddEmailAddress($temp); } unset($temp); } if ($addReply) { $toReply =& $this->GetReplyTo(); if ($toReply->Count() > 0) { foreach (array_keys($toReply->Instance()) as $key) { $temp = $toReply->Get($key); if ($temp && !in_array($temp->Email, $emails)) { $emails[] = $temp->Email; $allRecipients->AddEmailAddress($temp); } unset($temp); } } else { $toFrom =& $this->GetFrom(); if ($toFrom && !in_array($toFrom->Email, $emails)) { $emails[] = $toFrom->Email; $allRecipients->AddEmailAddress($toFrom); } } } return $allRecipients; }
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); } }
} } } 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 ($l = 0; $l < $emailsCollection->Count(); $l++) { $emailObj =& $emailsCollection->Get($l); if (trim($emailObj->Email)) { $arrEmails[$emailObj->Email] = trim($emailObj->DisplayName); } } if (count($gids) > 0) { $processor->DbStorage->UpdateGroupsFrequency($gids); } $processor->DbStorage->UpdateSuggestTable($account, $arrEmails); //End suggestion if ($needToDelete) { $messageIdSet = array($idtoDelete); if ($account->MailProtocol == MAILPROTOCOL_IMAP4) { if ($processor->PurgeFolder($draftsFolder)) { $processor->DbStorage->DeleteMessages($messageIdSet, false, $draftsFolder);
/** * @param EmailAddressCollection $recipients */ function AddEmailAddressCollection($recipients) { for ($i = 0; $i < $recipients->Count(); $i++) { $this->AddEmailAddress($recipients->Get($i)); } }