Beispiel #1
0
    def __fetch_body(self, index):
        '''To fetch body of emails using imap object'''

        try:
            # start loading
            loading = Loading(self.__stdscr)
            loading.start()
            response = self.__imap.fetch_text_body(self.__index)
            self.__body = response['body']
            self.__is_attachment_present = response['is_attachment']
            self.__attachment_filenames = response['filename']

            # If attachment is_present add it in options array
            if response['is_attachment']:
                self.options.insert(0, {
                    'key': 'D',
                    'msg': 'Download Attachment'
                })
            loading.stop()
        except Exception as e:
            # To show the error message
            loading.stop()
            self.__is_error = True
            msg = "Something went wrong! Press 'q' to go back"
            self.__show_message(msg)
Beispiel #2
0
    def __init__(self, stdscr):
        self.__stdscr = stdscr
        loading = Loading(stdscr)
        loading.start()

        try:
            cred = Credentials()
            flag, email, password = cred.get_credentials()
            if not flag:
                raise Exception("Invalid credentials")
            imap = IMAP(email, password)
            folders = imap.get_mailboxes()
            options = []
            for item in folders:
                options.append({
                    'title': item.replace('"', ''),
                    'Function': EMAIL_LIST,
                    'args': (item, imap)
                })
            options.append({'title': "Back", 'Function': None, 'args': None})
            loading.stop()
            Menu(self.__stdscr, options, "Folders")

        except:
            loading.stop()
            utils.show_message(self.__stdscr,
                               "Something went wrong! Press 'q' to go back")
Beispiel #3
0
    def __fetch_emails(self):
        '''To fetch emails from imap server using IMAP class'''

        try:
            # Start loading until mails are fetched
            loading = Loading(self.__stdscr)
            loading.start()
            # Select particular mailbox
            num = self.__imap.select_mailbox(self.__directory_name)

            if num == 0:
                loading.stop()
                self.__is_error = True
                msg = "Nothing in " + \
                    self.__directory_name.replace(
                        '"', '') + "!! Press 'q' to go back"
                utils.show_message(self.__stdscr, msg)
                return
            self.__num = num

            # Fetch atleast 30 mails if total mails are less than that then fetch total number of mails
            count = min(self.__num - 1, 30)
            if (self.__num - self.__fetched_emails) > 0:
                emails = self.__imap.fetch_email_headers(
                    self.__num - self.__fetched_emails, count)
                self.__fetched_emails += count + 1
                self.__main_list.extend(emails)
                self.emails = emails
            else:
                self.__is_end = True

            loading.stop()
        except Exception as e:
            # To show the error message
            loading.stop()
            self.__is_error = True
            msg = "Something went wrong! Press 'q' to go back"
            utils.show_message(self.__stdscr, msg)