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