diff --git a/utils/kolabformatchecker.py b/utils/kolabformatchecker.py index 5b0c5ae..b71e441 100644 --- a/utils/kolabformatchecker.py +++ b/utils/kolabformatchecker.py @@ -1,75 +1,77 @@ #!/usr/bin/env python2.7 import sys import kolabformat import argparse import email parser = argparse.ArgumentParser(description='Check kolab xml objects.') parser.add_argument('messagetype', choices=['xml', 'mime'], help='The type of the object to parse') parser.add_argument('kolabtype', choices=['event', 'todo', 'contact', 'journal', 'distlist', 'note', 'configuration', 'file'], help='The type of the object to parse') parser.add_argument('filename', help='The file to parse') args = parser.parse_args() messageType = args.messagetype objectType = args.kolabtype filename = args.filename if messageType == 'mime': f = open(filename,"r") msg = email.message_from_string(f.read()) kolabType = msg.get('X-Kolab-Type') if not kolabType: print("Missing kolab type X-Kolab-Type") else: print("Found X-Kolab-Type ", kolabType) version = msg.get('X-Kolab-Mime-Version') if not version: print("Missing kolab type X-Kolab-Mime-Version") else: print("Found X-Kolab-Mime-Version ", version) for part in msg.walk(): if part.get_content_type() in ['application/calendar+xml', 'application/vcard+xml', 'application/vnd.kolab+xm']: print("Content type of part is ", part.get_content_type()) print("Filename of part is ", part.get_filename()) xml = part.get_payload(decode=True) print("Found xml ", xml) isPath = False else: xml = filename isPath = True if objectType == 'event': kolabformat.readEvent(xml, isPath) elif objectType == 'todo': kolabformat.readTodo(xml, isPath) elif objectType == 'contact': kolabformat.readContact(xml, isPath) elif objectType == 'journal': kolabformat.readJournal(xml, isPath) elif objectType == 'distlist': kolabformat.readDistlist(xml, isPath) elif objectType == 'note': kolabformat.readNote(xml, isPath) elif objectType == 'configuration': kolabformat.readConfiguration(xml, isPath) elif objectType == 'file': kolabformat.readFile(xml, isPath) error = kolabformat.error() if error == None or not error: print("Successfully parsed the message") + sys.exit(0) else: print("There was an error while parsing ", kolabformat.errorMessage()) + sys.exit(1)