git subrepo clone https://github.com/mailcow/mailcow-dockerized.git mailcow/src/mailcow-dockerized

subrepo: subdir:   "mailcow/src/mailcow-dockerized"
  merged:   "a832becb"
upstream: origin:   "https://github.com/mailcow/mailcow-dockerized.git"
  branch:   "master"
  commit:   "a832becb"
git-subrepo: version:  "0.4.3"
  origin:   "???"
  commit:   "???"
Change-Id: If5be2d621a211e164c9b6577adaa7884449f16b5
diff --git a/mailcow/src/mailcow-dockerized/data/web/inc/functions.presets.inc.php b/mailcow/src/mailcow-dockerized/data/web/inc/functions.presets.inc.php
new file mode 100644
index 0000000..17aaa3f
--- /dev/null
+++ b/mailcow/src/mailcow-dockerized/data/web/inc/functions.presets.inc.php
@@ -0,0 +1,38 @@
+<?php
+function presets($_action, $_kind) {
+  switch ($_action) {
+    case 'get':
+      if ($_SESSION['mailcow_cc_role'] != "admin" && $_SESSION['mailcow_cc_role'] != "domainadmin") {
+        return false;
+      }
+      $presets = array();
+      $kind = strtolower(trim($_kind));
+      $lang_base = 'admin';
+      $presets_path = __DIR__ . '/presets/' . $kind;
+      if (!in_array($kind, ['rspamd', 'sieve'], true)) {
+        return array();
+      }
+      if ($kind === 'sieve') {
+        $lang_base = 'mailbox';
+      }
+      foreach (glob($presets_path . '/*.yml') as $filename) {
+        $presets[] = getPresetFromFilePath($filename, $lang_base);
+      }
+      return $presets;
+    break;
+  }
+  return array();
+}
+function getPresetFromFilePath($filePath, $lang_base) {
+  global $lang;
+  $preset = Spyc::YAMLLoad($filePath);
+  $preset = ['name' => basename($filePath, '.yml')] + $preset;
+  /* get translated headlines */
+  if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) {
+    $langTextName = trim(substr($preset['headline'], 5));
+    if (isset($lang[$lang_base][$langTextName])) {
+      $preset['headline'] = $lang[$lang_base][$langTextName];
+    }
+  }
+  return $preset;
+}