Skip to content
This repository was archived by the owner on Sep 27, 2021. It is now read-only.
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions src/ImapLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down