Skip to content

Commit e47d69c

Browse files
authored
Merge pull request #3 from moenny/fix-pop3
Fix some pop3 issues
2 parents 40fcdb9 + 2875611 commit e47d69c

File tree

1 file changed

+9
-8
lines changed
  • src/MailClientLibrary/mailclient/protocols

1 file changed

+9
-8
lines changed

src/MailClientLibrary/mailclient/protocols/pop3.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, useSsl:bool):
2525
MailClientError.raise_mail_client_error(MailClientError.FalseHost.format("Pop3",Variables.pop3_mail_server))
2626
except:
2727
try:
28-
self.pop3obj = poplib.POP3(Variables.imap_mail_server, Variables.imap_ssl_port)
28+
self.pop3obj = poplib.POP3(Variables.pop3_mail_server, Variables.pop3_ssl_port)
2929
self.pop3obj.stls()
3030
except(poplib.error_proto):
3131
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):
4747
MailClientError.raise_mail_client_error(MailClientError.FalseCridentials.format("Pop3",Variables.pop3_username,Variables.pop3_password))
4848
self.data = []
4949
for mail in self.mails:
50-
self.data.append(int(mail[:1].decode()))
50+
self.data.append(int(mail.decode().split()[0]))
5151

5252
def __del__(self):
5353
"""
@@ -82,7 +82,7 @@ def is_inbox_empty(self):
8282

8383
def open_mail_by_criteria(self, criteria:str, value:str, firstOnly=True):
8484
"""
85-
This function finds the first mail in the initialized imap mailbox with the given subject
85+
This function finds the first mail in the initialized pop3 mailbox with the given subject
8686
Criteria= "From" or "Subject" (Case Sensitive)
8787
Returns the entire mail's mime as string.
8888
"""
@@ -103,11 +103,12 @@ def open_mail_by_criteria(self, criteria:str, value:str, firstOnly=True):
103103

104104
def open_mail_by_index(self,index:int):
105105
"""
106-
This function returns the index-th mail raw context from initialized imap mailbox
106+
This function returns the index-th mail raw context from initialized pop3 mailbox
107107
Returns False if there is no mail with the given index in mailbox
108108
"""
109109
if self.is_inbox_empty():
110110
return False
111+
index = int(index)
111112
if index in self.data:
112113
byte_lines = self.pop3obj.retr(index)[1]
113114
messageText = str(message_from_bytes(b'\r\n'.join(byte_lines)))
@@ -116,7 +117,7 @@ def open_mail_by_index(self,index:int):
116117

117118
def delete_every_mail(self):
118119
"""
119-
This function deletes every mail in initialized imap mailbox
120+
This function deletes every mail in initialized pop3 mailbox
120121
Returns True if any mail is deleted otherwise False
121122
"""
122123
if self.is_inbox_empty():
@@ -131,7 +132,7 @@ def delete_every_mail(self):
131132

132133
def delete_mail_by_criteria(self, criteria, subject, firstOnly=True):
133134
"""
134-
This function reads an email inbox using imap protocol and deletes the email with corresponding subject.
135+
This function reads an email inbox using pop3 protocol and deletes the email with corresponding subject.
135136
Returns True if any mail is deleted otherwise False
136137
"""
137138
deletedAny = False
@@ -145,7 +146,7 @@ def delete_mail_by_criteria(self, criteria, subject, firstOnly=True):
145146

146147
def delete_mail_by_index(self, index:int):
147148
"""
148-
This function reads an email inbox using imap protocol and deletes the email with corresponding subject.
149+
This function reads an email inbox using pop3 protocol and deletes the email with corresponding subject.
149150
"""
150151
if self.is_inbox_empty():
151152
return False
@@ -155,7 +156,7 @@ def delete_mail_by_index(self, index:int):
155156
return False
156157

157158
def _get_mail_indexes_by_criteria(self, criteria, value):
158-
""" This function iterates only through subjects of the mails in initialized imap mailbox
159+
""" This function iterates only through subjects of the mails in initialized pop3 mailbox
159160
and returns the first index found with the given subject or sender
160161
Args:
161162
Creteria = "Subject" or "From" (CaseSensible)

0 commit comments

Comments
 (0)