Restore sending message by email (revert #1109)

- 스팸 방지를 위해 관리자만 발송할 수 있도록 변경
- 보낸이의 메일 주소를 노출하지 않도록 변경
This commit is contained in:
Kijin Sung 2023-10-24 21:33:39 +09:00
parent c84756e769
commit 53ec02b6bb
5 changed files with 63 additions and 0 deletions

View file

@ -88,6 +88,12 @@ class CommunicationController extends communication
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$send_mail = Context::get('send_mail') === 'Y' ? 'Y' : 'N';
if ($send_mail === 'Y' && !$this->user->isAdmin())
{
throw new Rhymix\Framework\Exception('msg_send_mail_admin_only');
}
// Check if there is a member to receive a message
$oMemberModel = getModel('member');
$oCommunicationModel = getModel('communication');
@ -128,6 +134,12 @@ class CommunicationController extends communication
return $output;
}
// send an e-mail (admin only)
if($send_mail === 'Y')
{
$this->sendMessageByEmail($logged_info, $receiver_member_info, $title, $content);
}
if(!in_array(Context::getRequestMethod(), array('XMLRPC', 'JSON')))
{
if(Context::get('is_popup') != 'Y' && Context::get('window_type') != 'self')
@ -267,6 +279,44 @@ class CommunicationController extends communication
return new BaseObject(0, 'success_sended');
}
/**
* Send a message by email.
*
* @param object $sender
* @param object $recipient
* @param string $title
* @param string $content
* @return bool
*/
public function sendMessageByEmail($sender, $recipient, $title, $content): bool
{
if (empty($recipient->email_address) || !config('mail.default_from'))
{
return false;
}
$view_url = Context::getRequestUri();
$mail_title = vsprintf('%s - %s', [
Context::getSiteTitle(),
$title,
]);
$mail_content = vsprintf('From: %s<br><hr><br>%s<br><hr><br>%s<br><a href="%s" target="_blank">%s</a>', [
$sender->nick_name,
utf8_mbencode(removeHackTag($content)),
Context::getSiteTitle(),
$view_url, $view_url,
]);
$oMail = new \Rhymix\Framework\Mail();
$oMail->setFrom(config('mail.default_from'), config('mail.default_name'));
$oMail->addTo($recipient->email_address, $recipient->nick_name ?: null);
$oMail->setSubject($mail_title);
$oMail->setBody($mail_content);
$output = $oMail->send();
return (bool)$output;
}
/**
* Move a message to the archive.
*/