From b4b3356b50f24a5cd7287b85839bde7c1cfe2443 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 9 Jan 2023 08:37:45 +0100 Subject: [PATCH] init --- chatbot.py | 19 +++++++++++++++ mailParse.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ responder.py | 24 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 chatbot.py create mode 100644 mailParse.py create mode 100644 responder.py diff --git a/chatbot.py b/chatbot.py new file mode 100644 index 0000000..b56d398 --- /dev/null +++ b/chatbot.py @@ -0,0 +1,19 @@ +import requests, os +from dotenv import load_dotenv +load_dotenv() +pw = os.getenv('BOT') + +headers = { + +'Content-Type': 'application/json', + +'Accept': 'application/json', + +'OCS-APIRequest': 'true', + +} + +data = '{"token": "xzntzmuh", "message": "test"}' + +response = requests.post('https://cloud1.sommerschein.de/ocs/v2.php/apps/spreed/api/v1/chat/xzntzmuh', headers=headers, data=data, auth=('Maily', 'pw')) +print(response.content) \ No newline at end of file diff --git a/mailParse.py b/mailParse.py new file mode 100644 index 0000000..d612015 --- /dev/null +++ b/mailParse.py @@ -0,0 +1,66 @@ +import imaplib, email, os +from dotenv import load_dotenv + +complexSearch1 = "UNANSWERED SENTSINCE 01-Sep-2022" + +load_dotenv() +pw = os.getenv('PASSWORD') +server ="w00e1ce2.kasserver.com" +username ="booking@sommerschein.de" + +# Connect to inbox +imap_server = imaplib.IMAP4_SSL(host=server) +imap_server.login(username, pw) +imap_server.select() # Default is `INBOX` + +contacts = [] + +# Find all emails in inbox +_, message_numbers_raw = imap_server.search(None, complexSearch1) +for message_number in message_numbers_raw[0].split(): + _, msg = imap_server.fetch(message_number, '(RFC822)') + + # Parse the raw email message in to a convenient object + message = email.message_from_bytes(msg[0][1]) + contact = message['from'].lower() + if contact not in contacts: + contacts.append(contact) + """ + print('== Email message =====') + # print(message) # print FULL message + print('== Email details =====') + print(f'From: {message["from"]}') + + + print(f'To: {message["to"]}') + print(f'Cc: {message["cc"]}') + print(f'Bcc: {message["bcc"]}') + print(f'Urgency (1 highest 5 lowest): {message["x-priority"]}') + print(f'Object type: {type(message)}') + print(f'Content type: {message.get_content_type()}') + print(f'Content disposition: {message.get_content_disposition()}') + print(f'Multipart?: {message.is_multipart()}') + # If the message is multipart, it basically has multiple emails inside + # so you must extract each "submail" separately. + if message.is_multipart(): + print('Multipart types:') + for part in message.walk(): + print(f'- {part.get_content_type()}') + multipart_payload = message.get_payload() + for sub_message in multipart_payload: + # The actual text/HTML email contents, or attachment data + print(f'Payload\n{sub_message.get_payload()}') + else: # Not a multipart message, payload is simple string + print(f'Payload\n{message.get_payload()}') + # You could also use `message.iter_attachments()` to get attachments only + +for c in contacts: + print(c) +""" +for c in contacts: + contact = c.split('<') + if len(contact) == 2: + contact = contact[1].split('>') + print(contact[0]) + else: + print(contact[0]) \ No newline at end of file diff --git a/responder.py b/responder.py new file mode 100644 index 0000000..68d0696 --- /dev/null +++ b/responder.py @@ -0,0 +1,24 @@ +# import the modules +import imaplib +import email +from email.header import decode_header +import webbrowser +import os +from dotenv import load_dotenv +import time +# load env file +load_dotenv() +pw = os.getenv('PASSWORD') +server ="w00e1ce2.kasserver.com" +username ="booking@sommerschein.de" + +# Connect to inbox +imap_server = imaplib.IMAP4_SSL(host=server) +imap_server.login(username, pw) +imap_server.select() # Default is `INBOX` + +# Find all emails in inbox and print out the raw email data +_, message_numbers_raw = imap_server.search(None, 'ALL') +for message_number in message_numbers_raw[0].split(): + _, msg = imap_server.fetch(message_number, '(RFC822)') + print(msg[0][1]) \ No newline at end of file