mirror of
https://github.com/khoaliber/LetterFeed.git
synced 2026-03-02 13:18:27 +00:00
chore: backend cleanup
This commit is contained in:
@@ -4,7 +4,7 @@ from app.core.database import Base
|
||||
|
||||
|
||||
class Settings(Base):
|
||||
"""Represents application settings, including IMAP configuration."""
|
||||
"""Represents application settings."""
|
||||
|
||||
__tablename__ = "settings"
|
||||
|
||||
|
||||
@@ -56,27 +56,20 @@ def _fetch_unread_email_ids(mail: imaplib.IMAP4_SSL) -> list[str]:
|
||||
|
||||
def _get_email_body(msg: Message) -> str:
|
||||
"""Extract body from an email message."""
|
||||
body, html = "", ""
|
||||
body = ""
|
||||
for part in msg.walk():
|
||||
ctype = part.get_content_type()
|
||||
cdispo = str(part.get("Content-Disposition"))
|
||||
if "attachment" in cdispo:
|
||||
continue
|
||||
if ctype == "text/plain":
|
||||
if ctype in ["text/plain", "text/html"]:
|
||||
try:
|
||||
payload = part.get_payload(decode=True)
|
||||
charset = part.get_content_charset() or "utf-8"
|
||||
body = payload.decode(charset, "ignore")
|
||||
except Exception:
|
||||
pass
|
||||
elif ctype == "text/html":
|
||||
try:
|
||||
payload = part.get_payload(decode=True)
|
||||
charset = part.get_content_charset() or "utf-8"
|
||||
html = payload.decode(charset, "ignore")
|
||||
except Exception:
|
||||
pass
|
||||
return html or body
|
||||
return body
|
||||
|
||||
|
||||
def _auto_add_newsletter(
|
||||
|
||||
@@ -25,7 +25,7 @@ def generate_feed(db: Session, newsletter_id: str):
|
||||
fg.logo(logo_url)
|
||||
fg.icon(icon_url)
|
||||
fg.link(href=feed_url, rel="self")
|
||||
fg.link(href=settings.app_base_url, rel="alternate")
|
||||
fg.link(href=f"{settings.app_base_url}/", rel="alternate")
|
||||
sender_emails = ", ".join([s.email for s in newsletter.senders])
|
||||
fg.description(f"A feed of newsletters from {sender_emails}")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "letterfeed-backend"
|
||||
version = "0.1.0"
|
||||
version = "0.4.0"
|
||||
description = "Backend for LetterFeed"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
|
||||
Reference in New Issue
Block a user