From 0daaf8153c5776694f490bf772e53bce7f379241 Mon Sep 17 00:00:00 2001 From: Mayara Ribeiro Fernandes Date: Mon, 19 Mar 2018 09:31:48 -0300 Subject: [PATCH] Fixes the keyword delete all emails and adds keyword that decodes a base64 to UTF-8 --- src/ImapLibrary/__init__.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/ImapLibrary/__init__.py b/src/ImapLibrary/__init__.py index 5dc9417..4544171 100644 --- a/src/ImapLibrary/__init__.py +++ b/src/ImapLibrary/__init__.py @@ -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() @@ -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``.