Email: add explicit SMTP security mode
This commit is contained in:
@@ -298,6 +298,7 @@ class EmailAccount(TimestampMixin, Base):
|
||||
# SMTP (sending)
|
||||
smtp_host = Column(String, default="")
|
||||
smtp_port = Column(Integer, default=465)
|
||||
smtp_security = Column(String, default="ssl") # ssl | starttls | none
|
||||
smtp_user = Column(String, default="")
|
||||
smtp_password = Column(String, default="")
|
||||
|
||||
@@ -1517,6 +1518,7 @@ def init_db():
|
||||
_migrate_drop_ping_notes_tasks()
|
||||
_migrate_add_crew_member_id()
|
||||
_migrate_add_assistant_columns()
|
||||
_migrate_add_email_smtp_security()
|
||||
_migrate_seed_email_account()
|
||||
_migrate_add_calendar_metadata()
|
||||
_migrate_add_calendar_is_utc()
|
||||
@@ -1525,6 +1527,32 @@ def init_db():
|
||||
_migrate_encrypt_endpoint_keys()
|
||||
|
||||
|
||||
def _migrate_add_email_smtp_security():
|
||||
"""Add explicit SMTP security mode for Proton Bridge/custom local SMTP."""
|
||||
import sqlite3
|
||||
db_path = DATABASE_URL.replace("sqlite:///", "")
|
||||
if not os.path.exists(db_path):
|
||||
return
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.execute("PRAGMA table_info(email_accounts)")
|
||||
columns = [row[1] for row in cursor.fetchall()]
|
||||
if columns and "smtp_security" not in columns:
|
||||
conn.execute("ALTER TABLE email_accounts ADD COLUMN smtp_security TEXT DEFAULT 'ssl'")
|
||||
conn.execute(
|
||||
"UPDATE email_accounts SET smtp_security = CASE "
|
||||
"WHEN COALESCE(smtp_port, 465) = 587 THEN 'starttls' "
|
||||
"WHEN COALESCE(smtp_port, 465) = 465 THEN 'ssl' "
|
||||
"ELSE 'ssl' END "
|
||||
"WHERE smtp_security IS NULL OR smtp_security = ''"
|
||||
)
|
||||
conn.commit()
|
||||
logging.getLogger(__name__).info("Migrated: added smtp_security column to email_accounts")
|
||||
conn.close()
|
||||
except Exception as e:
|
||||
logging.getLogger(__name__).warning(f"smtp_security migration skipped: {e}")
|
||||
|
||||
|
||||
def _migrate_encrypt_endpoint_keys():
|
||||
"""Encrypt any plaintext provider API keys in model_endpoints. Idempotent;
|
||||
raw SQL so the EncryptedText decorator isn't applied twice."""
|
||||
|
||||
Reference in New Issue
Block a user