Source

iredmail / iRedMail / functions / dovecot1.sh

Diff from to

File iRedMail/functions/dovecot1.sh

         backup_file ${DOVECOT_SHARE_FOLDER_CONF}
 
         if [ X"${BACKEND}" == X"OPENLDAP" ]; then
-            share_folder_db_name="${IREDADMIN_DB_NAME}"
-            share_folder_db_user="${IREDADMIN_DB_USER}"
-            share_folder_db_passwd="${IREDADMIN_DB_PASSWD}"
+            export share_folder_db_name="${IREDADMIN_DB_NAME}"
+            export share_folder_db_user="${IREDADMIN_DB_USER}"
+            export share_folder_db_passwd="${IREDADMIN_DB_PASSWD}"
         else
-            share_folder_db_name="${VMAIL_DB}"
-            share_folder_db_user="${VMAIL_DB_ADMIN_USER}"
-            share_folder_db_passwd="${VMAIL_DB_ADMIN_PASSWD}"
+            export share_folder_db_name="${VMAIL_DB}"
+            export share_folder_db_user="${VMAIL_DB_ADMIN_USER}"
+            export share_folder_db_passwd="${VMAIL_DB_ADMIN_PASSWD}"
         fi
 
         # Enable dict quota in dovecot.
 }
 EOF
 
-        # SQL lookup for share folder.
-        cat > ${DOVECOT_SHARE_FOLDER_CONF} <<EOF
-${CONF_MSG}
-connect = host=${MYSQL_SERVER} dbname=${share_folder_db_name} user=${share_folder_db_user} password=${share_folder_db_passwd}
-map {
-    pattern = shared/shared-boxes/user/\$to/\$from
-    table = ${DOVECOT_SHARE_FOLDER_DB_TABLE}
-    value_field = dummy
-
-    fields {
-        from_user = \$from
-        to_user = \$to
-    }
-}
-
-# To share mailbox to anyone, please uncomment 'acl_anyone = allow' in
-# dovecot.conf
-map {
-    pattern = shared/shared-boxes/anyone/\$from
-    table = ${DOVECOT_SHARE_FOLDER_ANYONE_DB_TABLE}
-    value_field = dummy
-    fields {
-        from_user = \$from
-    }
-}
-EOF
-
+        # IMAP share folder.
+        cp ${SAMPLE_DIR}/dovecot/dovecot-share-folder.conf ${DOVECOT_SHARE_FOLDER_CONF}
         chown ${DOVECOT_USER}:${DOVECOT_GROUP} ${DOVECOT_SHARE_FOLDER_CONF}
         chmod 0500 ${DOVECOT_SHARE_FOLDER_CONF}
 
+        # Replace place holders in sample config file
+        perl -pi -e 's#PH_SQL_SERVER#$ENV{SQL_SERVER}#' ${DOVECOT_SHARE_FOLDER_CONF}
+        perl -pi -e 's#PH_DOVECOT_SHARE_FOLDER_DB_NAME#$ENV{share_folder_db_name}#' ${DOVECOT_SHARE_FOLDER_CONF}
+        perl -pi -e 's#PH_DOVECOT_SHARE_FOLDER_DB_USER#$ENV{share_folder_db_user}#' ${DOVECOT_SHARE_FOLDER_CONF}
+        perl -pi -e 's#PH_DOVECOT_SHARE_FOLDER_DB_PASSWORD#$ENV{share_folder_db_passwd}#' ${DOVECOT_SHARE_FOLDER_CONF}
+        perl -pi -e 's#PH_DOVECOT_SHARE_FOLDER_DB_TABLE#$ENV{DOVECOT_SHARE_FOLDER_DB_TABLE}#' ${DOVECOT_SHARE_FOLDER_CONF}
+        perl -pi -e 's#PH_DOVECOT_SHARE_FOLDER_ANYONE_DB_TABLE#$ENV{DOVECOT_SHARE_FOLDER_ANYONE_DB_TABLE}#' ${DOVECOT_SHARE_FOLDER_CONF}
+
         # Create MySQL database ${IREDADMIN_DB_USER} and table 'share_folder'
         # which used to store realtime quota.
         if [ X"${BACKEND}" == X"OPENLDAP" -a X"${USE_IREDADMIN}" != X"YES" ]; then