Update mail2sms/main.py
Build and Push Docker Image / test-and-build (push) Successful in 44s

Cette révision appartient à :
2026-02-26 05:40:29 +00:00
Parent 206757b5db
révision bb078a37e7
-43
Voir le fichier
@@ -41,49 +41,6 @@ def log(message):
print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] {message}", flush=True)
def html_to_sms_text(raw_html):
"""
Convert HTML content to clean SMS-compatible plain text.
- Removes HTML tags
- Decodes HTML entities
- Normalizes unicode
- Removes unsupported SMS characters
"""
if not raw_html:
return ""
# Parse HTML
soup = BeautifulSoup(raw_html, "html.parser")
# Get text only
text = soup.get_text(separator=" ")
# Decode HTML entities (  & etc.)
text = html.unescape(text)
# Normalize unicode (remove weird accents/combined chars)
text = unicodedata.normalize("NFKD", text)
# Remove non GSM basic characters
gsm_basic = (
"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ"
+ ' !"%&\'()*+,-./'
+ "0123456789:;<=>?"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "ÄÖÑܧ¿"
+ "abcdefghijklmnopqrstuvwxyz"
+ "äöñüà"
)
cleaned = "".join(c for c in text if c in gsm_basic)
# Remove multiple spaces
cleaned = re.sub(r"\s+", " ", cleaned).strip()
return cleaned
# ============================================================
# SUBJECT PARAMETER EXTRACTION
# ============================================================