diff --git a/src/MailClientLibrary/mailclient/protocols/pop3.py b/src/MailClientLibrary/mailclient/protocols/pop3.py index 45a09a7..62b72c4 100644 --- a/src/MailClientLibrary/mailclient/protocols/pop3.py +++ b/src/MailClientLibrary/mailclient/protocols/pop3.py @@ -25,7 +25,7 @@ def __init__(self, useSsl:bool): MailClientError.raise_mail_client_error(MailClientError.FalseHost.format("Pop3",Variables.pop3_mail_server)) except: try: - self.pop3obj = poplib.POP3(Variables.imap_mail_server, Variables.imap_ssl_port) + self.pop3obj = poplib.POP3(Variables.pop3_mail_server, Variables.pop3_ssl_port) self.pop3obj.stls() except(poplib.error_proto): MailClientError.raise_mail_client_error(MailClientError.FalseHostOrPort.format("Pop3", Variables.pop3_mail_server, Variables.pop3_ssl_port)) @@ -47,7 +47,7 @@ def __init__(self, useSsl:bool): MailClientError.raise_mail_client_error(MailClientError.FalseCridentials.format("Pop3",Variables.pop3_username,Variables.pop3_password)) self.data = [] for mail in self.mails: - self.data.append(int(mail[:1].decode())) + self.data.append(int(mail.decode().split()[0])) def __del__(self): """ @@ -82,7 +82,7 @@ def is_inbox_empty(self): def open_mail_by_criteria(self, criteria:str, value:str, firstOnly=True): """ - This function finds the first mail in the initialized imap mailbox with the given subject + This function finds the first mail in the initialized pop3 mailbox with the given subject Criteria= "From" or "Subject" (Case Sensitive) Returns the entire mail's mime as string. """ @@ -103,11 +103,12 @@ def open_mail_by_criteria(self, criteria:str, value:str, firstOnly=True): def open_mail_by_index(self,index:int): """ - This function returns the index-th mail raw context from initialized imap mailbox + This function returns the index-th mail raw context from initialized pop3 mailbox Returns False if there is no mail with the given index in mailbox """ if self.is_inbox_empty(): return False + index = int(index) if index in self.data: byte_lines = self.pop3obj.retr(index)[1] messageText = str(message_from_bytes(b'\r\n'.join(byte_lines))) @@ -116,7 +117,7 @@ def open_mail_by_index(self,index:int): def delete_every_mail(self): """ - This function deletes every mail in initialized imap mailbox + This function deletes every mail in initialized pop3 mailbox Returns True if any mail is deleted otherwise False """ if self.is_inbox_empty(): @@ -131,7 +132,7 @@ def delete_every_mail(self): def delete_mail_by_criteria(self, criteria, subject, firstOnly=True): """ - This function reads an email inbox using imap protocol and deletes the email with corresponding subject. + This function reads an email inbox using pop3 protocol and deletes the email with corresponding subject. Returns True if any mail is deleted otherwise False """ deletedAny = False @@ -145,7 +146,7 @@ def delete_mail_by_criteria(self, criteria, subject, firstOnly=True): def delete_mail_by_index(self, index:int): """ - This function reads an email inbox using imap protocol and deletes the email with corresponding subject. + This function reads an email inbox using pop3 protocol and deletes the email with corresponding subject. """ if self.is_inbox_empty(): return False @@ -155,7 +156,7 @@ def delete_mail_by_index(self, index:int): return False def _get_mail_indexes_by_criteria(self, criteria, value): - """ This function iterates only through subjects of the mails in initialized imap mailbox + """ This function iterates only through subjects of the mails in initialized pop3 mailbox and returns the first index found with the given subject or sender Args: Creteria = "Subject" or "From" (CaseSensible)