Commits

Zhang Huangbin committed 5c80c92

Postfix now works with PostgreSQL.

Comments (0)

Files changed (7)

iRedMail/conf/dovecot

 
 # Dovecot quota warning.
 export DOVECOT_QUOTA_WARNING_SCRIPT='/usr/local/bin/dovecot-quota-warning.sh'
-export DOVECOT_REALTIME_QUOTA_SQLTYPE='mysql'
 export DOVECOT_REALTIME_QUOTA_TABLE='used_quota'
-export DOVECOT_SHARE_FOLDER_SQLTYPE='mysql'
+export DOVECOT_SHARE_FOLDER_DB_TABLE='share_folder'
+if [ X"${BACKEND}" == X"OPENLDAP" -o X"${BACKEND}" == X"MYSQL" ]; then
+    export DOVECOT_SHARE_FOLDER_SQLTYPE='mysql'
+    export DOVECOT_REALTIME_QUOTA_SQLTYPE='mysql'
+elif [ X"${BACKEND}" == X"PGSQL" ]; then
+    export DOVECOT_SHARE_FOLDER_SQLTYPE='pgsql'
+    export DOVECOT_REALTIME_QUOTA_SQLTYPE='pgsql'
+fi
 
 if [ X"${DOVECOT_VERSION}" == X"1.1" -o X"${DOVECOT_VERSION}" == X"1.2" ]; then
     export DOVECOT_PROTOCOLS="pop3 pop3s imap imaps managesieve"

iRedMail/conf/postfix

 # virtual_maildir_limit_message.
 export MAILDIR_LIMIT_MESSAGE="Sorry, the user's maildir has overdrawn the disk quota, please notice the user and try again later."
 
-# LDAP/MYSQL lookup configuration files.
-# LDAP lookup.
-export POSTFIX_LOOKUP_DIR_LDAP="${POSTFIX_ROOTDIR}/ldap"
-export ldap_virtual_mailbox_domains_cf="${POSTFIX_LOOKUP_DIR_LDAP}/virtual_mailbox_domains.cf"
-export ldap_transport_maps_user_cf="${POSTFIX_LOOKUP_DIR_LDAP}/transport_maps_user.cf"
-export ldap_transport_maps_domain_cf="${POSTFIX_LOOKUP_DIR_LDAP}/transport_maps_domain.cf"
-export ldap_virtual_mailbox_maps_cf="${POSTFIX_LOOKUP_DIR_LDAP}/virtual_mailbox_maps.cf"
-export ldap_virtual_alias_maps_cf="${POSTFIX_LOOKUP_DIR_LDAP}/virtual_alias_maps.cf"
-export ldap_virtual_group_maps_cf="${POSTFIX_LOOKUP_DIR_LDAP}/virtual_group_maps.cf"
-export ldap_virtual_maillist_maps_cf="${POSTFIX_LOOKUP_DIR_LDAP}/virtual_maillist_maps.cf"
-export ldap_sender_login_maps_cf="${POSTFIX_LOOKUP_DIR_LDAP}/sender_login_maps.cf"
-export ldap_recipient_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR_LDAP}/recipient_bcc_maps_domain.cf"
-export ldap_recipient_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR_LDAP}/recipient_bcc_maps_user.cf"
-export ldap_sender_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR_LDAP}/sender_bcc_maps_domain.cf"
-export ldap_sender_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR_LDAP}/sender_bcc_maps_user.cf"
-export ldap_relay_domains_cf="${POSTFIX_LOOKUP_DIR_LDAP}/relay_domains.cf"
-export ldap_catch_all_maps_cf="${POSTFIX_LOOKUP_DIR_LDAP}/catchall_maps.cf"
-
-# MySQL lookup.
-export POSTFIX_LOOKUP_DIR_MYSQL="${POSTFIX_ROOTDIR}/mysql"
-export mysql_virtual_mailbox_domains_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/virtual_mailbox_domains.cf"
-export mysql_transport_maps_user_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/transport_maps_user.cf"
-export mysql_transport_maps_domain_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/transport_maps_domain.cf"
-export mysql_virtual_mailbox_maps_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/virtual_mailbox_maps.cf"
-export mysql_virtual_alias_maps_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/virtual_alias_maps.cf"
-export mysql_catchall_maps_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/catchall_maps.cf"
-export mysql_domain_alias_maps_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/domain_alias_maps.cf"
-export mysql_domain_alias_catchall_maps_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/domain_alias_catchall_maps.cf"
-export mysql_sender_login_maps_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/sender_login_maps.cf"
-export mysql_sender_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/sender_bcc_maps_domain.cf"
-export mysql_sender_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/sender_bcc_maps_user.cf"
-export mysql_recipient_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/recipient_bcc_maps_domain.cf"
-export mysql_recipient_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/recipient_bcc_maps_user.cf"
-export mysql_relay_domains_cf="${POSTFIX_LOOKUP_DIR_MYSQL}/relay_domains.cf"
-
+# LDAP/MYSQL/PGSQL lookup configuration files.
 if [ X"${BACKEND}" == X"OPENLDAP" ]; then
-    export POSTFIX_LOOKUP_DIR="${POSTFIX_LOOKUP_DIR_LDAP}"
+    export POSTFIX_LOOKUP_DIR="${POSTFIX_ROOTDIR}/ldap"
 elif [ X"${BACKEND}" == X"MYSQL" ]; then
-    export POSTFIX_LOOKUP_DIR="${POSTFIX_LOOKUP_DIR_MYSQL}"
+    export POSTFIX_LOOKUP_DIR="${POSTFIX_ROOTDIR}/mysql"
+elif [ X"${BACKEND}" == X"PGSQL" ]; then
+    export POSTFIX_LOOKUP_DIR="${POSTFIX_ROOTDIR}/pgsql"
 else
     export POSTFIX_LOOKUP_DIR="${POSTFIX_ROOTDIR}/lookups"
 fi
+
+export ldap_virtual_mailbox_domains_cf="${POSTFIX_LOOKUP_DIR}/virtual_mailbox_domains.cf"
+export ldap_transport_maps_user_cf="${POSTFIX_LOOKUP_DIR}/transport_maps_user.cf"
+export ldap_transport_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/transport_maps_domain.cf"
+export ldap_virtual_mailbox_maps_cf="${POSTFIX_LOOKUP_DIR}/virtual_mailbox_maps.cf"
+export ldap_virtual_alias_maps_cf="${POSTFIX_LOOKUP_DIR}/virtual_alias_maps.cf"
+export ldap_virtual_group_maps_cf="${POSTFIX_LOOKUP_DIR}/virtual_group_maps.cf"
+export ldap_virtual_maillist_maps_cf="${POSTFIX_LOOKUP_DIR}/virtual_maillist_maps.cf"
+export ldap_sender_login_maps_cf="${POSTFIX_LOOKUP_DIR}/sender_login_maps.cf"
+export ldap_recipient_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/recipient_bcc_maps_domain.cf"
+export ldap_recipient_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR}/recipient_bcc_maps_user.cf"
+export ldap_sender_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/sender_bcc_maps_domain.cf"
+export ldap_sender_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR}/sender_bcc_maps_user.cf"
+export ldap_relay_domains_cf="${POSTFIX_LOOKUP_DIR}/relay_domains.cf"
+export ldap_catch_all_maps_cf="${POSTFIX_LOOKUP_DIR}/catchall_maps.cf"
+
+# MySQL lookup.
+export mysql_virtual_mailbox_domains_cf="${POSTFIX_LOOKUP_DIR}/virtual_mailbox_domains.cf"
+export mysql_transport_maps_user_cf="${POSTFIX_LOOKUP_DIR}/transport_maps_user.cf"
+export mysql_transport_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/transport_maps_domain.cf"
+export mysql_virtual_mailbox_maps_cf="${POSTFIX_LOOKUP_DIR}/virtual_mailbox_maps.cf"
+export mysql_virtual_alias_maps_cf="${POSTFIX_LOOKUP_DIR}/virtual_alias_maps.cf"
+export mysql_catchall_maps_cf="${POSTFIX_LOOKUP_DIR}/catchall_maps.cf"
+export mysql_domain_alias_maps_cf="${POSTFIX_LOOKUP_DIR}/domain_alias_maps.cf"
+export mysql_domain_alias_catchall_maps_cf="${POSTFIX_LOOKUP_DIR}/domain_alias_catchall_maps.cf"
+export mysql_sender_login_maps_cf="${POSTFIX_LOOKUP_DIR}/sender_login_maps.cf"
+export mysql_sender_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/sender_bcc_maps_domain.cf"
+export mysql_sender_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR}/sender_bcc_maps_user.cf"
+export mysql_recipient_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/recipient_bcc_maps_domain.cf"
+export mysql_recipient_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR}/recipient_bcc_maps_user.cf"
+export mysql_relay_domains_cf="${POSTFIX_LOOKUP_DIR}/relay_domains.cf"
+
+# PGSQL lookup.
+export pgsql_virtual_mailbox_domains_cf="${POSTFIX_LOOKUP_DIR}/virtual_mailbox_domains.cf"
+export pgsql_transport_maps_user_cf="${POSTFIX_LOOKUP_DIR}/transport_maps_user.cf"
+export pgsql_transport_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/transport_maps_domain.cf"
+export pgsql_virtual_mailbox_maps_cf="${POSTFIX_LOOKUP_DIR}/virtual_mailbox_maps.cf"
+export pgsql_virtual_alias_maps_cf="${POSTFIX_LOOKUP_DIR}/virtual_alias_maps.cf"
+export pgsql_catchall_maps_cf="${POSTFIX_LOOKUP_DIR}/catchall_maps.cf"
+export pgsql_domain_alias_maps_cf="${POSTFIX_LOOKUP_DIR}/domain_alias_maps.cf"
+export pgsql_domain_alias_catchall_maps_cf="${POSTFIX_LOOKUP_DIR}/domain_alias_catchall_maps.cf"
+export pgsql_sender_login_maps_cf="${POSTFIX_LOOKUP_DIR}/sender_login_maps.cf"
+export pgsql_sender_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/sender_bcc_maps_domain.cf"
+export pgsql_sender_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR}/sender_bcc_maps_user.cf"
+export pgsql_recipient_bcc_maps_domain_cf="${POSTFIX_LOOKUP_DIR}/recipient_bcc_maps_domain.cf"
+export pgsql_recipient_bcc_maps_user_cf="${POSTFIX_LOOKUP_DIR}/recipient_bcc_maps_user.cf"
+export pgsql_relay_domains_cf="${POSTFIX_LOOKUP_DIR}/relay_domains.cf"
+

iRedMail/functions/dovecot1.sh

 
         if [ X"${BACKEND}" == X"OPENLDAP" ]; then
             share_folder_db_name="${IREDADMIN_DB_NAME}"
-            share_folder_db_table="share_folder"
             share_folder_db_user="${IREDADMIN_DB_USER}"
             share_folder_db_passwd="${IREDADMIN_DB_PASSWD}"
         else
             share_folder_db_name="${VMAIL_DB}"
-            share_folder_db_table="share_folder"
             share_folder_db_user="${VMAIL_DB_ADMIN_USER}"
             share_folder_db_passwd="${VMAIL_DB_ADMIN_PASSWD}"
         fi
 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 = share_folder
+    table = ${DOVECOT_SHARE_FOLDER_DB_TABLE}
     value_field = dummy
 
     fields {

iRedMail/functions/dovecot2.sh

         realtime_quota_db_name="${IREDADMIN_DB_NAME}"
         realtime_quota_db_user="${IREDADMIN_DB_USER}"
         realtime_quota_db_passwd="${IREDADMIN_DB_PASSWD}"
-    else
+    elif [ X"${BACKEND}" == X"MYSQL" ]; then
         realtime_quota_db_name="${VMAIL_DB}"
         realtime_quota_db_user="${VMAIL_DB_ADMIN_USER}"
         realtime_quota_db_passwd="${VMAIL_DB_ADMIN_PASSWD}"
+    elif [ X"${BACKEND}" == X"PGSQL" ]; then
+        realtime_quota_db_name="${VMAIL_DB}"
+        realtime_quota_db_user="${VMAIL_DB_BIND_USER}"
+        realtime_quota_db_passwd="${VMAIL_DB_BIND_PASSWD}"
     fi
 
     cat > ${DOVECOT_REALTIME_QUOTA_CONF} <<EOF
 
         if [ X"${BACKEND}" == X"OPENLDAP" ]; then
             share_folder_db_name="${IREDADMIN_DB_NAME}"
-            share_folder_db_table="share_folder"
             share_folder_db_user="${IREDADMIN_DB_USER}"
             share_folder_db_passwd="${IREDADMIN_DB_PASSWD}"
-        else
+        elif [ X"${BACKEND}" == X"MYSQL" ]; then
             share_folder_db_name="${VMAIL_DB}"
-            share_folder_db_table="share_folder"
+            share_folder_db_user="${VMAIL_DB_ADMIN_USER}"
+            share_folder_db_passwd="${VMAIL_DB_ADMIN_PASSWD}"
+        elif [ X"${BACKEND}" == X"PGSQL" ]; then
+            share_folder_db_name="${VMAIL_DB}"
             share_folder_db_user="${VMAIL_DB_ADMIN_USER}"
             share_folder_db_passwd="${VMAIL_DB_ADMIN_PASSWD}"
         fi
 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 = share_folder
+    table = ${DOVECOT_SHARE_FOLDER_DB_TABLE}
     value_field = dummy
 
     fields {

iRedMail/functions/packages.sh

     fi
     #### End Awstats ####
 
-    ################
-    # MySQL server.
-    #
-    # Note: mysql server is always required, used to store extra data,
-    #       such as policyd, roundcube webmail data.
-    if [ X"${DISTRO}" == X"RHEL" ]; then
-        ALL_PKGS="${ALL_PKGS} mysql-server${PKG_ARCH} mysql${PKG_ARCH}"
-        ENABLED_SERVICES="${ENABLED_SERVICES} mysqld"
-    elif [ X"${DISTRO}" == X"SUSE" ]; then
-        ALL_PKGS="${ALL_PKGS} mysql-community-server mysql-community-server-client"
-        ENABLED_SERVICES="${ENABLED_SERVICES} mysql"
-    elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
-        ALL_PKGS="${ALL_PKGS} mysql-server mysql-client"
-        ENABLED_SERVICES="${ENABLED_SERVICES} mysql"
-    else
-        :
-    fi
-    #### End MySQL server ####
-    
     #################################################
-    # Backend: OpenLDAP or MySQL, and extra packages.
+    # Backend: OpenLDAP, MySQL, PGSQL and extra packages.
     #
     if [ X"${BACKEND}" == X"OPENLDAP" ]; then
         # OpenLDAP server & client.
             ALL_PKGS="${ALL_PKGS} openldap${PKG_ARCH} openldap-clients${PKG_ARCH} openldap-servers${PKG_ARCH}"
             ENABLED_SERVICES="${ENABLED_SERVICES} ${LDAP_RC_SCRIPT_NAME}"
 
+            # MySQL server and client.
+            ALL_PKGS="${ALL_PKGS} mysql-server${PKG_ARCH} mysql${PKG_ARCH}"
+            ENABLED_SERVICES="${ENABLED_SERVICES} mysqld"
+
         elif [ X"${DISTRO}" == X"SUSE" ]; then
             ALL_PKGS="${ALL_PKGS} openldap2 openldap2-client"
             ENABLED_SERVICES="${ENABLED_SERVICES} ldap"
 
+            # MySQL server and client.
+            ALL_PKGS="${ALL_PKGS} mysql-community-server mysql-community-server-client"
+            ENABLED_SERVICES="${ENABLED_SERVICES} mysql"
         elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
             ALL_PKGS="${ALL_PKGS} postfix-ldap slapd ldap-utils libnet-ldap-perl"
             ENABLED_SERVICES="${ENABLED_SERVICES} slapd"
+
+            # MySQL server and client.
+            ALL_PKGS="${ALL_PKGS} mysql-server mysql-client"
+            ENABLED_SERVICES="${ENABLED_SERVICES} mysql"
         fi
     elif [ X"${BACKEND}" == X"MYSQL" ]; then
         # MySQL server & client.
         if [ X"${DISTRO}" == X"RHEL" ]; then
+            # MySQL server and client.
+            ALL_PKGS="${ALL_PKGS} mysql-server${PKG_ARCH} mysql${PKG_ARCH}"
+            ENABLED_SERVICES="${ENABLED_SERVICES} mysqld"
+
             # For Awstats.
             [ X"${USE_AWSTATS}" == X"YES" ] && ALL_PKGS="${ALL_PKGS} mod_auth_mysql${PKG_ARCH}"
 
         elif [ X"${DISTRO}" == X"SUSE" ]; then
+            # MySQL server and client.
+            ALL_PKGS="${ALL_PKGS} mysql-community-server mysql-community-server-client"
+            ENABLED_SERVICES="${ENABLED_SERVICES} mysql"
+
             [ X"${USE_AWSTATS}" == X"YES" ] && ALL_PKGS="${ALL_PKGS} postfix-mysql apache2-mod_auth_mysql"
 
         elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
+            # MySQL server and client.
+            ALL_PKGS="${ALL_PKGS} mysql-server mysql-client"
+            ENABLED_SERVICES="${ENABLED_SERVICES} mysql"
+
+            # Postfix module
             ALL_PKGS="${ALL_PKGS} postfix-mysql"
 
             # For Awstats.
             [ X"${USE_AWSTATS}" == X"YES" ] && ALL_PKGS="${ALL_PKGS} libapache2-mod-auth-mysql"
         fi
     elif [ X"${BACKEND}" == X"PGSQL" ]; then
-        # MySQL server & client.
+        export USE_IREDAPD='NO'
+
+        # PGSQL server & client.
         if [ X"${DISTRO}" == X"RHEL" ]; then
             ALL_PKGS="${ALL_PKGS} postgresql-server"
+            ENABLED_SERVICES="${ENABLED_SERVICES} postgresql"
 
         elif [ X"${DISTRO}" == X"SUSE" ]; then
             ALL_PKGS="${ALL_PKGS} postgresql-server"
+            ENABLED_SERVICES="${ENABLED_SERVICES} postgresql"
 
         elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
             # postgresql-contrib provides extension 'dblink' used in Roundcube password plugin.
             ALL_PKGS="${ALL_PKGS} postgresql postgresql-client postgresql-contrib"
+            ENABLED_SERVICES="${ENABLED_SERVICES} postgresql"
+
+            # Postfix module
+            ALL_PKGS="${ALL_PKGS} postfix-pgsql"
         fi
     else
         :

iRedMail/functions/postfix.sh

     postconf -e virtual_gid_maps="static:${VMAIL_USER_GID}"
     postconf -e virtual_mailbox_base="${STORAGE_BASE_DIR}"
 
+    # Reject unlisted sender
+    postconf -e smtpd_reject_unlisted_sender='yes'
+
     # Simple backscatter block method.
     #postconf -e header_checks="pcre:${POSTFIX_FILE_HEADER_CHECKS}"
     cat >> ${POSTFIX_FILE_HEADER_CHECKS} <<EOF
     echo 'export status_postfix_config_basic="DONE"' >> ${STATUS_FILE}
 }
 
-postfix_config_ldap()
+postfix_config_vhost_ldap()
 {
     ECHO_DEBUG "Configure Postfix for LDAP lookup."
 
     #postconf -e relay_recipient_maps="proxy:ldap:${ldap_virtual_mailbox_maps_cf}"
 
     postconf -e smtpd_sender_login_maps="proxy:ldap:${ldap_sender_login_maps_cf}"
-    postconf -e smtpd_reject_unlisted_sender='yes'
 
     cat > ${ldap_virtual_mailbox_domains_cf} <<EOF
 ${CONF_MSG}
 EOF
     done
 
-    echo 'export status_postfix_config_ldap="DONE"' >> ${STATUS_FILE}
+    echo 'export status_postfix_config_vhost_ldap="DONE"' >> ${STATUS_FILE}
 }
 
-postfix_config_mysql()
+postfix_config_vhost_mysql()
 {
     ECHO_DEBUG "Configure Postfix for MySQL lookup."
 
     #postconf -e relay_recipient_maps="proxy:mysql:${mysql_virtual_mailbox_maps_cf}"
 
     postconf -e smtpd_sender_login_maps="proxy:mysql:${mysql_sender_login_maps_cf}"
-    postconf -e smtpd_reject_unlisted_sender='yes'
 
     # Per-domain transport maps.
     cat > ${mysql_transport_maps_domain_cf} <<EOF
 EOF
     done
 
-    echo 'export status_postfix_config_mysql="DONE"' >> ${STATUS_FILE}
+    echo 'export status_postfix_config_vhost_mysql="DONE"' >> ${STATUS_FILE}
+}
+
+postfix_config_vhost_pgsql()
+{
+    ECHO_DEBUG "Configure Postfix for PostgreSQL lookup."
+
+    postconf -e transport_maps="proxy:pgsql:${pgsql_transport_maps_user_cf}, proxy:pgsql:${pgsql_transport_maps_domain_cf}"
+    postconf -e virtual_mailbox_domains="proxy:pgsql:${pgsql_virtual_mailbox_domains_cf}"
+    postconf -e virtual_mailbox_maps="proxy:pgsql:${pgsql_virtual_mailbox_maps_cf}"
+    postconf -e virtual_alias_maps="proxy:pgsql:${pgsql_virtual_alias_maps_cf}, proxy:pgsql:${pgsql_domain_alias_maps_cf}, proxy:pgsql:${pgsql_catchall_maps_cf}, proxy:pgsql:${pgsql_domain_alias_catchall_maps_cf}"
+    postconf -e sender_bcc_maps="proxy:pgsql:${pgsql_sender_bcc_maps_domain_cf}, proxy:pgsql:${pgsql_sender_bcc_maps_user_cf}"
+    postconf -e recipient_bcc_maps="proxy:pgsql:${pgsql_recipient_bcc_maps_domain_cf}, proxy:pgsql:${pgsql_recipient_bcc_maps_user_cf}"
+    postconf -e relay_domains="\$mydestination, proxy:pgsql:${pgsql_relay_domains_cf}"
+    #postconf -e relay_recipient_maps="proxy:pgsql:${pgsql_virtual_mailbox_maps_cf}"
+
+    postconf -e smtpd_sender_login_maps="proxy:pgsql:${pgsql_sender_login_maps_cf}"
+
+    # Per-domain transport maps.
+    cat > ${pgsql_transport_maps_domain_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT transport FROM domain WHERE domain='%s' AND active=1
+EOF
+
+    # Per-user transport maps.
+    cat > ${pgsql_transport_maps_user_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT mailbox.transport FROM mailbox,domain WHERE mailbox.username='%s' AND mailbox.domain='%d' AND mailbox.domain=domain.domain AND mailbox.transport<>'' AND mailbox.active=1 AND mailbox.enabledeliver=1 AND domain.backupmx=0 AND domain.active=1
+EOF
+
+    cat > ${pgsql_virtual_mailbox_domains_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT domain FROM domain WHERE domain='%s' AND backupmx=0 AND active=1 UNION SELECT alias_domain.alias_domain FROM alias_domain,domain WHERE alias_domain.alias_domain='%s' AND alias_domain.active=1 AND alias_domain.target_domain=domain.domain AND domain.active=1 AND domain.backupmx=0
+EOF
+
+    cat > ${pgsql_relay_domains_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT domain FROM domain WHERE domain='%s' AND backupmx=1 AND active=1
+EOF
+
+    cat > ${pgsql_virtual_mailbox_maps_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT CONCAT(mailbox.storagenode, '/', mailbox.maildir) FROM mailbox,domain WHERE mailbox.username='%s' AND mailbox.active=1 AND mailbox.enabledeliver=1 AND domain.domain = mailbox.domain AND domain.active=1
+EOF
+
+    cat > ${pgsql_virtual_alias_maps_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT alias.goto FROM alias,domain WHERE alias.address='%s' AND alias.domain='%d' AND alias.domain=domain.domain AND alias.active=1 AND domain.backupmx=0 AND domain.active=1
+EOF
+
+    cat > ${pgsql_domain_alias_maps_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT alias.goto FROM alias,alias_domain,domain WHERE alias_domain.alias_domain='%d' AND alias.address=CONCAT('%u', '@', alias_domain.target_domain) AND alias_domain.target_domain=domain.domain AND alias.active=1 AND alias_domain.active=1 AND domain.backupmx=0
+EOF
+
+    cat > ${pgsql_catchall_maps_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT alias.goto FROM alias,domain WHERE alias.address='%d' AND alias.address=domain.domain AND alias.active=1 AND domain.active=1 AND domain.backupmx=0
+EOF
+
+    cat > ${pgsql_domain_alias_catchall_maps_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT alias.goto FROM alias,alias_domain,domain WHERE alias_domain.alias_domain='%d' AND alias.address=alias_domain.target_domain AND alias_domain.target_domain=domain.domain AND alias.active=1 AND alias_domain.active=1
+EOF
+
+    cat > ${pgsql_sender_login_maps_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT mailbox.username FROM mailbox,domain WHERE mailbox.username='%s' AND mailbox.domain='%d' AND mailbox.domain=domain.domain AND mailbox.enablesmtp=1 AND mailbox.active=1 AND domain.backupmx=0 AND domain.active=1
+EOF
+
+    cat > ${pgsql_sender_bcc_maps_domain_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT bcc_address FROM sender_bcc_domain WHERE domain='%d' AND active=1
+EOF
+
+    cat > ${pgsql_sender_bcc_maps_user_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT sender_bcc_user.bcc_address FROM sender_bcc_user,domain WHERE sender_bcc_user.username='%s' AND sender_bcc_user.domain='%d' AND sender_bcc_user.domain=domain.domain AND domain.backupmx=0 AND domain.active=1 AND sender_bcc_user.active=1
+EOF
+
+    cat > ${pgsql_recipient_bcc_maps_domain_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT bcc_address FROM recipient_bcc_domain WHERE domain='%d' AND active=1
+EOF
+
+    cat > ${pgsql_recipient_bcc_maps_user_cf} <<EOF
+${CONF_MSG}
+user        = ${VMAIL_DB_BIND_USER}
+password    = ${VMAIL_DB_BIND_PASSWD}
+hosts       = ${PGSQL_SERVER}
+port        = ${PGSQL_SERVER_PORT}
+dbname      = ${VMAIL_DB}
+query       = SELECT recipient_bcc_user.bcc_address FROM recipient_bcc_user,domain WHERE recipient_bcc_user.username='%s' AND recipient_bcc_user.domain='%d' AND recipient_bcc_user.domain=domain.domain AND domain.backupmx=0 AND domain.active=1 AND recipient_bcc_user.active=1
+EOF
+
+    ECHO_DEBUG "Set file permission: Owner/Group -> postfix/postfix, Mode -> 0640."
+    cat >> ${TIP_FILE} <<EOF
+Postfix (PostgreSQL):
+    * Configuration files:
+EOF
+    for i in ${pgsql_virtual_mailbox_domains_cf} \
+        ${pgsql_transport_maps_domain_cf} \
+        ${pgsql_transport_maps_user_cf} \
+        ${pgsql_virtual_mailbox_maps_cf} \
+        ${pgsql_virtual_alias_maps_cf} \
+        ${pgsql_domain_alias_maps_cf} \
+        ${pgsql_catchall_maps_cf} \
+        ${pgsql_domain_alias_catchall_maps_cf} \
+        ${pgsql_sender_login_maps_cf} \
+        ${pgsql_sender_bcc_maps_domain_cf} \
+        ${pgsql_sender_bcc_maps_user_cf} \
+        ${pgsql_recipient_bcc_maps_domain_cf} \
+        ${pgsql_recipient_bcc_maps_user_cf}
+    do
+        chown ${SYS_ROOT_USER}:${POSTFIX_DAEMON_GROUP} ${i}
+        chmod 0640 ${i}
+
+        cat >> ${TIP_FILE} <<EOF
+        - $i
+EOF
+    done
+
+    echo 'export status_postfix_config_vhost_pgsql="DONE"' >> ${STATUS_FILE}
 }
 
 # Starting config.
 postfix_config_virtual_host()
 {
     if [ X"${BACKEND}" == X"OPENLDAP" ]; then
-        check_status_before_run postfix_config_ldap
+        check_status_before_run postfix_config_vhost_ldap
     elif [ X"${BACKEND}" == X"MYSQL" ]; then
-        check_status_before_run postfix_config_mysql
-    else
-        :
+        check_status_before_run postfix_config_vhost_mysql
+    elif [ X"${BACKEND}" == X"PGSQL" ]; then
+        check_status_before_run postfix_config_vhost_pgsql
     fi
 
     echo 'export status_postfix_config_virtual_host="DONE"' >> ${STATUS_FILE}
     #
     # **** End HELO related ****
 
+    if [ X"${USE_IREDAPD}" == X"YES" ]; then
+        POSTCONF_IREDAPD="check_policy_service inet:${IREDAPD_LISTEN_ADDR}:${IREDAPD_LISTEN_PORT},"
+    else
+        POSTCONF_IREDAPD=''
+    fi
+
     if [ X"${USE_CLUEBRINGER}" == X"YES" ]; then
-        postconf -e smtpd_recipient_restrictions="reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unlisted_recipient, check_policy_service inet:${IREDAPD_LISTEN_ADDR}:${IREDAPD_LISTEN_PORT}, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, check_policy_service inet:${CLUEBRINGER_BINDHOST}:${CLUEBRINGER_BINDPORT}"
+        postconf -e smtpd_recipient_restrictions="reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unlisted_recipient, ${POSTCONF_IREDAPD} permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, check_policy_service inet:${CLUEBRINGER_BINDHOST}:${CLUEBRINGER_BINDPORT}"
         postconf -e smtpd_end_of_data_restrictions="check_policy_service inet:${CLUEBRINGER_BINDHOST}:${CLUEBRINGER_BINDPORT}"
     else
-        postconf -e smtpd_recipient_restrictions="reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unlisted_recipient, check_policy_service inet:${IREDAPD_LISTEN_ADDR}:${IREDAPD_LISTEN_PORT}, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, check_policy_service inet:${POLICYD_BINDHOST}:${POLICYD_BINDPORT}"
+        postconf -e smtpd_recipient_restrictions="reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unlisted_recipient, ${POSTCONF_IREDAPD}, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, check_policy_service inet:${POLICYD_BINDHOST}:${POLICYD_BINDPORT}"
     fi
 
     echo 'export status_postfix_config_sasl="DONE"' >> ${STATUS_FILE}

iRedMail/functions/postgresql.sh

 
 -- Set correct privilege for ROLE: vmail
 GRANT SELECT ON admin,alias,alias_domain,domain,domain_admins,mailbox,mailbox,recipient_bcc_domain,recipient_bcc_user,sender_bcc_domain,sender_bcc_user TO ${VMAIL_DB_BIND_USER};
-GRANT SELECT,UPDATE,INSERT,DELETE ON share_folder,used_quota TO ${VMAIL_DB_BIND_USER};
+GRANT SELECT,UPDATE,INSERT,DELETE ON used_quota TO ${VMAIL_DB_BIND_USER};
+-- GRANT SELECT,UPDATE,INSERT,DELETE ON share_folder TO ${VMAIL_DB_BIND_USER};
 
 -- Set correct privilege for ROLE: vmailadmin
-GRANT SELECT,UPDATE,INSERT ON admin,alias,alias_domain,domain,domain_admins,mailbox,mailbox,recipient_bcc_domain,recipient_bcc_user,sender_bcc_domain,sender_bcc_user,share_folder,used_quota TO ${VMAIL_DB_ADMIN_USER};
+GRANT SELECT,UPDATE,INSERT,DELETE ON admin,alias,alias_domain,domain,domain_admins,mailbox,mailbox,recipient_bcc_domain,recipient_bcc_user,sender_bcc_domain,sender_bcc_user,share_folder,used_quota TO ${VMAIL_DB_ADMIN_USER};
 
 -- Add first mail domain
 INSERT INTO domain (domain,transport,created) VALUES ('${FIRST_DOMAIN}', '${TRANSPORT}', NOW());
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.