Skip to content

Commit

Permalink
corrected Ruff problems
Browse files Browse the repository at this point in the history
corrected code to accommodate Ruff
  • Loading branch information
Mephisto2409 committed Nov 29, 2024
1 parent 66c631a commit 215f87a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
33 changes: 10 additions & 23 deletions EMailService.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import email
from email.message import EmailMessage
from datetime import datetime
from exchangelib import Credentials, Account, Message, FileAttachment, EWSDateTime, UTC
import os


class ProtocolTemplate(ABC):
Expand Down Expand Up @@ -46,7 +48,7 @@ class ImapProtocol(ProtocolTemplate):

@property
def logged_in(self) -> bool:
return self.user_passwort != None and self.user_username != None
return self.user_passwort is not None and self.user_username is not None

def login(self,user:str, password:str) -> bool:
self.user_username = user
Expand Down Expand Up @@ -82,7 +84,7 @@ def send_email(self, email:Email) -> bool:
msg['From'] = from_email
msg['To'] = to
msg['Cc'] = cc
msg['Bcc'] = ",".join(bcc)
#msg['Bcc'] = ",".join(bcc)
msg.set_content(email.body)

#attachment
Expand Down Expand Up @@ -111,7 +113,7 @@ def delete_email(self, uid:int) -> bool:
def get_emails(self, date : datetime = None)->list[Email]:
listofMails = []
self.IMAP.select_folder("INBOX")
if date != None:
if date is not None:
messages_ids = self.IMAP.search([u'SINCE',date])
else:
messages_ids = self.IMAP.search(["ALL"])
Expand Down Expand Up @@ -170,22 +172,6 @@ def get_emails(self, date : datetime = None)->list[Email]:
html_files = html_parts)]
return listofMails

def get_deleted_email(self)->list[str]:
listofUIPsDatenbank = []
listofUIPsIMAP = []
for mailbox in self.IMAP.list_folders():
self.IMAP.select_folder(mailbox)
messages_ids = self.IMAP.search(["ALL"])
for message_data in self.IMAP.fetch(messages_ids,["RFC822","UID"]).items():
listofUIPsIMAP.append(message_data.get(b"UID"))
return listofUIPsDatenbank-listofUIPsIMAP




from exchangelib import Credentials, Account, Message, FileAttachment, EWSDateTime, UTC
import os

class ExchangeProtocol(ProtocolTemplate):


Expand Down Expand Up @@ -244,7 +230,8 @@ def send_email(self,email:Email) -> bool:
for attachement in email.attachments:

path = attachement.filename
if not os.path.exists(path): continue
if not os.path.exists(path):
continue
with open(path,"b+r") as f:
content = f.read()
att = FileAttachment(name = os.path.basename(path), content = content)
Expand Down Expand Up @@ -337,7 +324,7 @@ def exchange_test():


#exchange
#import keyring
import keyring

test = Email(

Expand All @@ -348,11 +335,11 @@ def exchange_test():


print("Exchange Logged_in: ",exchange.logged_in)
#exchange.login("praxisprojekt-remail@uni-due.de",keyring.get_password("remail/exchange","praxisprojekt-remail@uni-due.de"))
exchange.login("praxisprojekt-remail@uni-due.de",keyring.get_password("remail/exchange","praxisprojekt-remail@uni-due.de"))
print("Exchange Logged_in: ",exchange.logged_in)
emails = exchange.get_emails(datetime(2024,11,29,9,29))
print(emails)
#exchange.send_email(test)
exchange.send_email(test)
exchange.logout()
print("Exchange Logged_in: ",exchange.logged_in)

Expand Down
3 changes: 1 addition & 2 deletions email2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from enum import Enum
from pathlib import Path
from typing import List, Optional
import sqlalchemy
from sqlmodel import Field, SQLModel, Relationship, Session, create_engine, select
from sqlmodel import Field, SQLModel, Relationship
from datetime import datetime

def id_field(table_name: str):
Expand Down

0 comments on commit 215f87a

Please sign in to comment.