🔍 Code Extractor

class ItemBody

Maturity: 47

A data class representing the body content of an item (message, event, or group post) with content and content type properties.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/item_body.py
Lines:
4 - 18
Complexity:
simple

Purpose

ItemBody encapsulates the body content of various Office 365 items such as messages, events, or group posts. It stores both the actual content text and its format type (text or HTML). This class inherits from ClientValue, making it compatible with Office 365 API serialization and deserialization patterns. It provides a simple container for managing item body data with proper type specification.

Source Code

class ItemBody(ClientValue):
    """Represents properties of the body of an item, such as a message, event or group post."""

    def __init__(self, content=None, content_type="Text"):
        """

        :param str content: The content of the item.
        :param str content_type: The type of the content. Possible values are text and html.
        """
        super(ItemBody, self).__init__()
        self.content = content
        self.contentType = content_type

    def __repr__(self):
        return self.content

Parameters

Name Type Default Kind
bases ClientValue -

Parameter Details

content: The actual text content of the item body. Can be plain text or HTML markup depending on the content_type. Defaults to None if not provided.

content_type: Specifies the format of the content. Accepts 'Text' for plain text or 'html' for HTML-formatted content. Defaults to 'Text' if not specified.

Return Value

Instantiation returns an ItemBody object with content and contentType attributes set. The __repr__ method returns the string representation of the content itself, making the object display its content when printed or converted to string.

Class Interface

Methods

__init__(self, content=None, content_type='Text') -> None

Purpose: Initializes an ItemBody instance with content and content type

Parameters:

  • content: The text or HTML content of the item body. Defaults to None.
  • content_type: The format type of the content, either 'Text' or 'html'. Defaults to 'Text'.

Returns: None - constructor initializes the instance

__repr__(self) -> str

Purpose: Returns a string representation of the ItemBody object, which is the content itself

Returns: The content string of the item body

Attributes

Name Type Description Scope
content str or None Stores the actual text or HTML content of the item body instance
contentType str Stores the format type of the content ('Text' or 'html') instance

Dependencies

  • office365

Required Imports

from office365.runtime.client_value import ClientValue

Usage Example

from office365.runtime.client_value import ClientValue

class ItemBody(ClientValue):
    def __init__(self, content=None, content_type="Text"):
        super(ItemBody, self).__init__()
        self.content = content
        self.contentType = content_type
    
    def __repr__(self):
        return self.content

# Create a plain text item body
text_body = ItemBody(content="Hello, this is a plain text message", content_type="Text")
print(text_body)  # Output: Hello, this is a plain text message
print(text_body.content)  # Output: Hello, this is a plain text message
print(text_body.contentType)  # Output: Text

# Create an HTML item body
html_body = ItemBody(
    content="<p>Hello, this is an <strong>HTML</strong> message</p>",
    content_type="html"
)
print(html_body)  # Output: <p>Hello, this is an <strong>HTML</strong> message</p>
print(html_body.contentType)  # Output: html

# Create with default content type
default_body = ItemBody(content="Default text content")
print(default_body.contentType)  # Output: Text

Best Practices

  • Always specify the correct content_type ('Text' or 'html') to match the actual content format
  • When using HTML content, ensure proper HTML escaping to prevent injection issues
  • The content attribute can be None, so check for None before processing the content
  • This class is immutable after creation - create a new instance if you need to change content or content type
  • The __repr__ method returns the content directly, which is useful for debugging but may expose sensitive information in logs
  • Use 'Text' for plain text content and 'html' for HTML-formatted content - case matters for content_type
  • This class inherits from ClientValue, so it can be serialized/deserialized by the Office 365 API client automatically

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class BodyType 61.8% similar

    A simple enumeration-style class that defines constants for different body content types in HTTP requests or responses.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/body_type.py
  • class TrainingEventsContent 60.8% similar

    TrainingEventsContent is a data class that inherits from ClientValue, representing training events content in the Office365 API context.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/security/attacksimulations/event.py
  • class AttachmentItem 60.8% similar

    A data class representing metadata attributes of an attachment item, including its type, name, and size.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/attachment_item.py
  • class Post 59.6% similar

    Represents an individual Post item within a conversationThread entity in the Office 365 API, inheriting from the Entity base class.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/post.py
  • class ItemAttachment 59.3% similar

    A class representing an attachment that contains an Outlook item (contact, event, or message) attached to a user event, message, or post.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/mail/attachments/item.py
← Back to Browse