Dovecot Core

repository·main·Indexed 22 days ago

https://github.com/dovecot/core

A powerful and flexible IMAP/POP3/LMTP mail server designed for high performance, security, and scalability. This repository contains the core server implementation, including the anvil connection manager, authentication services, the Local Delivery Agent (dovecot-lda), and IMAP/LMTP server components.

Tokens
6.9K
Snippets
12
Records
52
Agent score
78%

What's inside dovecot-core

  1. Run Dovecot after installation

    main

    After installation, Dovecot's minimal configuration files are located in /usr/local/etc/dovecot/.

    To run the service:

    1. Review and modify the configuration files in /usr/local/etc/dovecot/ to suit your requirements.
    2. Execute the dovecot binary to start the service.
  2. Build and install Dovecot from source

    main

    To build and install Dovecot, use the standard autotools workflow. If you are building directly from a git repository, you must run ./autogen.sh before configuring. By default, Dovecot installs to /usr/local.

    If your dependencies (like OpenSSL) are in non-standard locations, use CPPFLAGS for include paths and LDFLAGS for library paths during the configuration step.

  3. Run the Dovecot dict service

    main
    The dict service is a Dovecot component that provides a dictionary interface for various backends (like SQL or CDB). It is managed by the Dovecot master service. When running as a standalone process, it initializes drivers, commands, and connections, and then enters a loop to accept client connections via the master service interface.
  4. Submission protocol client implementation details

    main

    The submission-login process implements the Dovecot submission protocol (typically on port 587). It acts as a proxy/client that manages SMTP connections to a backend.

    Key behaviors:

    • Capabilities: It supports standard SMTP capabilities including SIZE, ENHANCEDSTATUSCODES, AUTH, and XCLIENT. It also supports STARTTLS if TLS is enabled on the client connection.
    • XCLIENT Support: It handles XCLIENT commands to extract proxy information such as source/destination IP, ports, and TTL. It specifically supports a FORWARD parameter which is decoded from Base64.
    • Security: It enforces a limit on bad commands (CLIENT_MAX_BAD_COMMANDS = 10) before disconnecting the client. It also manages TLS initialization via STARTTLS.
    • Backend Capabilities: The backend capabilities can be configured via submission_backend_capabilities. If not explicitly set, it defaults to 8BITMIME (and SMTPUTF8 if mail_utf8_extensions is enabled). If BINARYMIME is enabled, CHUNKING is automatically enabled.
  5. Understand the submission_proxy_state enumeration

    main

    The submission_proxy_state enum tracks the current stage of the Submission protocol proxy lifecycle. It defines the sequence of states a client transitions through when proxying submission connections, starting from the initial banner through EHLO, TLS negotiation, XCLIENT handling, and finally authentication.

    Available states:

    • SUBMISSION_PROXY_BANNER: Initial connection banner.
    • SUBMISSION_PROXY_EHLO: Handling the EHLO command.
    • SUBMISSION_PROXY_STARTTLS: Handling STARTTLS negotiation.
    • SUBMISSION_PROXY_TLS_EHLO: Handling EHLO after TLS is established.
    • SUBMISSION_PROXY_XCLIENT: Handling XCLIENT commands.
    • SUBMISSION_PROXY_XCLIENT_EHLO: Handling EHLO after XCLIENT.
    • SUBMISSION_PROXY_AUTHENTICATE: Handling the authentication phase.
    enum submission_proxy_state {
    	SUBMISSION_PROXY_BANNER = 0,
    	SUBMISSION_PROXY_EHLO,
    	SUBMISSION_PROXY_STARTTLS,
    	SUBMISSION_PROXY_TLS_EHLO,
    	SUBMISSION_PROXY_XCLIENT,
    	SUBMISSION_PROXY_XCLIENT_EHLO,
    	SUBMISSION_PROXY_AUTHENTICATE,
    
    SUBMISSION_PROXY_STATE_COUNT
    };
  6. Run LMTP in standalone mode via STDIN/STDOUT

    main
    The LMTP server can be run in a standalone mode (bypassing the master process) by ensuring the MASTER_IS_PARENT_ENV environment variable is not set. In this mode, the server reads from STDIN_FILENO and writes to STDOUT_FILENO. This is typically used for testing or specialized local piping.
  7. How the Dovecot config process lifecycle works

    main

    The config process in Dovecot is managed by the master_service. It follows a specific lifecycle to ensure configuration is parsed correctly before the master service considers the process healthy.

    1. Initialization: The service is initialized via master_service_init with specific flags (e.g., MASTER_SERVICE_FLAG_DONT_SEND_STATS).
    2. Security & Environment: Access is restricted using restrict_access_by_env and coredumps are managed via restrict_access_allow_coredumps.
    3. Configuration Loading: Modules are loaded via config_parse_load_modules and settings are configured using settings_set_config_binary.
    4. Service Readiness: Crucially, master_service_init_finish is called only after the configuration file has been successfully parsed. This prevents the master service from entering a crash loop by attempting to restart a process that is failing due to invalid configuration.
    5. Execution: The process enters its main loop via master_service_run, accepting connections through a callback (e.g., client_connected) that handles connection creation via config_connection_create.
    6. Cleanup: Upon exit, connections are destroyed, and modules/parsers are deinitialized in a specific order to prevent unmapping event categories before they are used.
  8. How the POP3 server handles standalone vs master mode

    main

    The POP3 server can operate in two distinct modes based on the environment:

    1. Standalone Mode: Detected when the MASTER_IS_PARENT_ENV environment variable is not set. In this mode, the server reads input from STDIN and writes to STDOUT. It is intended for simple testing or specific local use cases. It is explicitly forbidden to start the POP3 binary from inetd if running as root in standalone mode; instead, pop3-login should be used.

    2. Master Mode: The standard operational mode where the POP3 process acts as a service managed by Dovecot's master process. It uses a login_server to handle authentication requests and a mail_storage_service to manage mail access. It listens on sockets defined in the master configuration.

  9. Configure IMAP process title visibility

    main
    The IMAP server can display detailed process titles (e.g., showing the username, remote IP, and current command) in the process list. This is controlled by the verbose_proctitle global variable. When enabled, the server periodically refreshes the process title to reflect the current state of active connections.