def search_active_words()

in workmail-chat-bot-python/src/utils.py [0:0]


def search_active_words(subject, active_words):
    """
    This method looks for active_words in subject in a case-insensitive fashion

    Parameters
    ----------
    subject: string, required
        email subject
    active_words: string, required
        active words represented in a comma delimited fashion

    Returns
    -------
    True
        If any active words were found in subject or,
        No active words are configured
    False
        If no active words were found in subject
    """
    if not active_words:
        return True
    else:
        # Convert to lower case words by splitting active_words. For example: 'Hello  ,  World,' is generated as ('hello','world').
        lower_words = [word.strip().lower() for word in filter(None, active_words.split(','))]
        # Convert subject to lower case in order to do a case insensitive lookup.
        subject_lower = subject.lower()
        for word in lower_words:
            if word in subject_lower:
                return True
    return False