Example #1
0
def get_unread():
    mails = []
    username = backend_api.get_user_info('mail')
    passw = backend_api.get_user_info('password')
    imapserver = backend_api.get_user_info('imapserver')
    with Imbox(
            imapserver,
            username=username,
            password=passw,
            ssl=True,
            ssl_context=None,
            starttls=False,
    ) as imbox:

        logging.info('Account informations correct. Connected.')

        # Gets all messages after the day x
        all_inbox_messages = imbox.messages(unread=True)
        unread_msgs = imbox.messages(unread=True)
        unread_uid = []
        for uid, msg in unread_msgs:
            unread_uid.append(uid.decode())
        logging.debug('Gathered all inbox messages')

        for uid, message in reversed(all_inbox_messages):
            mail = mail_parsing(uid, message, unread_uid, 'Unread')
            mails.append(mail)

        return mails
Example #2
0
    def __init__(self):
        self.userId = backend_api.get_user_id()
        self.userName = backend_api.get_user_info("mail")
        self.password = backend_api.get_user_info("password")
        self.server = backend_api.get_user_server_config("server_imap")
        logger.debug("Getting userId: " + str(self.userId))
        logger.debug("Getting mail: " + self.userName)
        logger.debug("Getting password: ***")
        logger.debug("Getting imap address: " + self.server)
        # Getting the imap configuration

        ## Converting
        if backend_api.get_user_server_config("ssl") == 1:
            self.ssl = True
        else:
            self.ssl = False

        if backend_api.get_user_server_config("ssl_context") == 1:
            self.ssl_context = True
        else:
            self.ssl_context = None

        if backend_api.get_user_server_config("starttls") == 1:
            self.starttls = True
        else:
            self.starttls = False

        logger.debug("Getting ssl setting: " + str(self.ssl))
        logger.debug("Getting ssl_context: " + str(self.ssl_context))
        logger.debug("Getting srtattls setting: " + str(self.starttls))
Example #3
0
def get_deleted():
    mails = []
    username = backend_api.get_user_info("mail")
    passw = backend_api.get_user_info("password")
    imapserver = backend_api.get_user_info("imapserver")
    with Imbox(
            imapserver,
            username=username,
            password=passw,
            ssl=True,
            ssl_context=None,
            starttls=False,
    ) as imbox:

        logging.info("Account information correct. Connected.")

        # Gets all messages after the day x
        all_inbox_messages = imbox.messages(folder="Deleted")
        unread_msgs = imbox.messages(unread=True)
        unread_uid = []
        for uid, msg in unread_msgs:
            unread_uid.append(uid.decode())
        logging.debug("Gathered all inbox messages")

        for uid, message in reversed(all_inbox_messages):
            mail = mail_parsing(uid, message, unread_uid)
            mails.append(mail)

        return mails
Example #4
0
def get_mails(year, month, day):
    # Download all the mails from the DB
    # backend_api.get_mails(year,month,day)
    # mails = db_api.get("emails","*","WHERE datetimes = "+datetime.date(year, month, day))

    mails = []
    username = backend_api.get_user_info("mail")
    passw = backend_api.get_user_info("password")
    imapserver = backend_api.get_user_info("imapserver")
    with Imbox(
            imapserver,
            username=username,
            password=passw,
            ssl=True,
            ssl_context=None,
            starttls=False,
    ) as imbox:

        logging.info("Account informations correct. Connected.")

        # Gets all messages after the day x
        all_inbox_messages = imbox.messages(
            date__on=datetime.date(year, month, day))
        unread_msgs = imbox.messages(unread=True)
        unread_uid = []
        for uid, msg in unread_msgs:
            unread_uid.append(uid.decode())
        logging.debug("Gathered all inbox messages")

        for uid, message in reversed(all_inbox_messages):
            mail = mail_parsing(uid, message, unread_uid)
            mails.append(mail)

        return mails
Example #5
0
def mark_as_seen(uid):
    username = backend_api.get_user_info("mail")
    passw = backend_api.get_user_info("password")
    imapserver = backend_api.get_user_info("imapserver")
    with Imbox(
            imapserver,
            username=username,
            password=passw,
            ssl=True,
            ssl_context=None,
            starttls=False,
    ) as imbox:
        imbox.mark_seen(uid)
Example #6
0
def get_number_unread():
    username = backend_api.get_user_info("mail")
    passw = backend_api.get_user_info("password")
    imapserver = backend_api.get_user_info("imapserver")
    with Imbox(
            imapserver,
            username=username,
            password=passw,
            ssl=True,
            ssl_context=None,
            starttls=False,
    ) as imbox:
        logging.info("Account informations correct. Connected.")

        # Gets all messages after the day x

        # to get the mails of today:
        all_unread_message = imbox.messages(unread=True)
        return len(all_unread_message)
Example #7
0
def send_mail(account, to, subject, body, attach):
    # get user input
    # input sender email address and password:
    from_address = backend_api.get_user_info('mail')
    password = backend_api.get_user_info('password')
    # input receiver email address.
    to_address = to
    # input smtp server ip address:
    smtp_server = backend_api.get_user_info('smtpserver')

    # email object that has multiple part:
    msg = MIMEMultipart()
    msg['From'] = from_address
    msg['To'] = to_address
    msg['Subject'] = Header(subject, 'utf-8').encode()

    # attache a MIMEText object to save email content
    msg_content = MIMEText(body, 'plain', 'utf-8')
    msg.attach(msg_content)

    # to add an attachment is just add a MIMEBase object to read a picture locally.
    # extracting list of attach from the attach object (vector)
    """with open('/Users/jerry/img1.png', 'rb') as f:
        # set attachment mime and file name, the image type is png
        mime = MIMEBase('image', 'png', filename='img1.png')
        # add required header data:
        mime.add_header('Content-Disposition', 'attachment', filename='img1.png')
        mime.add_header('X-Attachment-Id', '0')
        mime.add_header('Content-ID', '<0>')
        # read attachment file content into the MIMEBase object
        mime.set_payload(f.read())
        # encode with base64
        encoders.encode_base64(mime)
        # add MIMEBase object to MIMEMultipart object
        msg.attach(mime)
        
        'smtp-mail.outlook.com'
        """

    mail_server = smtplib.SMTP(backend_api.get_user_info('imapserver'), 587)
    mail_server.ehlo()
    mail_server.starttls()
    mail_server.ehlo()
    mail_server.login(backend_api.get_user_info('mail'),
                      backend_api.get_user_info('password'))
    mail_server.sendmail(account, to, msg.as_string())
    mail_server.close()