Commits

Zhang Huangbin committed 210ac3b

Create maildir for first mail user. Comment:
We will deliver emails with sensitive info of iRedMail installation
to postmaster immediately after installation completed, but delivering
emails with dovecot-lda after installation completed doesn't work all the
time, so we choose to deliver emails by copying mail messages to mailbox
directly.
NOTE: 'Maildir/' is appended by Dovecot.

  • Participants
  • Parent commits 27cf0d5

Comments (0)

Files changed (5)

File iRedMail/functions/cleanup.sh

         enable_service_rh sshd
     fi
 
-    # Start Dovecot to deliver emails.
     ECHO_INFO "Mail sensitive administration info to ${FIRST_USER}@${FIRST_DOMAIN}."
-    if [ X"${BACKEND}" == X'OPENLDAP' ]; then
-        ${DIR_RC_SCRIPTS}/${OPENLDAP_RC_SCRIPT_NAME} restart &>/dev/null
-        ${DIR_RC_SCRIPTS}/${MYSQL_RC_SCRIPT_NAME} restart &>/dev/null
-    elif [ X"${BACKEND}" == X'MYSQL' ]; then
-        ${DIR_RC_SCRIPTS}/${MYSQL_RC_SCRIPT_NAME} restart &>/dev/null
-    elif [ X"${BACKEND}" == X'PGSQL' ]; then
-        ${DIR_RC_SCRIPTS}/${PGSQL_RC_SCRIPT_NAME} restart &>/dev/null
-    elif [ X"${BACKEND}" == X'LDAPD' ]; then
-        ${DIR_RC_SCRIPTS}/${LDAPD_RC_SCRIPT_NAME} stop &>/dev/null
-        ${DIR_RC_SCRIPTS}/${LDAPD_RC_SCRIPT_NAME} start &>/dev/null
-        ${DIR_RC_SCRIPTS}/${MYSQL_RC_SCRIPT_NAME} stop &>/dev/null
-        ${DIR_RC_SCRIPTS}/${MYSQL_RC_SCRIPT_NAME} start &>/dev/null
-    fi
+    FILE_IREDMAIL_INSTALLATION_DETAILS="${FIRST_USER_MAILDIR_INBOX}/details.eml"
+    FILE_IREDMAIL_LINKS="${FIRST_USER_MAILDIR_INBOX}/links.eml"
 
-    ${DIR_RC_SCRIPTS}/${DOVECOT_RC_SCRIPT_NAME} restart &>/dev/null
-    sleep 3
-
-    # Send tip file to the mail server admin and/or first mail user.
-    tip_recipient="${FIRST_USER}@${FIRST_DOMAIN}"
-
-    cat > /tmp/.tips.eml <<EOF
+    cat > ${FILE_IREDMAIL_INSTALLATION_DETAILS} <<EOF
 From: root@${HOSTNAME}
 To: ${tip_recipient}
 Subject: Details of this iRedMail installation
 
 EOF
 
-    cat ${TIP_FILE} >> /tmp/.tips.eml
-    ${DOVECOT_DELIVER} -c ${DOVECOT_CONF} -f root@${HOSTNAME} -d ${tip_recipient} < /tmp/.tips.eml
-    rm -f /tmp/.tips.eml &>/dev/null
+    cat ${TIP_FILE} >> ${FILE_IREDMAIL_INSTALLATION_DETAILS}
 
-    cat > /tmp/.links.eml <<EOF
+    cat > ${FILE_IREDMAIL_LINKS} <<EOF
 From: root@${HOSTNAME}
 To: ${tip_recipient}
 Subject: Useful resources for iRedMail administrator
 
 EOF
-    cat ${DOC_FILE} >> /tmp/.links.eml
-    ${DOVECOT_DELIVER} -c ${DOVECOT_CONF} -f root@${HOSTNAME} -d ${tip_recipient} < /tmp/.links.eml
-    rm -f /tmp/.links.eml &>/dev/null
+    cat ${DOC_FILE} >> ${FILE_IREDMAIL_LINKS}
+
+    chown -R ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} ${FILE_IREDMAIL_INSTALLATION_DETAILS} ${FILE_IREDMAIL_LINKS}
+    chmod -R 0700 ${FILE_IREDMAIL_INSTALLATION_DETAILS} ${FILE_IREDMAIL_LINKS}
 
     [ X"${DISTRO}" == X"RHEL" ] && check_status_before_run cleanup_disable_selinux
     [ X"${DISTRO}" != X'OPENBSD' ] && check_status_before_run cleanup_remove_sendmail

File iRedMail/functions/ldap_server.sh

 ${LDAP_ATTR_USER_RDN}: ${FIRST_USER}@${FIRST_DOMAIN}
 ${LDAP_ATTR_ACCOUNT_STATUS}: ${LDAP_STATUS_ACTIVE}
 ${LDAP_ATTR_USER_STORAGE_BASE_DIRECTORY}: ${STORAGE_BASE_DIR}
-mailMessageStore: ${STORAGE_NODE}/$( hash_domain ${FIRST_DOMAIN})/$( hash_maildir ${FIRST_USER} )
-homeDirectory: ${STORAGE_MAILBOX_DIR}/$( hash_domain ${FIRST_DOMAIN})/$( hash_maildir ${FIRST_USER} )
+mailMessageStore: ${STORAGE_NODE}/${FIRST_USER_MAILDIR_HASH_PART}
+homeDirectory: ${FIRST_USER_MAILDIR_FULL_PATH}
 ${LDAP_ATTR_USER_QUOTA}: 104857600
 ${LDAP_ATTR_USER_PASSWD}: $(gen_ldap_passwd "${FIRST_USER_PASSWD}")
 ${LDAP_ENABLED_SERVICE}: ${LDAP_SERVICE_MAIL}

File iRedMail/functions/mysql.sh

 INSERT INTO domain (domain,transport,created) VALUES ("${FIRST_DOMAIN}", "${TRANSPORT}", NOW());
 
 /* Add your first normal user. */
-INSERT INTO mailbox (username,password,name,maildir,quota,domain,isadmin,isglobaladmin,created) VALUES ("${FIRST_USER}@${FIRST_DOMAIN}","${FIRST_USER_PASSWD}","${FIRST_USER}","$( hash_domain ${FIRST_DOMAIN})/$( hash_maildir ${FIRST_USER} )",100, "${FIRST_DOMAIN}", 1, 1, NOW());
+INSERT INTO mailbox (username,password,name,maildir,quota,domain,isadmin,isglobaladmin,created) VALUES ("${FIRST_USER}@${FIRST_DOMAIN}","${FIRST_USER_PASSWD}","${FIRST_USER}","${FIRST_USER_MAILDIR_HASH_PART}",100, "${FIRST_DOMAIN}", 1, 1, NOW());
 INSERT INTO alias (address,goto,domain,created) VALUES ("${FIRST_USER}@${FIRST_DOMAIN}", "${FIRST_USER}@${FIRST_DOMAIN}", "${FIRST_DOMAIN}", NOW());
 
 /* Mark first mail user as global admin */

File iRedMail/functions/postgresql.sh

 INSERT INTO domain (domain,transport,created) VALUES ('${FIRST_DOMAIN}', '${TRANSPORT}', NOW());
 
 -- Add first mail user
-INSERT INTO mailbox (username,password,name,maildir,quota,domain,isadmin,isglobaladmin,created) VALUES ('${FIRST_USER}@${FIRST_DOMAIN}','${FIRST_USER_PASSWD}','${FIRST_USER}','$( hash_domain ${FIRST_DOMAIN})/$( hash_maildir ${FIRST_USER} )',100, '${FIRST_DOMAIN}', 1, 1, NOW());
+INSERT INTO mailbox (username,password,name,maildir,quota,domain,isadmin,isglobaladmin,created) VALUES ('${FIRST_USER}@${FIRST_DOMAIN}','${FIRST_USER_PASSWD}','${FIRST_USER}','${FIRST_USER_MAILDIR_HASH_PART}',100, '${FIRST_DOMAIN}', 1, 1, NOW());
 INSERT INTO alias (address,goto,domain,created) VALUES ('${FIRST_USER}@${FIRST_DOMAIN}', '${FIRST_USER}@${FIRST_DOMAIN}', '${FIRST_DOMAIN}', NOW());
 
 -- Mark first mail user as global admin

File iRedMail/functions/system_accounts.sh

     fi
     rm -f ${VMAIL_USER_HOME_DIR}/.* 2>/dev/null
 
-    # Set permission for exist home directory.
-    if [ -d ${VMAIL_USER_HOME_DIR} ]; then
-        chown -R ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} ${VMAIL_USER_HOME_DIR}
-        chmod -R 0700 ${VMAIL_USER_HOME_DIR}
-    fi
+    export FIRST_USER_MAILDIR_HASH_PART="$(hash_domain ${FIRST_DOMAIN})/$(hash_maildir ${FIRST_USER})"
+    export FIRST_USER_MAILDIR_FULL_PATH="${STORAGE_MAILBOX_DIR}/${FIRST_USER_MAILDIR_HASH_PART}"
+    # Create maildir.
+    # We will deliver emails with sensitive info of iRedMail installation
+    # to postmaster immediately after installation completed, but delivering
+    # emails with dovecot-lda after installation completed doesn't work all the
+    # time, so we choose to deliver emails by copying mail messages to mailbox
+    # directly.
+    # NOTE: 'Maildir/' is appended by Dovecot.
+    export FIRST_USER_MAILDIR_INBOX="${FIRST_USER_MAILDIR_FULL_PATH}/Maildir/new"
+    mkdir -p ${FIRST_USER_MAILDIR_INBOX} &>/dev/null
+
+    # Reset permission for home directory. Required by FIRST_USER_MAILDIR_FULL_PATH.
+    chown -R ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} ${VMAIL_USER_HOME_DIR}
+    chmod -R 0700 ${VMAIL_USER_HOME_DIR}
 
     ECHO_DEBUG "Create directory to store user sieve rule files: ${SIEVE_DIR}."
     mkdir -p ${SIEVE_DIR} && \