From bcc273196a9020bee958d89712b60efc13852629 Mon Sep 17 00:00:00 2001 From: Stefan Koelle Date: Tue, 4 Aug 2026 23:16:27 +0200 Subject: [PATCH] fix --- src/vcard_parser.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/vcard_parser.py b/src/vcard_parser.py index c00235c..f5fe502 100644 --- a/src/vcard_parser.py +++ b/src/vcard_parser.py @@ -11,6 +11,17 @@ def _get(vcard, attr, default=None): return getattr(vcard, attr).value if hasattr(vcard, attr) else default +def _type_str(obj) -> str: + """Liest den TYPE-Parameter sicher aus einem vobject-Element.""" + if hasattr(obj, "type_paramlist") and obj.type_paramlist: + return ",".join(obj.type_paramlist) + params = getattr(obj, "params", {}) + type_val = params.get("TYPE") or params.get("type") + if type_val: + return type_val if isinstance(type_val, str) else ",".join(type_val) + return "other" + + def parse_vcard(raw_text: str, account: str) -> dict | None: try: vcard = vobject.readOne(raw_text) @@ -30,21 +41,21 @@ def parse_vcard(raw_text: str, account: str) -> dict | None: prefix = n.value.prefix if n else None suffix = n.value.suffix if n else None - emails = [{"type": ",".join(e.type_paramlist) if e.type_paramlist else "other", "value": e.value} + emails = [{"type": _type_str(e), "value": e.value} for e in getattr(vcard, "email_list", [])] - phones = [{"type": ",".join(t.type_paramlist) if t.type_paramlist else "other", "value": t.value} + phones = [{"type": _type_str(t), "value": t.value} for t in getattr(vcard, "tel_list", [])] addresses = [] for a in getattr(vcard, "adr_list", []): v = a.value addresses.append({ - "type": ",".join(a.type_paramlist) if a.type_paramlist else "other", + "type": _type_str(a), "street": v.street, "city": v.city, "region": v.region, "zip": v.code, "country": v.country, }) - urls = [{"type": ",".join(u.type_paramlist) if u.type_paramlist else "other", "value": u.value} + urls = [{"type": _type_str(u), "value": u.value} for u in getattr(vcard, "url_list", [])] categories = [c.strip() for c in vcard.categories.value] if hasattr(vcard, "categories") else []