From e1faf7b4b273cf9bce9b3570308ffc255cef5e87 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 8 Oct 2020 21:53:19 +0200 Subject: [PATCH] Close lists --- sympasoap/client.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/sympasoap/client.py b/sympasoap/client.py index 375db78..b3d3cf2 100644 --- a/sympasoap/client.py +++ b/sympasoap/client.py @@ -131,7 +131,10 @@ class Client: return lists def create_list(self, list_name: str, subject: str, template: str, description: str, topic: str, - use_custom_template: bool = False) -> bool: + use_custom_template: bool = False, raise_error: bool = True) -> bool: + """ + Create a new mailing-list. + """ if topic not in TOPICS and topic not in SUBTOPICS: raise ValueError(f"Topic '{topic}' does not exist.") if template not in TEMPLATES and not use_custom_template: @@ -139,5 +142,26 @@ class Client: try: result = self.zeep.service.createList(list_name, subject, template, description, topic) return result._raw_elements[0].text == "true" - except Fault: - raise Fault(f"An unknown error occured while creating the list {list_name}. Maybe the list already exists?") + except Fault as e: + if raise_error: + raise Fault(f"An unknown error occured while creating the list {list_name}. " + f"Maybe the list already exists?", e) + else: + return False + + def delete_list(self, list_name: str, raise_error: bool = False) -> bool: + """ + Close a mailing list. + Warning: the list is not deleted in order to keep the history. Please use the web interface to fully + delete the list. + Well, the main reason is that the API does not provide a delete method. + """ + try: + result = self.zeep.service.closeList(list_name) + return result._raw_elements[0].text == "true" + except Fault as e: + if raise_error: + raise Fault(f"An unknown error occured while deleting the list {list_name}. " + f"Maybe the list did not exist?", e) + else: + return False