Commits

Zhang Huangbin  committed b017797

Enable Dovecot LMTP service by default.

  • Participants
  • Parent commits b9ae7ee

Comments (0)

Files changed (9)

File extra/update/updateLDAPValues_086_to_087.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+# Author:   Zhang Huangbin <zhb _at_ iredmail.org>
+# Purpose:  Add enabledService=lmtp for all mail users.
+#           Required by LMTP service used in Dovecot-2.x.
+# Date:     2014-02-20
+
+import sys
+import ldap
+
+# Note:
+#   * bind_dn must have write privilege on LDAP server.
+uri = 'ldap://127.0.0.1:389'
+basedn = 'o=domains,dc=example,dc=com'
+bind_dn = 'cn=Manager,dc=example,dc=com'
+bind_pw = 'passwd'
+
+# Initialize LDAP connection.
+print >> sys.stderr, "* Connecting to LDAP server: %s" % uri
+conn = ldap.initialize(uri=uri, trace_level=0,)
+conn.bind_s(bind_dn, bind_pw)
+
+# Get all mail users.
+print >> sys.stderr, "* Get all mail accounts..."
+allUsers = conn.search_s(basedn,
+                         ldap.SCOPE_SUBTREE,
+                         "(objectClass=mailUser)",
+                         ['mail', 'enabledService'])
+
+total = len(allUsers)
+print >> sys.stderr, "* Total %d user(s)." % (total)
+
+# Values of 'enabledService' which need to be added.
+services = ['lmtp']
+
+# Counter.
+count = 1
+
+for user in allUsers:
+    (dn, entry) = user
+    mail = entry['mail'][0]
+    if not 'enabledService' in entry:
+        continue
+
+    enabledService = entry['enabledService']
+    # Get missing values.
+    values = [str(s).lower() for s in services if s not in enabledService]
+
+    mod_attrs = []
+
+    # Add missing values of 'enabledService'.
+    if len(values) > 0:
+        mod_attrs += [(ldap.MOD_ADD, 'enabledService', values)]
+
+    # Update.
+    if len(mod_attrs) > 0:
+        print >> sys.stderr, "* (%d of %d) Updating user: %s" % (count, total, mail)
+        conn.modify_s(dn, mod_attrs)
+    else:
+        print >> sys.stderr, "* (%d of %d) [SKIP] No update required: %s" % (count, total, mail)
+
+    count += 1
+
+# Unbind connection.
+print >> sys.stderr, "* Unbind LDAP server."
+conn.unbind()
+
+print >> sys.stderr, "* Update completed."

File iRedMail/ChangeLog

 iRedMail-0.9.0:
+    * Enable LMTP service in Dovecot by default.
+      To use LMTP instead of Dovecot LDA as per-domain or per-user local
+      deliver agent in Postfix, you need to use one of below:
+        - LMTP socket: lmtp:unix:private/dovecot-lmtp
+        - LMTP inet listener: lmtp:inet:127.0.0.1:24
     * New columns for MySQL and PostgreSQL backends:
+        + mailbox.enablelmtp: used by Dovecot LMTP server.
         + mailbox.settings: used to store per-user settings, used in
           iRedAdmin-Pro.
         + admin.settings: used to store per-user settings, used in

File iRedMail/conf/dovecot

 
 # Log & logrotate files.
 export DOVECOT_LOG_FILE='/var/log/dovecot.log'
-export SIEVE_LOG_FILE='/var/log/sieve.log'
+export DOVECOT_SIEVE_LOG_FILE='/var/log/dovecot-sieve.log'
+export DOVECOT_LMTP_LOG_FILE='/var/log/dovecot-lmtp.log'
 export DOVECOT_LOGROTATE_FILE="${LOGROTATE_DIR}/dovecot"
 export SIEVE_LOGROTATE_FILE="${LOGROTATE_DIR}/sieve"
 
     export DOVECOT_REALTIME_QUOTA_SQLTYPE='pgsql'
 fi
 
-export DOVECOT_PROTOCOLS="pop3 imap sieve"
+export DOVECOT_PROTOCOLS="pop3 imap sieve lmtp"

File iRedMail/functions/amavisd.sh

   virus_admin_maps => ["root\@\$mydomain"],
   spam_admin_maps  => ["root\@\$mydomain"],
   warnbadhsender   => 0,
+  warnbannedsender   => 0,
   warnvirussender  => 1,
   warnspamsender   => 1,
   # forward to a smtpd service providing DKIM signing service
     virus_admin_maps => ["root\@\$mydomain"],
     spam_admin_maps  => ["root\@\$mydomain"],
 
-    # Notify spam/virus/banned/bad header sender
-    warnspamsender      => 0,
-    warnvirussender     => 0,
-    warnbannedsender    => 0,
-    warnbadhsender      => 0,
-
     # forward to a smtpd service providing DKIM signing service
     #forward_method => 'smtp:[${AMAVISD_SERVER}]:10027',
 

File iRedMail/functions/dovecot.sh

 
     # Sieve.
     perl -pi -e 's#PH_SIEVE_DIR#$ENV{SIEVE_DIR}#' ${DOVECOT_CONF}
+    perl -pi -e 's#PH_DOVECOT_SIEVE_LOG_FILE#$ENV{DOVECOT_SIEVE_LOG_FILE}#' ${DOVECOT_CONF}
     perl -pi -e 's#PH_SIEVE_RULE_FILENAME#$ENV{SIEVE_RULE_FILENAME}#' ${DOVECOT_CONF}
     perl -pi -e 's#PH_GLOBAL_SIEVE_FILE#$ENV{DOVECOT_GLOBAL_SIEVE_FILE}#' ${DOVECOT_CONF}
 
+    # LMTP
+    perl -pi -e 's#PH_DOVECOT_LMTP_LOG_FILE#$ENV{DOVECOT_LMTP_LOG_FILE}#' ${DOVECOT_CONF}
+
     # SSL.
     perl -pi -e 's#PH_SSL_CERT#$ENV{SSL_CERT_FILE}#' ${DOVECOT_CONF}
     perl -pi -e 's#PH_SSL_KEY#$ENV{SSL_KEY_FILE}#' ${DOVECOT_CONF}
 
+    perl -pi -e 's#PH_POSTFIX_CHROOT_DIR#$ENV{POSTFIX_CHROOT_DIR}#' ${DOVECOT_CONF}
 
     # Generate dovecot quota warning script.
     mkdir -p $(dirname ${DOVECOT_QUOTA_WARNING_SCRIPT}) 2>/dev/null
     chown ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} ${DOVECOT_GLOBAL_SIEVE_FILE}.sample
     chmod 0500 ${DOVECOT_GLOBAL_SIEVE_FILE}.sample
 
-    ECHO_DEBUG "Create dovecot log file: ${DOVECOT_LOG_FILE}, ${SIEVE_LOG_FILE}."
-    touch ${DOVECOT_LOG_FILE} ${SIEVE_LOG_FILE}
-    chown ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} ${DOVECOT_LOG_FILE} ${SIEVE_LOG_FILE}
-    chmod 0600 ${DOVECOT_LOG_FILE}
-
-    # Sieve log file must be world-writable.
-    chmod 0666 ${SIEVE_LOG_FILE}
+    for f in ${DOVECOT_LOG_FILE} ${DOVECOT_SIEVE_LOG_FILE} ${DOVECOT_LMTP_LOG_FILE}; do
+        ECHO_DEBUG "Create dovecot log file: ${f}."
+        touch ${f}
+        chown ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} ${f}
+        chmod 0600 ${f}
+    done
 
     ECHO_DEBUG "Enable dovecot SASL support in postfix: ${POSTFIX_FILE_MAIN_CF}."
     postconf -e mailbox_command="${DOVECOT_DELIVER}"
     if [ X"${KERNEL_NAME}" == X'LINUX' ]; then
         cat > ${DOVECOT_LOGROTATE_FILE} <<EOF
 ${CONF_MSG}
-${DOVECOT_LOG_FILE} {
+${DOVECOT_LOG_FILE}
+${DOVECOT_SIEVE_LOG_FILE}
+${DOVECOT_LMTP_LOG_FILE} {
     compress
     weekly
     rotate 10
     endscript
 }
 EOF
-
-    cat > ${SIEVE_LOGROTATE_FILE} <<EOF
-${CONF_MSG}
-${SIEVE_LOG_FILE} {
-    compress
-    weekly
-    rotate 10
-    create 0666 ${VMAIL_USER_NAME} ${VMAIL_GROUP_NAME}
-    missingok
-    postrotate
-        doveadm log reopen
-    endscript
-}
-EOF
     elif [ X"${KERNEL_NAME}" == X'FREEBSD' ]; then
         if ! grep "${DOVECOT_LOG_FILE}" /etc/newsyslog.conf &>/dev/null; then
             # Define command used to reopen log service after rotated
 EOF
         fi
 
-        if ! grep "${SIEVE_LOG_FILE}" /etc/newsyslog.conf &>/dev/null; then
+        if ! grep "${DOVECOT_SIEVE_LOG_FILE}" /etc/newsyslog.conf &>/dev/null; then
             # Define command used to reopen log service after rotated
             cat >> /etc/newsyslog.conf <<EOF
-${SIEVE_LOG_FILE}    ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME}   600  7     *    24    Z    ${DOVECOT_MASTER_PID}
+${DOVECOT_SIEVE_LOG_FILE}    ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME}   600  7     *    24    Z    ${DOVECOT_MASTER_PID}
 EOF
         fi
 
+        if ! grep "${DOVECOT_LMTP_LOG_FILE}" /etc/newsyslog.conf &>/dev/null; then
+            # Define command used to reopen log service after rotated
+            cat >> /etc/newsyslog.conf <<EOF
+${DOVECOT_LMTP_LOG_FILE}    ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME}   600  7     *    24    Z    ${DOVECOT_MASTER_PID}
+EOF
+        fi
     elif [ X"${KERNEL_NAME}" == X'OPENBSD' ]; then
         if ! grep "${DOVECOT_LOG_FILE}" /etc/newsyslog.conf &>/dev/null; then
             # Define command used to reopen log service after rotated
 EOF
         fi
 
-        if ! grep "${SIEVE_LOG_FILE}" /etc/newsyslog.conf &>/dev/null; then
+        if ! grep "${DOVECOT_SIEVE_LOG_FILE}" /etc/newsyslog.conf &>/dev/null; then
             # Define command used to reopen log service after rotated
             cat >> /etc/newsyslog.conf <<EOF
-${SIEVE_LOG_FILE}    ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME}   600  7     *    24    Z "${DOVECOT_DOVEADM_BIN} log reopen"
+${DOVECOT_SIEVE_LOG_FILE}    ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME}   600  7     *    24    Z "${DOVECOT_DOVEADM_BIN} log reopen"
+EOF
+        fi
+
+        if ! grep "${DOVECOT_LMTP_LOG_FILE}" /etc/newsyslog.conf &>/dev/null; then
+            # Define command used to reopen log service after rotated
+            cat >> /etc/newsyslog.conf <<EOF
+${DOVECOT_LMTP_LOG_FILE}    ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME}   600  7     *    24    Z "${DOVECOT_DOVEADM_BIN} log reopen"
 EOF
         fi
     fi
     * RC script: ${DIR_RC_SCRIPTS}/${DOVECOT_RC_SCRIPT_NAME}
     * Log files:
         - ${DOVECOT_LOG_FILE}
-        - ${SIEVE_LOG_FILE}
+        - ${DOVECOT_SIEVE_LOG_FILE}
+        - ${DOVECOT_LMTP_LOG_FILE}
     * See also:
         - ${DOVECOT_GLOBAL_SIEVE_FILE}
         - Logrotate config file: ${DOVECOT_LOGROTATE_FILE}

File iRedMail/samples/dovecot/dovecot2.conf

 #default_process_limit = 100
 
 service auth {
-    unix_listener /var/spool/postfix/dovecot-auth {
+    unix_listener PH_POSTFIX_CHROOT_DIR/dovecot-auth {
         user = PH_DOVECOT_AUTH_USER
         group = PH_DOVECOT_AUTH_GROUP
         mode = 0666
     }
 }
 
+# LMTP server (Local Mail Transfer Protocol).
+# Reference: http://wiki2.dovecot.org/LMTP
+service lmtp {
+    user = PH_AUTH_MASTER_USER
+
+    # For higher volume sites, it may be desirable to increase the number of
+    # active listener processes. A range of 5 to 20 is probably good for most
+    # sites.
+    process_min_avail = 5
+
+    # Logging.
+    # Require 'info_log_path =' in 'protocol lmtp {}' block.
+    executable = lmtp -L
+
+    # Listening on socket file and TCP
+    unix_listener PH_POSTFIX_CHROOT_DIR/private/dovecot-lmtp {
+        user = PH_DOVECOT_AUTH_USER
+        group = PH_DOVECOT_AUTH_GROUP
+        mode = 0600
+    }
+
+    inet_listener lmtp {
+        #address = 192.168.0.24 127.0.0.1 ::1
+        port = 24
+    }
+}
+
 # Virtual mail accounts.
 userdb {
     args = PH_USERDB_ARGS
     # Reference: http://wiki2.dovecot.org/LDA
     mail_plugins = $mail_plugins sieve autocreate
     auth_socket_path = /var/run/dovecot/auth-master
-    log_path = /var/log/sieve.log
+    log_path = PH_DOVECOT_SIEVE_LOG_FILE
     lda_mailbox_autocreate = yes
     postmaster_address = root
 }
+
+protocol lmtp {
+    # Log file
+    info_log_path = PH_DOVECOT_LMTP_LOG_FILE
+
+    # Plugins
+    mail_plugins = quota sieve
+    postmaster_address = postmaster
+
+    lmtp_save_to_detail_mailbox = yes
+    recipient_delimiter = +
+}
+
 protocol imap {
     mail_plugins = $mail_plugins imap_quota autocreate
     imap_client_workarounds = tb-extra-mailbox-sep

File iRedMail/samples/dovecot/dovecot22.conf

 #default_process_limit = 100
 
 service auth {
-    unix_listener /var/spool/postfix/dovecot-auth {
+    unix_listener PH_POSTFIX_CHROOT_DIR/dovecot-auth {
         user = PH_DOVECOT_AUTH_USER
         group = PH_DOVECOT_AUTH_GROUP
         mode = 0666
     }
 }
 
+# LMTP server (Local Mail Transfer Protocol).
+# Reference: http://wiki2.dovecot.org/LMTP
+service lmtp {
+    user = PH_AUTH_MASTER_USER
+
+    # For higher volume sites, it may be desirable to increase the number of
+    # active listener processes. A range of 5 to 20 is probably good for most
+    # sites.
+    process_min_avail = 5
+
+    # Logging.
+    # Require 'info_log_path =' in 'protocol lmtp {}' block.
+    executable = lmtp -L
+
+    # Listening on socket file and TCP
+    unix_listener PH_POSTFIX_CHROOT_DIR/private/dovecot-lmtp {
+        user = PH_DOVECOT_AUTH_USER
+        group = PH_DOVECOT_AUTH_GROUP
+        mode = 0600
+    }
+
+    inet_listener lmtp {
+        #address = 192.168.0.24 127.0.0.1 ::1
+        port = 24
+    }
+}
+
 # Virtual mail accounts.
 userdb {
     args = PH_USERDB_ARGS
     # Reference: http://wiki2.dovecot.org/LDA
     mail_plugins = $mail_plugins sieve
     auth_socket_path = /var/run/dovecot/auth-master
-    log_path = /var/log/sieve.log
+    log_path = PH_DOVECOT_SIEVE_LOG_FILE
     lda_mailbox_autocreate = yes
     postmaster_address = root
 }
+
+protocol lmtp {
+    # Log file
+    info_log_path = PH_DOVECOT_LMTP_LOG_FILE
+
+    # Plugins
+    mail_plugins = quota sieve
+    postmaster_address = postmaster
+
+    lmtp_save_to_detail_mailbox = yes
+    recipient_delimiter = +
+}
+
 protocol imap {
     mail_plugins = $mail_plugins imap_quota
     imap_client_workarounds = tb-extra-mailbox-sep

File iRedMail/samples/iredmail.mysql

     INDEX (enablemanagesievesecured),
     INDEX (enablesieve),
     INDEX (enablesievesecured),
+    INDEX (enablelmtp),
     INDEX (enableinternal),
     INDEX (enabledoveadm),
     INDEX (`enablelib-storage`),

File iRedMail/samples/iredmail.pgsql

 CREATE INDEX idx_mailbox_enablemanagesievesecured ON mailbox (enablemanagesievesecured);
 CREATE INDEX idx_mailbox_enablesieve ON mailbox (enablesieve);
 CREATE INDEX idx_mailbox_enablesievesecured ON mailbox (enablesievesecured);
+CREATE INDEX idx_mailbox_enablelmtp ON mailbox (enablelmtp);
 CREATE INDEX idx_mailbox_enableinternal ON mailbox (enableinternal);
 CREATE INDEX idx_mailbox_enabledoveadm ON mailbox (enabledoveadm);
 CREATE INDEX idx_mailbox_enablelib_storage ON mailbox ("enablelib-storage");