git subrepo commit (merge) mailcow/src/mailcow-dockerized

subrepo: subdir:   "mailcow/src/mailcow-dockerized"
  merged:   "02ae5285"
upstream: origin:   "https://github.com/mailcow/mailcow-dockerized.git"
  branch:   "master"
  commit:   "649a5c01"
git-subrepo: version:  "0.4.3"
  origin:   "???"
  commit:   "???"
Change-Id: I870ad468fba026cc5abf3c5699ed1e12ff28b32b
diff --git a/mailcow/src/mailcow-dockerized/data/web/inc/functions.quota_notification.inc.php b/mailcow/src/mailcow-dockerized/data/web/inc/functions.quota_notification.inc.php
index 9ca5a22..9f58bfb 100644
--- a/mailcow/src/mailcow-dockerized/data/web/inc/functions.quota_notification.inc.php
+++ b/mailcow/src/mailcow-dockerized/data/web/inc/functions.quota_notification.inc.php
@@ -65,3 +65,86 @@
     break;

   }

 }

+function quota_notification_bcc($_action, $_data = null) {

+	global $redis;

+	$_data_log = $_data;

+  if ($_SESSION['mailcow_cc_role'] != "admin" && $_SESSION['mailcow_cc_role'] != "domainadmin") {

+    $_SESSION['return'][] = array(

+      'type' => 'danger',

+      'log' => array(__FUNCTION__, $_action, $_data_log),

+      'msg' => 'access_denied'

+    );

+    return false;

+  }

+  switch ($_action) {

+    case 'edit':

+      $domain = $_data['domain'];

+      if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {

+        $_SESSION['return'][] = array(

+          'type' => 'danger',

+          'log' => array(__FUNCTION__, $_action, $_data_log),

+          'msg' => 'access_denied'

+        );

+        return false;

+      }

+      $active = intval($_data['active']);

+      $bcc_rcpts = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['bcc_rcpt']));

+      foreach ($bcc_rcpts as $i => &$rcpt) {

+        $rcpt = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $rcpt);

+          if (!empty($rcpt) && filter_var($rcpt, FILTER_VALIDATE_EMAIL) === false) {

+            $_SESSION['return'][] = array(

+              'type' => 'danger',

+              'log' => array(__FUNCTION__, $_action, $_data_log),

+              'msg' => array('goto_invalid', htmlspecialchars($rcpt))

+            );

+            unset($bcc_rcpts[$i]);

+            continue;

+          }

+      }

+      $bcc_rcpts = array_unique($bcc_rcpts);

+      $bcc_rcpts = array_filter($bcc_rcpts);

+      if (empty($bcc_rcpts)) {

+        $active = 0;

+        

+      }

+      try {

+        $redis->hSet('QW_BCC', $domain, json_encode(array('bcc_rcpts' => $bcc_rcpts, 'active' => $active)));

+      }

+      catch (RedisException $e) {

+        $_SESSION['return'][] = array(

+          'type' => 'danger',

+          'log' => array(__FUNCTION__, $_action, $_data_log),

+          'msg' => array('redis_error', $e)

+        );

+        return false;

+      }

+      $_SESSION['return'][] = array(

+        'type' => 'success',

+        'log' => array(__FUNCTION__, $_action, $_data_log),

+        'msg' => 'saved_settings'

+      );

+    break;

+    case 'get':

+      $domain = $_data;

+      if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {

+        $_SESSION['return'][] = array(

+          'type' => 'danger',

+          'log' => array(__FUNCTION__, $_action, $_data_log),

+          'msg' => 'access_denied'

+        );

+        return false;

+      }

+      try {

+        return json_decode($redis->hGet('QW_BCC', $domain), true);

+      }

+      catch (RedisException $e) {

+        $_SESSION['return'][] = array(

+          'type' => 'danger',

+          'log' => array(__FUNCTION__, $_action, $_data_log),

+          'msg' => array('redis_error', $e)

+        );

+        return false;

+      }

+    break;

+  }

+}