import re


def prune_protected(mailboxes, ns):
    """ Remove protected folders from a list of mailboxes

    Exchange has several protected folders that are used for non-mail
    purposes, but still appear in the list. Therefore, we want to exclude
    these folders to prevent reading non-mail items.

    Args:
        [<str>]: list of mailboxes - Must not include surrounding quotes
        <str>: namespace for the account

    Returns:
        [<str>]: list of mailboxes with protected folders removed
    """
    protected = ['Calendar', 'Contacts', 'Tasks', 'Journal', 'Deleted Items']
    flagged = []

    for folder in protected:
        pattern = "(?:{})?{}\\b".format(ns,folder)
        for mailbox in mailboxes:
            result = re.match(pattern, mailbox, flags=re.IGNORECASE)
            if result:
                flagged.append(mailbox)
    
    return [mailbox for mailbox in mailboxes if mailbox not in flagged]