mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-04-28 08:44:59 +00:00
Add error handling to quoted-printable decoding
Wrapped the decode_quoted_printable function in a try-except block to handle decoding errors gracefully. If decoding fails, a warning is logged and the original value is returned, improving robustness when processing malformed vCard data.
This commit is contained in:
@@ -40,8 +40,16 @@ class ContactsFromVCards:
|
|||||||
|
|
||||||
def decode_quoted_printable(value: str, charset: str) -> str:
|
def decode_quoted_printable(value: str, charset: str) -> str:
|
||||||
"""Decode a vCard value that may be quoted-printable UTF-8."""
|
"""Decode a vCard value that may be quoted-printable UTF-8."""
|
||||||
bytes_val = quopri.decodestring(value)
|
try:
|
||||||
return bytes_val.decode(charset, errors="replace")
|
bytes_val = quopri.decodestring(value)
|
||||||
|
return bytes_val.decode(charset, errors="replace")
|
||||||
|
except Exception:
|
||||||
|
# Fallback: return the original value if decoding fails
|
||||||
|
logger.warning(
|
||||||
|
f"Failed to decode quoted-printable value: {value}, "
|
||||||
|
f"charset: {charset}. Please report this issue.{CLEAR_LINE}"
|
||||||
|
)
|
||||||
|
return value
|
||||||
|
|
||||||
def _parse_vcard_line(line: str) -> tuple[str, dict[str, str], str] | None:
|
def _parse_vcard_line(line: str) -> tuple[str, dict[str, str], str] | None:
|
||||||
"""
|
"""
|
||||||
@@ -143,10 +151,7 @@ def process_vcard_entry(entry: str) -> dict | bool:
|
|||||||
if not name:
|
if not name:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 2. Extract phone numbers
|
|
||||||
numbers = get_vcard_value(entry, "TEL")
|
numbers = get_vcard_value(entry, "TEL")
|
||||||
|
|
||||||
# Ensure at least one number was found
|
|
||||||
if not numbers:
|
if not numbers:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user