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.
*/

View file

@ -39,6 +39,7 @@ $lang->msg_allow_message_to_friend = 'Failed to send a message because the recip
$lang->msg_disallow_message = 'Failed to send a message because the recipient blocked receiving messages.';
$lang->about_allow_message = 'You can set whether to receive messages or not.';
$lang->msg_send_mail_privacy = 'Your email address will be exposed to the recipient.';
$lang->msg_send_mail_admin_only = 'The email option can only be used by the administrator.';
$lang->message_notice = 'Send a message to the author about this. If you don\'t write a message, it is not sent.';
$lang->friends_page_does_not_support = 'Friends in a mobile environment is not supported. Please go to the PC page.';
$lang->communication_send_message_grant = 'Send Message Grant';

View file

@ -38,6 +38,7 @@ $lang->msg_content_is_null = '내용을 입력해주세요.';
$lang->msg_allow_message_to_friend = '친구에게만 쪽지 발송을 허용한 사용자라서 쪽지 발송을 하지 못했습니다.';
$lang->msg_disallow_message = '쪽지 수신을 거부한 사용자라서 쪽지 발송을 하지 못했습니다.';
$lang->msg_send_mail_privacy = '보낸이의 메일 주소가 받는이에게 노출될 수 있습니다.';
$lang->msg_send_mail_admin_only = '메일 발송 기능은 관리자만 사용할 수 있습니다.';
$lang->about_allow_message = '쪽지 수신 여부를 결정할 수 있습니다.';
$lang->message_notice = '저작자에게 쪽지를 발송해서 이 사실을 알립니다. 작성하지 않으면 발송하지 않습니다.';
$lang->friends_page_does_not_support = '모바일 환경에서는 친구 보기 페이지를 지원하지 않습니다. PC 화면으로 이동하세요.';

View file

@ -41,6 +41,11 @@
<label for="message_content">{$lang->content}</label>
<textarea id="message_content" name="new_content" rows="8" style="width:100%;box-sizing:border-box"></textarea>
</li>
<!--@if($this->user->isAdmin())-->
<li>
<span id="message_send_mail"><input type="checkbox" value="Y" name="send_mail" /> {$lang->cmd_send_mail}</span>
</li>
<!--@endif-->
</ul>
<div class="bna">
<span class="fl"><a href="{getUrl('act', 'dispCommunicationMessages')}" class="bn white">{$lang->cmd_back}</a></span>

View file

@ -37,6 +37,12 @@
<th scope="row">{$lang->title}</th>
<td><input type="text" name="title" id="message_title" value="{$source_message->title}" style="width:90%" /></td>
</tr>
<!--@if($this->user->isAdmin())-->
<tr>
<th scope="row">{$lang->cmd_option}</th>
<td><label><input type="checkbox" value="Y" name="send_mail" /> {$lang->cmd_send_mail}</label></td>
</tr>
<!--@endif-->
</table>
{$editor|noescape}
<div class="btnArea">