Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/ImapLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def delete_all_emails(self):
Examples:
| Delete All Emails |
"""
typ, mails = self._imap.uid('search', None, 'ALL')
self._mails = mails[0].split()

print("Deleting e-mails from ID: [{0}]".format(', '.join(map(str, self._mails))))

for mail in self._mails:
self.delete_email(mail)
self._imap.expunge()
Expand Down Expand Up @@ -135,6 +140,26 @@ def get_email_body(self, email_index):
decode('quoted-printable')
return body

def decode_email_body(self, body_email_encoded):
"""Returns the email body encoded on base64 decoded to a string UTF-8.

Arguments:
- ``body_email_encoded``: An string from the email body encoded on base64.

Examples:
| ${BODY} | Get Email Body | ${EMAIL_INDEX} |
| ${BODYDECODED} | Decode Email Body | ${BODY} |
| Log | ${BODY} |
"""
print("Deconding [%s] to string." % (body_email_encoded))

if not body_email_encoded.endswith("=="):
body_email_encoded = body_email_encoded + "=="

email_decoded = base64.b64decode(body_email_encoded)

return email_decoded.decode('UTF-8')

def get_links_from_email(self, email_index):
"""Returns all links found in the email body from given ``email_index``.

Expand Down