Example #1
0
def outlook_update_mail(access_token, mail_subject, forward_to, message_id_value, updated_message):

    try:
        account = pyOutlook.OutlookAccount(access_token)

        email_subjects = account.get_messages()

        #print(email_subjects)

        index = 0

        count = 0

        #import pdb; pdb.set_trace()

        for i in range(0, len(email_subjects)):

            print(str(email_subjects[i]))
        
            if str(email_subjects[i]) == str(mail_subject):

                print(email_subjects[i].message_id)

                if str(email_subjects[i].message_id) == str(message_id_value):

                    print("Inside ifffffffff")

                    index = i

                    break

                else:
                    print("Inside elseeeeeeeeeeeeeeeee")
                    count = count + 1

            else:
                count = count + 1

        if count == len(email_subjects):

            return {'status': 'Fail', 'error': 'Email with the subject '+ mail_subject +' not found'}

        else:

            email_subjects[index].forward([forward_to], updated_message)

            return {'status': 'Pass', 'error': None}

    except pyOutlook.internal.errors.AuthError as error:
        return {'status': 'Fail', 'error': 'Authentication Failed'}

    except pyOutlook.internal.errors.APIError as error:
        return {'status': 'Fail', 'error': 'API error occurred'}

    except Exception as error:
        return {'status': 'Fail', 'error': str(error)}
Example #2
0
def outlook_delete_mail(access_token, mail_subject, message_id_value):

    try:

        account = pyOutlook.OutlookAccount(access_token)

        messages = account.get_messages()

        index = 0

        count = 0

        ##import pdb;pdb.set_trace()

        for i in range(0, len(messages)):

            if str(messages[i]) == str(mail_subject):

                if str(messages[i].message_id) == str(message_id_value):

                    index = i

                    break

                else:
                    count = count + 1

            else:

                count = count + 1

        if count == len(messages):

            return {
                'status': 'Fail',
                'error':
                'Email with the subject ' + mail_subject + ' not found'
            }

        else:

            messages[index].delete()

            return {'status': 'Pass', 'error': None}

        return {'status': 'Pass', 'error': None}

    except pyOutlook.internal.errors.AuthError as error:
        return {'status': 'Fail', 'error': 'Authentication Failed'}

    except pyOutlook.internal.errors.APIError as error:
        return {'status': 'Fail', 'error': 'API error occurred'}

    except Exception as error:
        return {'status': 'Fail', 'error': str(error)}
Example #3
0
def outlook_reply_mail(access_token, mail_subject, reply_message,
                       message_id_value):

    try:
        account = pyOutlook.OutlookAccount(access_token)

        email_subjects = account.get_messages()

        index = 0

        count = 0

        for i in range(0, len(email_subjects)):

            if str(email_subjects[i]) == str(mail_subject):

                print(str(email_subjects[i]))
                print(str(email_subjects[i].message_id))

                if str(email_subjects[i].message_id) == str(message_id_value):

                    index = i

                    break

                else:
                    count = count + 1

            else:
                count = count + 1

        if count == len(email_subjects):

            return {
                'status': 'Fail',
                'error':
                'Email with the subject ' + mail_subject + ' not found'
            }

        else:

            email_subjects[index].reply(reply_message)

            return {'status': 'Pass', 'error': None}

    except pyOutlook.internal.errors.AuthError as error:
        return {'status': 'Fail', 'error': 'Authentication Failed'}

    except pyOutlook.internal.errors.APIError as error:
        return {'status': 'Fail', 'error': 'API error occurred'}

    except Exception as error:
        return {'status': 'Fail', 'error': str(error)}
Example #4
0
def outlook_get_folders(access_token):

    try:
        account = pyOutlook.OutlookAccount(access_token)

        all_folders = account.get_folders()

        return {'status': 'Pass', 'folders': all_folders, 'error': None}

    except pyOutlook.internal.errors.AuthError as error:
        return {'status': 'Fail', 'error': 'Authentication failed'}

    except pyOutlook.internal.errors.APIError as error:
        return {'status': 'Fail', 'error': 'API error occurred'}

    except Exception as error:
        return {'status': 'Fail', 'error': str(error)}
Example #5
0
def outlook_get_messages(access_token):

    try:
        account = pyOutlook.OutlookAccount(access_token)

        inbox_messages = account.get_messages()

        sent_messages = account.sent_messages()

        return {'status': 'Pass', 'inbox_messages': inbox_messages, 'sent_messages': sent_messages, 'error': None}

    except pyOutlook.internal.errors.AuthError as error:
        return {'status': 'Fail', 'error': 'Authentication failed'}

    except pyOutlook.internal.errors.APIError as error:
        return {'status': 'Fail', 'error': 'API error occurred'}

    except Exception as error:
        return {'status': 'Fail', 'error': str(error)}
Example #6
0
def outlook_create_folder(access_token, folder_name, child_folder_name):

    try:
        account = pyOutlook.OutlookAccount(access_token)

        folders = account.get_folders()

        index = 0

        count = 0

        for i in range(0, len(folders)):

            if str(folders[i]) == folder_name:

                index = i

                break

            else:
                count = count + 1

        if count == len(folders):
            return {
                'status': 'Fail',
                'error':
                'The folder with the name ' + folder_name + ' not found'
            }

        else:
            folders[index].create_child_folder(child_folder_name)

            return {'status': 'Pass', 'error': None}

    except pyOutlook.internal.errors.AuthError as error:
        return {'status': 'Fail', 'error': 'Authentication failed'}

    except pyOutlook.internal.errors.APIError as error:
        return {'status': 'Fail', 'error': 'API error occurred'}

    except Exception as error:
        return {'status': 'Fail', 'error': str(error)}
Example #7
0
def outlook_move_folder(access_token, folder_1, folder_2):

    try:
        account = pyOutlook.OutlookAccount(access_token)

        folders = account.get_folders()

        folder_index_1 = 0

        count_1 = 0

        folder_index_2 = 0

        count_2 = 0

        for i in range(0, len(folders)):

            if str(folders[i]) == folder_1:

                folder_index_1 = i

                break

            else:
                count_1 = count_1 + 1

        if count_1 == len(folders):
            return {
                'status': 'Fail',
                'error': 'The folder with the name ' + folder_1 + ' not found'
            }

        for j in range(0, len(folders)):

            if str(folders[j]) == folder_2:

                folder_index_2 = j

                break

            else:
                count_2 = count_2 + 1

        if count_2 == len(folders):
            return {
                'status': 'Fail',
                'error': 'The folder with the name ' + folder_2 + ' not found'
            }

        else:
            folders[folder_index_1].move_into(folders[folder_index_2])

            return {'status': 'Pass', 'error': None}

    except pyOutlook.internal.errors.AuthError as error:
        return {'status': 'Fail', 'error': 'Authentication failed'}

    except pyOutlook.internal.errors.APIError as error:
        return {'status': 'Fail', 'error': 'API error occurred'}

    except Exception as error:
        return {'status': 'Fail', 'error': str(error)}
Example #8
0
def outlook_move_mail(access_token, mail_subject, move_folder,
                      message_id_value):

    try:
        account = pyOutlook.OutlookAccount(access_token)

        messages = account.get_messages()

        mail_index = 0

        mail_count = 0

        for i in range(0, len(messages)):

            if str(messages[i]) == mail_subject:

                if str(messages[i].message_id) == str(message_id_value):

                    mail_index = i

                    break

                else:
                    mail_count = mail_count + 1

            else:

                mail_count = mail_count + 1

        if mail_count == len(messages):

            return {
                'status': 'Fail',
                'error':
                'Email with the subject ' + mail_subject + ' not found'
            }

        folders = account.get_folders()

        folder_index = 0

        folder_count = 0

        for i in range(0, len(folders)):

            if str(folders[i]) == move_folder:

                folder_index = i

                break

            else:

                folder_count = folder_count + 1

        if folder_count == len(folders):

            return {
                'status': 'Fail',
                'error': 'Folder with the name ' + move_folder + ' not found'
            }

        else:

            messages[mail_index].move_to(folders[folder_index])

            return {'status': 'Pass', 'error': None}

    except pyOutlook.internal.errors.AuthError as error:
        return {'status': 'Fail', 'error': 'Authentication Failed'}

    except pyOutlook.internal.errors.APIError as error:
        return {'status': 'Fail', 'error': 'API error occurred'}

    except Exception as error:
        return {'status': 'Fail', 'error': str(error)}