Commit 4a00c042 authored by Jonny Bradley's avatar Jonny Bradley

[ENH] user messages: Add reply-to and bcc checkboxes to message send forms.

Allows your real email to be the reply-to address on a message notification, and to be able to receive a copy via Bcc.
Also slightly better error handling.
parent 265db744
......@@ -38,7 +38,7 @@ class Messu extends TikiLib
/**
* Send a message to a user
*/
function post_message($user, $from, $to, $cc, $subject, $body, $priority, $replyto_hash='') {
function post_message($user, $from, $to, $cc, $subject, $body, $priority, $replyto_hash='', $replyto_email='', $bcc_sender = '') {
global $smarty, $userlib, $prefs;
$subject = strip_tags($subject);
......@@ -77,13 +77,21 @@ class Messu extends TikiLib
$mail->setSubject(sprintf($s, $_SERVER["SERVER_NAME"]));
$mail_data = $smarty->fetchLang($lg, 'mail/messu_message_notification.tpl');
$mail->setText($mail_data);
if ($userlib->get_user_preference($from,'email is public','n') == 'y') {
$prefs['sender_email'] = $userlib->get_user_email($from);
$from_email = $userlib->get_user_email($from);
if ($bcc_sender === 'y' && !empty($from_email)) {
$mail->setHeader("Bcc", $from_email);
}
if ($replyto_email !== 'y' && $userlib->get_user_preference($from,'email is public','n') !== 'y') {
$from_email = ''; // empty $from_email if not to be used - saves getting it twice
}
if (!empty($from_email)) {
$mail->setHeader("Reply-To", $from_email);
}
if (strlen( $prefs['sender_email'] ) > 1 ) {
$mail->setHeader("Reply-To", $prefs['sender_email']);
if (!empty($prefs['sender_email'])) {
$mail->setHeader("From", $prefs['sender_email']);
} else if (!empty($from_email)) {
$mail->setHeader("From", $from_email);
}
if (!$mail->send(array($email), 'mail'))
......
......@@ -141,14 +141,19 @@ if (isset($_REQUEST['send'])) {
}
// Insert the message in the inboxes of each user
foreach($users as $a_user) {
$messulib->post_message($a_user, $user, $_REQUEST['to'], $_REQUEST['cc'], $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['priority'], $_REQUEST['replyto_hash']);
if ($prefs['feature_score'] == 'y') {
$tikilib->score_event($user, 'message_send');
$tikilib->score_event($a_user, 'message_receive');
}
// if this is a reply flag the original messages replied to
if ($_REQUEST['replyto_hash'] <> '') {
$messulib->mark_replied($a_user, $_REQUEST['replyto_hash']);
$result = $messulib->post_message($a_user, $user, $_REQUEST['to'], $_REQUEST['cc'], $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['priority'], $_REQUEST['replyto_hash'],
isset($_REQUEST['replytome']) ? 'y' : '', isset($_REQUEST['bccme']) ? 'y' : '');
if ($result) {
if ($prefs['feature_score'] == 'y') {
$tikilib->score_event($user, 'message_send');
$tikilib->score_event($a_user, 'message_receive');
}
// if this is a reply flag the original messages replied to
if ($_REQUEST['replyto_hash'] <> '') {
$messulib->mark_replied($a_user, $_REQUEST['replyto_hash']);
}
} else {
$message = tra('An error occurred, please check your mail settings and try again');
}
}
// Insert a copy of the message in the sent box of the sender
......
......@@ -85,6 +85,16 @@
<td>&nbsp;</td>
<td>
<input type="submit" name="send" value="{tr}Send{/tr}" />
<input type="checkbox" name="replytome" id="replytome" />
<label for="replytome">
{tr}Reply-to my email{/tr}
{help url="User+Information" desc="{tr}Reply-to my email{/tr}:{tr}The user will be able to reply to you directly via email.{/tr}"}
</label>
<input type="checkbox" name="bccme" id="bccme" />
<label for="bccme">
{tr}Send me a copy{/tr}
{help url="User+Information" desc="{tr}Send me a copy{/tr}:{tr}You will be sent a copy of this email.{/tr}"}
</label>
</td>
</tr>
</table>
......
......@@ -338,6 +338,17 @@
<textarea rows="20" cols="80" name="body" style="border: solid 1px #000; width: 100%;"></textarea>
</label>
</div>
<input type="checkbox" name="replytome" id="replytome" />
<label for="replytome">
{tr}Reply-to my email{/tr}
{help url="User+Information" desc="{tr}Reply-to my email{/tr}:{tr}The user will be able to reply to you directly via email.{/tr}"}
</label>
<input type="checkbox" name="bccme" id="bccme" />
<label for="bccme">
{tr}Send me a copy{/tr}
{help url="User+Information" desc="{tr}Send me a copy{/tr}:{tr}You will be sent a copy of this email.{/tr}"}
</label>
</div>
</form>
......
......@@ -63,8 +63,13 @@ if ($user) {
$smarty->display("tiki.tpl");
die;
}
$message = tra('Message sent to') . ':' . $userwatch . '<br />';
$messulib->post_message($userwatch, $user, $_REQUEST['to'], '', $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['priority']);
$sent = $messulib->post_message($userwatch, $user, $_REQUEST['to'], '', $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['priority'], '',
isset($_REQUEST['replytome']) ? 'y' : '', isset($_REQUEST['bccme']) ? 'y' : '');
if ($sent) {
$message = tra('Message sent to') . ':' . $userwatch . '<br />';
} else {
$message = tra('An error occurred, please check your mail settings and try again');
}
$smarty->assign('message', $message);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment