Improve the broadcast message tool

* Make it possible by config option that non global admins can send
  broadcast messages to their domains.
* Allow the sender to select the domains the broadcast message should be
  delivered to
* Allow the sender to decide if the broadcast message should just be
  delivered to mailboxes
pull/24/head
Jan-Frederik Rieckers 8 years ago
parent ace8597bb3
commit 3c3d844130
No known key found for this signature in database
GPG Key ID: 664B03955EA04DEF

@ -27,7 +27,11 @@
require_once('common.php');
authentication_require_role('global-admin');
if ($CONF['sendmail_only_global_admin'] == 'YES' ) {
authentication_require_role('global-admin');
} else {
authentication_require_role('admin');
}
if ($CONF['sendmail'] != 'YES') {
header("Location: main.php");
@ -35,6 +39,7 @@ if ($CONF['sendmail'] != 'YES') {
}
$smtp_from_email = smtp_get_admin_email();
$allowed_domains = list_domains_for_admin(authentication_get_username());
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
@ -47,23 +52,38 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
}
else
{
$wanted_domains = array_intersect($allowed_domains, $_POST['domains']);
$table_mailbox = table_by_key('mailbox');
$table_alias = table_by_key('alias');
$q = "select username from $table_mailbox union select goto from $table_alias " .
"where goto not in (select username from $table_mailbox)";
$result = db_query ($q);
if ($result['rows'] > 0)
{
$table_alias = table_by_key('alias');
$recipients = [];
foreach( $wanted_domains as $domain) {
$q = "SELECT username from $table_mailbox WHERE domain = '$domain'";
if(!isset($_POST['mailboxes_only']) || $_POST['mailboxes_only'] != "on") {
$q .= " UNION SELECT GOTO FROM $table_alias WHERE domain = '$domain' " .
" AND goto NOT IN ($q)";
}
$result = db_query ($q);
if($result['rows'] > 0) {
while($row = db_array($result['result'])) {
$recipients[] = $row[0];
}
}
}
$recipients = array_unique($recipients);
if(count($recipients)>0) {
mb_internal_encoding("UTF-8");
$b_name = mb_encode_mimeheader( $_POST['name'], 'UTF-8', 'Q');
$b_subject = mb_encode_mimeheader( $_POST['subject'], 'UTF-8', 'Q');
$b_message = base64_encode($_POST['message']);
$i = 0;
while ($row = db_array ($result['result'])) {
$fTo = $row[0];
foreach ($recipients as $rcpt) {
$fTo = $rcpt;
$fHeaders = 'To: ' . $fTo . "\n";
$fHeaders .= 'From: ' . $b_name . ' <' . $smtp_from_email . ">\n";
$fHeaders .= 'Subject: ' . $b_subject . "\n";
@ -92,6 +112,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if ($_SERVER['REQUEST_METHOD'] == "GET" || $error == 1)
{
$smarty->assign ('allowed_domains', $allowed_domains);
$smarty->assign ('smtp_from_email', $smtp_from_email);
$smarty->assign ('error', $error);
$smarty->assign ('smarty_template', 'broadcast-message');

@ -396,6 +396,9 @@ $CONF['backup'] = 'NO';
// Send Mail
// If you don't want sendmail tab set this to 'NO';
$CONF['sendmail'] = 'YES';
// Set this to NO if you want to allow non-super-admins to
// send mails to their users
$CONF['sendmail_only_global_admin'] = 'YES';
// Logging
// If you don't want logging set this to 'NO';

@ -331,6 +331,8 @@ $PALANG['pBroadcast_name'] = 'Your name';
$PALANG['pBroadcast_success'] = 'Your broadcast message was sent.';
$PALANG['pAdminMenu_broadcast_message'] = 'Broadcast message';
$PALANG['pBroadcast_error_empty'] = 'The fields Name, Subject and Message shouldn\'t be empty!';
$PALANG['broadcast_mailboxes_only'] = 'Only send to mailboxes';
$PALANG['broadcast_to_domains'] = 'Send to domains:';
$PALANG['pStatus_undeliverable'] = 'maybe UNDELIVERABLE ';
$PALANG['pStatus_custom'] = 'Delivers to ';

@ -21,6 +21,18 @@
<td class="label"><label>{$PALANG.message}:</label></td>
<td><textarea class="flat" cols="40" rows="6" name="message"></textarea></td>
</tr>
<tr>
<td class="label"><label>{$PALANG.broadcast_mailboxes_only}</label></td>
<td><input type="checkbox" name="mailboxes_only"/></td>
</tr>
<tr>
<td class="label"><label>{$PALANG.broadcast_to_domains}</label></td>
<td>
<select multiple="multiple" name="domains[]">
{html_options output=$allowed_domains values=$allowed_domains selected=$allowed_domains}
</select>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>

@ -62,7 +62,7 @@
<li><a target="_top" href="{#url_sendmail#}">{$PALANG.pMenu_sendmail}</a>
<ul>
<li><a target="_top" href="{#url_sendmail#}">{$PALANG.pMenu_sendmail}</a></li>
{if $authentication_has_role.global_admin}
{if $authentication_has_role.global_admin || $CONF.sendmail_only_global_admin!== 'YES'}
<li><a target="_top" href="{#url_broadcast_message#}">{$PALANG.pAdminMenu_broadcast_message}</a></li>
{/if}
</ul>

Loading…
Cancel
Save