Skip to content

Commit

Permalink
rename functions, get rid of star import
Browse files Browse the repository at this point in the history
  • Loading branch information
JNAOB committed Nov 27, 2024
1 parent 0edd9a3 commit 2cd67ba
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions EMailService.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass
from email2 import *
from imaplib import IMAP4_SSL
from email2 import Email, EmailReception, Attachment, Contact, RecipientKind
#from imaplib import IMAP4_SSL
from imapclient import IMAPClient
from smtplib import SMTP_SSL,SMTP_SSL_PORT
import email
Expand All @@ -22,15 +21,15 @@ def login(self,user:str, password:str) -> bool:
def logout(self) -> bool:
pass
@abstractmethod
def sendEmail(self,email: Email) -> bool:
def send_email(self,email: Email) -> bool:
"""Requierment: User is logged in"""
pass
@abstractmethod
def deleteEmail(self, uid:int) -> bool:
def delete_email(self, uid:int) -> bool:
"""Requierment: User is logged in"""
pass
@abstractmethod
def getEmails(self)->list[Email]:
def get_emails(self)->list[Email]:
pass

class ImapProtocol(ProtocolTemplate):
Expand Down Expand Up @@ -58,7 +57,7 @@ def logout(self) -> bool:
self.user_passwort = None
self.user_username = None

def sendEmail(self, email:Email) -> bool:
def send_email(self, email:Email) -> bool:
"""Requierment: User is logged in"""
SMTP_USER = self.user_username
SMTP_PASS = self.user_passwort
Expand Down Expand Up @@ -101,15 +100,15 @@ def sendEmail(self, email:Email) -> bool:
smtp_server.quit()
pass

def deleteEmail(self, uid:int) -> bool:
def delete_email(self, uid:int) -> bool:
"""Requierment: User is logged in"""
for mailbox in self.IMAP.list_folders():
self.IMAP.select_folder(mailbox)
messages_ids = self.IMAP.search(["UID",uid])
if len(messages_ids)!= 0:
self.IMAP.delete_messages()

def getEmails(self)->list[Email]:
def get_emails(self)->list[Email]:
listofMails = []
self.IMAP.select_folder("INBOX")
messages_ids = self.IMAP.search(["ALL"])
Expand Down Expand Up @@ -200,7 +199,7 @@ def logout(self) -> bool:
self._logged_in = False
return True

def sendEmail(self,email:Email) -> bool:
def send_email(self,email:Email) -> bool:
"""Requierment: User is logged in"""
if not self.logged_in:
return False
Expand Down Expand Up @@ -245,7 +244,7 @@ def mark_email(self, uid, read : bool):
item.save(update_fields = ["is_read"])


def deleteEmail(self, uid:int) -> bool:
def delete_email(self, uid:int) -> bool:
"""Requierment: User is logged in
moves the email in the trash folder"""
if not self.logged_in:
Expand All @@ -254,7 +253,7 @@ def deleteEmail(self, uid:int) -> bool:
for item in self.acc.inbox.filter(message_id=uid):
item.move_to_trash()

def getEmails(self)->list[Email]:
def get_emails(self)->list[Email]:

if not self.logged_in:
return None
Expand Down Expand Up @@ -293,10 +292,10 @@ def imap_test():
imap.login("thatchmilo35@gmail.com","mgtszvrhgkphxghm")
print("IMAP Logged_in: ",imap.logged_in)

imap.sendEmail(test)
imap.send_email(test)
print("sent?")

listofmails = imap.getEmails()
listofmails = imap.get_emails()

Check failure on line 298 in EMailService.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

EMailService.py:298:5: F841 Local variable `listofmails` is assigned to but never used
#print("body" ,listofmails[0].body,"id",listofmails[0].id )

imap.logout()
Expand All @@ -320,8 +319,8 @@ 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"))
print("Exchange Logged_in: ",exchange.logged_in)
emails = exchange.getEmails()
#exchange.sendEmail(test)
emails = exchange.get_emails()

Check failure on line 322 in EMailService.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

EMailService.py:322:5: F841 Local variable `emails` is assigned to but never used
#exchange.send_email(test)
exchange.logout()
print("Exchange Logged_in: ",exchange.logged_in)

Expand Down

0 comments on commit 2cd67ba

Please sign in to comment.