From 32bd12f38f053a28e629b3f9453d1b61bb9c2caa Mon Sep 17 00:00:00 2001 From: Johannes Hammersen Date: Wed, 30 Oct 2013 18:48:36 +0100 Subject: [PATCH 1/2] Add Keyword: get email subject Added new Keyword to get the subject of an email. --- src/ImapLibrary/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ImapLibrary/__init__.py b/src/ImapLibrary/__init__.py index 1f28772..ba5d28b 100644 --- a/src/ImapLibrary/__init__.py +++ b/src/ImapLibrary/__init__.py @@ -3,6 +3,7 @@ import imaplib import time import urllib2 +from email.parser import HeaderParser THIS_DIR = os.path.dirname(os.path.abspath(__file__)) execfile(os.path.join(THIS_DIR, 'version.py')) @@ -101,6 +102,17 @@ def get_email_body(self, mailNumber): body = self.imap.fetch(mailNumber, '(BODY[TEXT])')[1][0][1].decode('quoted-printable') return body + def get_email_subject(self, mailNumber): + """ + Returns an email subject + + `mailNumber` is the index number of the mail to open + """ + header_data = self.imap.fetch(mailNumber,'(BODY[HEADER.FIELDS (SUBJECT)])')[1][0][1] + parser = HeaderParser() + data = parser.parsestr(header_data) + return data['Subject'] + def _criteria(self, fromEmail, toEmail, status): crit = [] if fromEmail: From 21a8c80518c41a841f1703b8991604bc949ab20a Mon Sep 17 00:00:00 2001 From: Johannes Hammersen Date: Thu, 21 Nov 2013 18:37:55 +0100 Subject: [PATCH 2/2] make ssl authentication optional --- src/ImapLibrary/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ImapLibrary/__init__.py b/src/ImapLibrary/__init__.py index ba5d28b..646fc96 100644 --- a/src/ImapLibrary/__init__.py +++ b/src/ImapLibrary/__init__.py @@ -16,14 +16,15 @@ class ImapLibrary(object): ROBOT_LIBRARY_VERSION = VERSION ROBOT_LIBRARY_SCOPE = 'GLOBAL' - port = 993 - - def open_mailbox(self, server, user, password): + def open_mailbox(self, server, user, password, ssl=True): """ Open the mailbox on a mail server with a valid authentication. """ - self.imap = imaplib.IMAP4_SSL(server, self.port) + if ssl == True: + self.imap = imaplib.IMAP4_SSL(server, 993) + else: + self.imap = imaplib.IMAP4(server, 143) self.imap.login(user, password) self.imap.select()