Exemple #1
0
    def __main(self):
        '''Main function which setups the whole login page'''

        curses.curs_set(0)
        self.__setup_layout("", "")
        key = 1
        email = ""
        password = ""
        utils.set_title(self.__stdscr, "LOGIN")
        utils.show_status_message(
            self.__stdscr,
            "Please read login instructions before logging in!!",
            time_to_show=2)
        while key != ord('q'):
            # If the key is e then make the email box active
            if key == ord('e'):
                email = self.__edit_box(email, "*" * len(password),
                                        self.__y_start + 1, self.__x_start + 2)

            # If the key is p then make the password box active
            elif key == ord('p'):
                password = self.__edit_box(email,
                                           "*" * len(password),
                                           self.__y_start + 5,
                                           self.__x_start + 2,
                                           isPass=True)

            elif key == ord('l'):
                # Authenticate
                self.__authenticate(email, password)

            # Show login instructions
            elif key == ord('i'):
                Instructions(self.__stdscr)

            # This is to refresh the layout when user resizes the terminal
            self.__set_values()
            self.__setup_layout(email, "*" * len(password))

            self.__stdscr.refresh()
            key = self.__stdscr.getch()
        sys.exit()
Exemple #2
0
    def __authenticate(self, email, password):
        '''To Authenticate using IMAP Server'''

        # Show the authenticating message
        utils.show_status_message(self.__stdscr,
                                  "Authenticating....",
                                  isLoading=True)
        try:
            email = email.strip()
            password = password.strip()
            self.__is_valid(email, password)
            # Authenticate using email and password, it throws exception if something went wrong
            IMAP(email, password)
            # Store in .bashbird directory
            cred = Credentials()
            cred.store_credentials(email, password)
            utils.show_status_message(self.__stdscr,
                                      "Authentication Successful",
                                      time_to_show=1)
            # Show main menu after authentication is completed
            main_menu = Main_Menu(self.__stdscr)
            main_menu.show()

        except Exception as e:
            utils.show_status_message(self.__stdscr, str(e), time_to_show=3)
Exemple #3
0
    def __set_confirm_email_bar(self):
        '''Setup confirm email bar'''

        h, w = self.__stdscr.getmaxyx()
        rectangle(self.__stdscr, h - 4, 0, h - 1, w - 2)
        title = " Confirm sending email ".upper()
        self.__stdscr.attron(curses.A_BOLD)
        self.__stdscr.addstr(h - 4, 1, title)
        self.__stdscr.attroff(curses.A_BOLD)
        self.__display_bottom_bar_menu()

        while 1:
            key = self.__stdscr.getch()

            if key == curses.KEY_UP and self.__curr_confirm_index != 0:
                self.__curr_confirm_index -= 1
            elif key == curses.KEY_DOWN and self.__curr_confirm_index != len(
                    self.__confirm_menu) - 1:
                self.__curr_confirm_index += 1

            # TODO: Do the functionality according to choice of user
            elif key == curses.KEY_ENTER or key in [10, 13]:
                if self.__curr_confirm_index == 0:
                    # Send mail using SMTP class and go back
                    # TODO: Check if subject or body is not empty
                    # Show sending mail status message
                    utils.show_status_message(self.__stdscr,
                                              "Sending email....",
                                              isLoading=True)
                    try:
                        self.__check_validation()
                        # Authenticate
                        smtp = SMTP(self.__email_from, self.__pass)
                        receiver_emails = self.__email_to.split(';')
                        data = smtp.add_attachment(
                            self.__subject, self.__body,
                            self.__attachments.split(';'))
                        smtp.send_email(receiver_emails, data=data)

                        # Show mail sent successfully message
                        utils.show_status_message(self.__stdscr,
                                                  "Mail sent Successfully",
                                                  time_to_show=1.5)

                        self.__is_mail_sent = True

                        # Quit from smtp server
                        smtp.quit()
                    except Exception as e:
                        utils.show_status_message(self.__stdscr, str(e), 2)

                self.__set_default_screen(self.__title, isMain=True)
                break

            self.__display_bottom_bar_menu()
Exemple #4
0
    def __download_attachment(self):
        '''To download attachments in mail'''

        try:
            utils.show_status_message(stdscr=self.__stdscr,
                                      msg="Downloading File.....",
                                      isLoading=True)
            msg = self.__imap.download_attachment(self.__index)
            utils.show_status_message(self.__stdscr, msg, time_to_show=3)
        except Exception as e:
            utils.show_status_message(self.__stdscr, str(e), time_to_show=2)
Exemple #5
0
    def __set_confirm_email_bar(self):
        '''Setup confirm email bar'''

        try:
            h, w = self.__stdscr.getmaxyx()
            self.__stdscr.clear()
            self.__set_email_list(isConfirm=True)

            while 1:
                key = self.__stdscr.getch()

                if key == curses.KEY_UP and self.__curr_confirm_index != 0:
                    self.__curr_confirm_index -= 1
                elif key == curses.KEY_DOWN and self.__curr_confirm_index != len(
                        self.__confirm_menu) - 1:
                    self.__curr_confirm_index += 1

                # TODO: Do the functionality according to choice of user
                elif key == curses.KEY_ENTER or key in [10, 13]:
                    if self.__curr_confirm_index == 0:
                        utils.show_status_message(self.__stdscr,
                                                  "Deleting email....",
                                                  isLoading=True)
                        try:
                            num = self.__imap.delete_email(self.__num -
                                                           self.__arr_position)

                            # Set the new mail count
                            self.__num = num

                            main_list_length = len(self.__main_list)

                            # Update the array
                            self.__main_list.pop(self.__arr_position)

                            if main_list_length - 1 == self.__arr_position:
                                self.__curr_position -= 1
                                self.__arr_position -= 1

                            # Show mail sent successfully message
                            utils.show_status_message(
                                self.__stdscr,
                                "Mail deleted Successfully",
                                time_to_show=1)
                        except Exception as e:
                            utils.show_status_message(self.__stdscr, str(e), 2)

                    self.__set_email_list()
                    break

                self.__set_email_list(isConfirm=True)
        except:
            utils.show_message(self.__stdscr,
                               "Something went wrong! Press 'q' to go back")
Exemple #6
0
    def __set_main_layout(self):
        '''To setup the main layout of page with scrollable behaviour'''

        try:
            key = 0
            arr_start = 0
            # Initially setup the list to get maximum mails that can be shown on single page
            self.__display_list = self.__main_list
            self.__max_len = self.__set_email_list()

            # Loop until key is 'q'
            while key != ord('q'):
                key = self.__stdscr.getch()

                # If the key pressed is up
                if key == curses.KEY_UP and self.__arr_position != 0:
                    self.__curr_position -= 1
                    self.__arr_position -= 1

                    # if the current position becomes -1 then show previous page.
                    if self.__curr_position == -1:
                        arr_start = arr_start - self.__max_len
                        self.__curr_position = self.__max_len - 1

                # IF the key pressed is down
                elif key == curses.KEY_DOWN:
                    if self.__arr_position != len(self.__main_list) - 1:
                        self.__curr_position += 1
                        self.__arr_position += 1

                        # It the current position becomes max_len then show next page.
                        if self.__curr_position >= self.__max_len:
                            arr_start = self.__arr_position

                            # Again reset the current position
                            self.__curr_position = 0

                # If d is pressed
                elif key == ord('d'):
                    self.__set_confirm_email_bar()

                # Load next 50 emails
                elif key == ord('f'):
                    self.__fetch_emails()

                # When enter is pressed
                elif key == curses.KEY_ENTER or key in [10, 13]:
                    # Show the email info component which will show details of email
                    EMAIL_INFO(
                        self.__stdscr,
                        (self.__num - self.__arr_position,
                         self.__main_list[self.__arr_position]['Subject'],
                         self.__main_list[self.__arr_position]['From'],
                         self.__main_list[self.__arr_position]['Date']),
                        self.__imap)

                # Calculate the end of display list
                arr_end = min(arr_start + self.__max_len,
                              len(self.__main_list))

                # Show the email list
                self.__display_list = self.__main_list[arr_start:arr_end]
                self.__max_len = max(self.__set_email_list(), self.__max_len)

                # Show the message if there are no more mails fetched
                if self.__is_end:
                    utils.show_status_message(
                        self.__stdscr,
                        "No more emails available to fetch!!",
                        time_to_show=2)
                    self.__is_end = False

        except Exception as e:
            msg = "Something went wrong! Press 'q' to go back"
            utils.show_message(self.__stdscr, msg)