[fs2zammad] extra tweaks for zammad to accept edge cases/tickets

This commit is contained in:
fnux 2024-05-15 11:49:06 +02:00
parent 64218fe9d8
commit a44c5361f4
No known key found for this signature in database
GPG key ID: 4502C902C00A1E12

View file

@ -70,15 +70,25 @@ def maybe_create_zammad_user(userdata, zammad_session, attr="login", default=Non
else: else:
raise ValueError("Invalid userdata") raise ValueError("Invalid userdata")
# We manually filter out invalid addresses.
if email == "*@*.com":
userdata = {
'EmailAddress': 'technik@ungleich.ch',
'RealName': 'Disabled RT'
}
email = userdata["EmailAddress"]
lowercase_email = email.lower() lowercase_email = email.lower()
if lowercase_email not in USERMAP: if lowercase_email not in USERMAP:
kwargs = {"email": email} kwargs = {"email": email}
kwargs.update(config["userdata"]) kwargs.update(config["userdata"])
if "RealName" in userdata: if "RealName" in userdata:
realname = userdata["RealName"] realname = userdata["RealName"]
if ", " in realname: if ", " in realname.strip():
last, first = realname.split(", ", 1) last, first = realname.split(", ", 1)
elif " " in realname: elif " " in realname.strip():
first, last = realname.split(None, 1) first, last = realname.split(None, 1)
else: else:
last = realname last = realname
@ -217,6 +227,8 @@ def create_zammad_ticket(id, zammad, h2t, retries=3):
entry_content = base64.b64decode(file["data"]).decode("utf-8") entry_content = base64.b64decode(file["data"]).decode("utf-8")
if file["mime-type"]: if file["mime-type"]:
entry_content = h2t.handle(entry_content) entry_content = h2t.handle(entry_content)
if entry_content.strip() == '':
entry_content = "RT: Empty content."
zammad_entry_template = { zammad_entry_template = {
"ticket_id": zammad_ticket["id"], "ticket_id": zammad_ticket["id"],