Integrations/MicrosoftGraphMail/MicrosoftGraphMail.py
def build_mail_object(raw_response: Union[dict, list], user_id: str, get_body: bool = False) -> Union[dict, list]:
    """Building mail entry context
    Getting a list from build_mail_object

    Args:
        user_id (str): user id of the mail
        get_body (bool): should get body
        raw_response (dict or list): list of pages

    Returns:
        dict or list: output context
    """

    def build_mail(given_mail: dict) -> dict:
        """

        Args:
            given_mail (dict):

        Returns:
            dict:
        """
        # Dicts
        mail_properties = {
            'ID': 'id',
            'Created': 'createdDateTime',
            'LastModifiedTime': 'lastModifiedDateTime',
            'ReceivedTime': 'receivedDateTime',
            'SendTime': 'sentDateTime',
            'Categories': 'categories',
            'HasAttachments': 'hasAttachments',
            'Subject': 'subject',
            'IsDraft': 'isDraft',
            'Headers': 'internetMessageHeaders',
            'Flag': 'flag',
            'Importance': 'importance',
        }

        contact_properties = {
            'Sender': 'sender',
            'From': 'from',
            'CCRecipients': 'ccRecipients',
            'BCCRecipients': 'bccRecipients',
            'ReplyTo': 'replyTo'
        }

        # Create entry properties
        entry = {k: given_mail.get(v) for k, v in mail_properties.items()}

        # Create contacts properties
        entry.update(
            {k: build_contact(given_mail.get(v)) for k, v in contact_properties.items()}  # type: ignore
        )

        if get_body:
            entry['Body'] = given_mail.get('body', {}).get('content')
        entry['UserID'] = user_id
        return entry

    def build_contact(contacts: Union[dict, list, str]) -> object:
        """Building contact object

        Args:
            contacts (list or dict or str):

        Returns:
            dict or list[dict] or str or None: describing contact
        """
        if contacts:
            if isinstance(contacts, list):
                return [build_contact(contact) for contact in contacts]
            elif isinstance(contacts, dict):
                email = contacts.get('emailAddress')
                if email and isinstance(email, dict):
                    return {
                        'Name': email.get('name'),
                        'Address': email.get('address')
                    }
        return None

    mails_list = list()
    if isinstance(raw_response, list):
        for page in raw_response:
            # raw_response can be a list containing multiple pages or one response
            # if value in page, we got
            value = page.get('value')
            if value:
                for mail in value:
                    mails_list.append(build_mail(mail))
            else:
                mails_list.append(build_mail(page))
    elif isinstance(raw_response, dict):
        return build_mail(raw_response)
    return mails_list
Building mail entry context
    Getting a list from build_mail_object

    Args:
        user_id (str): user id of the mail
        get_body (bool): should get body
        raw_response (dict or list): list of pages

    Returns:
        dict or list: output context
    
Building mail entry context
Getting a list from build_mail_object
Building mail entry context Getting a list from build_mail_object
def build_mail_object(raw_response: Union[dict, list], user_id: str, get_body: bool = False) -> Union[dict, list]:
    def build_mail(given_mail: dict) -> dict:
        mail_properties = {
            'ID': 'id',
            'Created': 'createdDateTime',
            'LastModifiedTime': 'lastModifiedDateTime',
            'ReceivedTime': 'receivedDateTime',
            'SendTime': 'sentDateTime',
            'Categories': 'categories',
            'HasAttachments': 'hasAttachments',
            'Subject': 'subject',
            'IsDraft': 'isDraft',
            'Headers': 'internetMessageHeaders',
            'Flag': 'flag',
            'Importance': 'importance',
        }
        contact_properties = {
            'Sender': 'sender',
            'From': 'from',
            'CCRecipients': 'ccRecipients',
            'BCCRecipients': 'bccRecipients',
            'ReplyTo': 'replyTo'
        }
        entry = {k: given_mail.get(v) for k, v in mail_properties.items()}
        entry.update(
            {k: build_contact(given_mail.get(v)) for k, v in contact_properties.items()}  
        )
        if get_body:
            entry['Body'] = given_mail.get('body', {}).get('content')
        entry['UserID'] = user_id
        return entry
    def build_contact(contacts: Union[dict, list, str]) -> object:
        if contacts:
            if isinstance(contacts, list):
                return [build_contact(contact) for contact in contacts]
            elif isinstance(contacts, dict):
                email = contacts.get('emailAddress')
                if email and isinstance(email, dict):
                    return {
                        'Name': email.get('name'),
                        'Address': email.get('address')
                    }
        return None
    mails_list = list()
    if isinstance(raw_response, list):
        for page in raw_response:
            value = page.get('value')
            if value:
                for mail in value:
                    mails_list.append(build_mail(mail))
            else:
                mails_list.append(build_mail(page))
    elif isinstance(raw_response, dict):
        return build_mail(raw_response)
    return mails_list
def build_mail_object ( raw_response : Union [ dict , list ] , user_id : str , get_body : bool = False ) -> Union [ dict , list ] : def build_mail ( given_mail : dict ) -> dict : """

        Args:
            given_mail (dict):

        Returns:
            dict:
        """ mail_properties = { 'ID' : 'id' , 'Created' : 'createdDateTime' , 'LastModifiedTime' : 'lastModifiedDateTime' , 'ReceivedTime' : 'receivedDateTime' , 'SendTime' : 'sentDateTime' , 'Categories' : 'categories' , 'HasAttachments' : 'hasAttachments' , 'Subject' : 'subject' , 'IsDraft' : 'isDraft' , 'Headers' : 'internetMessageHeaders' , 'Flag' : 'flag' , 'Importance' : 'importance' , } contact_properties = { 'Sender' : 'sender' , 'From' : 'from' , 'CCRecipients' : 'ccRecipients' , 'BCCRecipients' : 'bccRecipients' , 'ReplyTo' : 'replyTo' } entry = { k : given_mail . get ( v ) for k , v in mail_properties . items ( ) } entry . update ( { k : build_contact ( given_mail . get ( v ) ) for k , v in contact_properties . items ( ) } ) if get_body : entry [ 'Body' ] = given_mail . get ( 'body' , { } ) . get ( 'content' ) entry [ 'UserID' ] = user_id return entry def build_contact ( contacts : Union [ dict , list , str ] ) -> object : """Building contact object

        Args:
            contacts (list or dict or str):

        Returns:
            dict or list[dict] or str or None: describing contact
        """ if contacts : if isinstance ( contacts , list ) : return [ build_contact ( contact ) for contact in contacts ] elif isinstance ( contacts , dict ) : email = contacts . get ( 'emailAddress' ) if email and isinstance ( email , dict ) : return { 'Name' : email . get ( 'name' ) , 'Address' : email . get ( 'address' ) } return None mails_list = list ( ) if isinstance ( raw_response , list ) : for page in raw_response : value = page . get ( 'value' ) if value : for mail in value : mails_list . append ( build_mail ( mail ) ) else : mails_list . append ( build_mail ( page ) ) elif isinstance ( raw_response , dict ) : return build_mail ( raw_response ) return mails_list
Building mail entry context
Getting a list from build_mail_object
Building mail entry context Getting a list from build_mail_object
"""Building mail entry context
    Getting a list from build_mail_object

    Args:
        user_id (str): user id of the mail
        get_body (bool): should get body
        raw_response (dict or list): list of pages

    Returns:
        dict or list: output context
    """ """

        Args:
            given_mail (dict):

        Returns:
            dict:
        """ # Dicts # Create entry properties # Create contacts properties # type: ignore """Building contact object

        Args:
            contacts (list or dict or str):

        Returns:
            dict or list[dict] or str or None: describing contact
        """ # raw_response can be a list containing multiple pages or one response # if value in page, we got
dict or list: output context
dict or list : output context
raw_response
Union[dict, list]
list of pages
list of pages
user_id
str
user id of the mail
user id of the mail
get_body
bool
should get body
should get body