Skip to content

EmailFactories.from_env ignores port/ssl env variablesΒ #71

Description

@FernandoCelmer

Description

EmailFactories.from_env honors EMAIL_SERVER, EMAIL_USERNAME, and EMAIL_PASSWORD, but there is no equivalent for port or ssl. When EMAIL_SERVER is set, a Credentials is built with the hard-coded defaults port=993, ssl=True, so a user who needs to point at an IMAP server on a non-standard port (Proton Bridge on 127.0.0.1:1143, dev sandboxes, IMAP-over-STARTTLS on 143) cannot do so via env vars.

Location

email_profile/core/credentials.py lines ~43-71

Current Behavior

server = os.environ.get(server_var)
if server:
    return Credentials(server=server, user=user, password=password)
# else fall back to from_address auto-discovery (also no port/ssl override)

port / ssl are silently fixed to the dataclass defaults.

Expected Behavior

Read EMAIL_PORT and EMAIL_SSL (or configurable env-var names) and forward them into Credentials. Validate types.

Suggested Fix

@classmethod
def from_env(
    cls,
    server_var="EMAIL_SERVER",
    user_var="EMAIL_USERNAME",
    password_var="EMAIL_PASSWORD",
    port_var="EMAIL_PORT",
    ssl_var="EMAIL_SSL",
    load_dotenv=True,
) -> Credentials:
    ...
    port = int(os.environ.get(port_var, 993))
    ssl_raw = os.environ.get(ssl_var, "true").strip().lower()
    ssl = ssl_raw in ("1", "true", "yes", "on")

    server = os.environ.get(server_var)
    if server:
        return Credentials(
            server=server, user=user, password=password, port=port, ssl=ssl,
        )

    return cls.from_address(user, password, port=port, ssl=ssl)

Document the new variables in the README's .env example.

Impact

Anyone deploying via .env-driven configuration cannot connect to non-standard ports without dropping out of the high-level Email.from_env() flow.

Priority

High

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthighHigh priority β€” incorrect behavior, performance, API breakage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions