feat: mail UI improvements - folder mapping, display name, resize perf, list header
- Add configurable folder mapping (sent/drafts/spam/trash) per account - Migration 0005_folder_mapping.sql with 4 new columns on mail_accounts - Backend: send_mail uses account.sent_folder_imap_name if set - Backend: _build_folder_hierarchy respects folder_mapping for is_standard - Frontend: MailSettings shows folder mapping editor per account - Frontend: MailSettings allows editing display_name for existing accounts - Frontend: MailFolderTree shows display_name || email, removes MailIcon - Frontend: ResizablePanel isDragging state with contain:strict + pointer-events:none - Frontend: MailList merges select-all and sort controls into one line
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
-- Mail plugin migration 0005: add configurable IMAP folder mapping columns
|
||||
|
||||
ALTER TABLE mail_accounts ADD COLUMN IF NOT EXISTS sent_folder_imap_name VARCHAR(255);
|
||||
ALTER TABLE mail_accounts ADD COLUMN IF NOT EXISTS drafts_folder_imap_name VARCHAR(255);
|
||||
ALTER TABLE mail_accounts ADD COLUMN IF NOT EXISTS spam_folder_imap_name VARCHAR(255);
|
||||
ALTER TABLE mail_accounts ADD COLUMN IF NOT EXISTS trash_folder_imap_name VARCHAR(255);
|
||||
@@ -48,6 +48,10 @@ class MailAccount(Base, TenantMixin):
|
||||
encrypted_password: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
is_shared: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
||||
sent_folder_imap_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
drafts_folder_imap_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
spam_folder_imap_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
trash_folder_imap_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,10 @@ class MailAccountCreate(BaseModel):
|
||||
username: str = Field(default="", min_length=0, max_length=255)
|
||||
password: str = Field(..., min_length=1, max_length=512)
|
||||
is_shared: bool = False
|
||||
sent_folder_imap_name: str | None = Field(None, max_length=255)
|
||||
drafts_folder_imap_name: str | None = Field(None, max_length=255)
|
||||
spam_folder_imap_name: str | None = Field(None, max_length=255)
|
||||
trash_folder_imap_name: str | None = Field(None, max_length=255)
|
||||
|
||||
|
||||
class MailAccountUpdate(BaseModel):
|
||||
@@ -38,6 +42,10 @@ class MailAccountUpdate(BaseModel):
|
||||
password: str | None = Field(None, min_length=1, max_length=512)
|
||||
is_shared: bool | None = None
|
||||
is_active: bool | None = None
|
||||
sent_folder_imap_name: str | None = Field(None, max_length=255)
|
||||
drafts_folder_imap_name: str | None = Field(None, max_length=255)
|
||||
spam_folder_imap_name: str | None = Field(None, max_length=255)
|
||||
trash_folder_imap_name: str | None = Field(None, max_length=255)
|
||||
|
||||
|
||||
class MailAccountResponse(BaseModel):
|
||||
@@ -54,6 +62,10 @@ class MailAccountResponse(BaseModel):
|
||||
username: str
|
||||
is_shared: bool
|
||||
is_active: bool
|
||||
sent_folder_imap_name: str | None = None
|
||||
drafts_folder_imap_name: str | None = None
|
||||
spam_folder_imap_name: str | None = None
|
||||
trash_folder_imap_name: str | None = None
|
||||
created_at: datetime | None = None
|
||||
updated_at: datetime | None = None
|
||||
|
||||
|
||||
@@ -270,6 +270,10 @@ async def create_mail_account(
|
||||
encrypted_password=encrypt_password(data["password"]),
|
||||
is_shared=data.get("is_shared", False),
|
||||
is_active=True,
|
||||
sent_folder_imap_name=data.get("sent_folder_imap_name"),
|
||||
drafts_folder_imap_name=data.get("drafts_folder_imap_name"),
|
||||
spam_folder_imap_name=data.get("spam_folder_imap_name"),
|
||||
trash_folder_imap_name=data.get("trash_folder_imap_name"),
|
||||
)
|
||||
db.add(account)
|
||||
await db.flush()
|
||||
@@ -319,6 +323,10 @@ async def update_mail_account(db: AsyncSession, account: MailAccount, data: dict
|
||||
"username": "username",
|
||||
"is_shared": "is_shared",
|
||||
"is_active": "is_active",
|
||||
"sent_folder_imap_name": "sent_folder_imap_name",
|
||||
"drafts_folder_imap_name": "drafts_folder_imap_name",
|
||||
"spam_folder_imap_name": "spam_folder_imap_name",
|
||||
"trash_folder_imap_name": "trash_folder_imap_name",
|
||||
}
|
||||
for api_field, model_field in field_map.items():
|
||||
if api_field in data and data[api_field] is not None:
|
||||
@@ -351,6 +359,10 @@ def account_to_response(account: MailAccount) -> dict:
|
||||
"username": account.username,
|
||||
"is_shared": account.is_shared,
|
||||
"is_active": account.is_active,
|
||||
"sent_folder_imap_name": account.sent_folder_imap_name,
|
||||
"drafts_folder_imap_name": account.drafts_folder_imap_name,
|
||||
"spam_folder_imap_name": account.spam_folder_imap_name,
|
||||
"trash_folder_imap_name": account.trash_folder_imap_name,
|
||||
"created_at": account.created_at,
|
||||
"updated_at": account.updated_at,
|
||||
}
|
||||
@@ -454,6 +466,7 @@ def _build_folder_hierarchy(
|
||||
tenant_id: uuid.UUID,
|
||||
existing_folders: dict[str, MailFolder],
|
||||
delimiter: str = '.',
|
||||
folder_mapping: dict[str, str | None] | None = None,
|
||||
) -> list[MailFolder]:
|
||||
"""Create or update MailFolder records from IMAP LIST response.
|
||||
|
||||
@@ -463,6 +476,13 @@ def _build_folder_hierarchy(
|
||||
"""
|
||||
result: list[MailFolder] = []
|
||||
|
||||
# Build reverse mapping: imap_name -> standard type (sent/drafts/spam/trash)
|
||||
mapping_by_imap: dict[str, str] = {}
|
||||
if folder_mapping:
|
||||
for std_type, imap_name_val in folder_mapping.items():
|
||||
if imap_name_val:
|
||||
mapping_by_imap[imap_name_val] = std_type
|
||||
|
||||
# First pass: create or update folder records
|
||||
for flags, imap_name in imap_folders:
|
||||
if not imap_name:
|
||||
@@ -471,6 +491,19 @@ def _build_folder_hierarchy(
|
||||
display_name = _get_german_folder_name(imap_name)
|
||||
is_standard = imap_name in STANDARD_IMAP_FOLDERS
|
||||
|
||||
# If account has explicit folder mapping, mark mapped folders as standard
|
||||
if imap_name in mapping_by_imap:
|
||||
is_standard = True
|
||||
std_type = mapping_by_imap[imap_name]
|
||||
if std_type == "sent":
|
||||
display_name = "Gesendet"
|
||||
elif std_type == "drafts":
|
||||
display_name = "Entwürfe"
|
||||
elif std_type == "spam":
|
||||
display_name = "Spam"
|
||||
elif std_type == "trash":
|
||||
display_name = "Papierkorb"
|
||||
|
||||
if imap_name in existing_folders:
|
||||
folder = existing_folders[imap_name]
|
||||
folder.name = display_name
|
||||
@@ -641,8 +674,15 @@ async def imap_sync_account(
|
||||
break
|
||||
|
||||
# 3) Create/update folders in DB
|
||||
folder_mapping = {
|
||||
"sent": account.sent_folder_imap_name,
|
||||
"drafts": account.drafts_folder_imap_name,
|
||||
"spam": account.spam_folder_imap_name,
|
||||
"trash": account.trash_folder_imap_name,
|
||||
}
|
||||
db_folders = _build_folder_hierarchy(
|
||||
imap_folders, account.id, tenant_id, existing_by_imap, imap_delimiter
|
||||
imap_folders, account.id, tenant_id, existing_by_imap, imap_delimiter,
|
||||
folder_mapping=folder_mapping,
|
||||
)
|
||||
for folder in db_folders:
|
||||
if folder.id is None:
|
||||
@@ -1079,33 +1119,45 @@ async def send_mail_via_smtp(
|
||||
await smtp.send_message(msg, recipients=recipients)
|
||||
await smtp.quit()
|
||||
|
||||
# Store sent mail in Sent folder — flexible lookup to handle
|
||||
# different IMAP naming conventions (Sent, INBOX.Sent, Sent Items, etc.)
|
||||
sent_folder = (
|
||||
await db.execute(
|
||||
select(MailFolder).where(
|
||||
and_(
|
||||
MailFolder.account_id == account.id,
|
||||
MailFolder.imap_name.in_(
|
||||
["Sent", "INBOX.Sent", "Sent Items", "Sent Mail"]
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
|
||||
if not sent_folder:
|
||||
# Store sent mail in Sent folder — use configured mapping if set,
|
||||
# otherwise flexible lookup to handle different IMAP naming conventions
|
||||
if account.sent_folder_imap_name:
|
||||
sent_folder = (
|
||||
await db.execute(
|
||||
select(MailFolder).where(
|
||||
and_(
|
||||
MailFolder.account_id == account.id,
|
||||
MailFolder.is_standard == True,
|
||||
MailFolder.imap_name.ilike("%sent%"),
|
||||
MailFolder.imap_name == account.sent_folder_imap_name,
|
||||
)
|
||||
)
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
else:
|
||||
sent_folder = (
|
||||
await db.execute(
|
||||
select(MailFolder).where(
|
||||
and_(
|
||||
MailFolder.account_id == account.id,
|
||||
MailFolder.imap_name.in_(
|
||||
["Sent", "INBOX.Sent", "Sent Items", "Sent Mail"]
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
|
||||
if not sent_folder:
|
||||
sent_folder = (
|
||||
await db.execute(
|
||||
select(MailFolder).where(
|
||||
and_(
|
||||
MailFolder.account_id == account.id,
|
||||
MailFolder.is_standard == True,
|
||||
MailFolder.imap_name.ilike("%sent%"),
|
||||
)
|
||||
)
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
|
||||
if sent_folder:
|
||||
thread_id = _compute_thread_id(msg_id, references_header or "", in_reply_to)
|
||||
|
||||
Reference in New Issue
Block a user