From c39a24f80e8b500811e40ff06ddaf36557c18f75 Mon Sep 17 00:00:00 2001 From: "kevingaspard@koshie.fr" Date: Fri, 27 Sep 2013 14:44:39 +0200 Subject: [PATCH] Add textOnly paramater to get_links_from_email Useful when mail is format in text only --- README.rst | 1 + src/ImapLibrary/__init__.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index b41fa47..42294ac 100644 --- a/README.rst +++ b/README.rst @@ -51,6 +51,7 @@ These keyword actions are available:: Arguments: - mailNumber: is the index number of the mail to open + - textOnly: to use if mail is in text format Open Link from Mail: Find a link in an email body and open the link. Returns the links' html. diff --git a/src/ImapLibrary/__init__.py b/src/ImapLibrary/__init__.py index 1f28772..5b0137f 100644 --- a/src/ImapLibrary/__init__.py +++ b/src/ImapLibrary/__init__.py @@ -48,14 +48,19 @@ def wait_for_mail(self, fromEmail=None, toEmail=None, status=None, time.sleep(10) raise AssertionError("No mail received within time") - def get_links_from_email(self, mailNumber): + def get_links_from_email(self, mailNumber, textOnly=False): ''' Finds all links in an email body and returns them `mailNumber` is the index number of the mail to open + + `textOnly` to use if the mail is in text format ''' body = self.get_email_body(mailNumber) - return re.findall(r'href=[\'"]?([^\'" >]+)', body) + if not textOnly: + return re.findall(r'href=[\'"]?([^\'" >]+)', body) + else: + return re.findall('(https?://\\S+)', body) def open_link_from_mail(self, mailNumber, linkNumber=0): """