Attachment

class O365.utils.attachment.AttachableMixin(attachment_name_property=None, attachment_type=None)[source]

Bases: object

__init__(attachment_name_property=None, attachment_type=None)[source]

Defines the functionality for an object to be attachable. Any object that inherits from this class will be attachable (if the underlying api allows that)

to_api_data()[source]

Returns a dict to communicate with the server

Return type:

dict

property attachment_name

Name of the attachment

Getter:

get attachment name

Setter:

set new name for the attachment

Type:

str

property attachment_type

Type of attachment

Return type:

str

class O365.utils.attachment.BaseAttachment(attachment=None, *, parent=None, **kwargs)[source]

Bases: ApiComponent

BaseAttachment class is the base object for dealing with attachments

__init__(attachment=None, *, parent=None, **kwargs)[source]

Creates a new attachment, optionally from existing cloud data

Parameters:
  • attachment (dict or str or Path or list[str] or AttachableMixin) – attachment data (dict = cloud data, other = user data)

  • parent (BaseAttachments) – the parent Attachments

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

attach(api_object, on_cloud=False)[source]

Attach this attachment to an existing api_object. This BaseAttachment object must be an orphan BaseAttachment created for the sole purpose of attach it to something and therefore run this method.

Parameters:
  • api_object – object to attach to

  • on_cloud – if the attachment is on cloud or not

Returns:

Success / Failure

Return type:

bool

save(location=None, custom_name=None)[source]

Save the attachment locally to disk

Parameters:
  • location (str) – path string to where the file is to be saved.

  • custom_name (str) – a custom name to be saved as

Returns:

Success / Failure

Return type:

bool

to_api_data()[source]

Returns a dict to communicate with the server

Return type:

dict

attachment

Path to the attachment if on disk

   Type: Path

attachment_id

The attachment’s id. Default ‘file’

   Type: str

attachment_type

The attachment’s type. Default ‘file’

   Type: str

content

Content of the attachment

   Type: any

content_id

The attachment’s content id Default ‘file’.

   Type: str

is_inline

true if the attachment is an inline attachment; otherwise, false.

   Type: bool

name

The attachment’s file name.

   Type: str

on_cloud

Indicates if the attachment is stored on cloud.

   Type: bool

on_disk

Indicates if the attachment is stored on disk.

   Type: bool

class O365.utils.attachment.BaseAttachments(parent, attachments=None)[source]

Bases: ApiComponent

A Collection of BaseAttachments

__init__(parent, attachments=None)[source]

Attachments must be a list of path strings or dictionary elements

Parameters:
  • parent (Account) – parent object

  • attachments (list[str] or list[Path] or str or Path or dict) – list of attachments

add(attachments)[source]

Add more attachments

Parameters:

attachments (list[str] or list[Path] or str or Path or dict) – list of attachments

clear()[source]

Clear the attachments

download_attachments()[source]

Downloads this message attachments into memory. Need a call to ‘attachment.save’ to save them on disk.

Returns:

Success / Failure

Return type:

bool

remove(attachments)[source]

Remove the specified attachments

Parameters:

attachments (list[str] or list[Path] or str or Path or dict) – list of attachments

to_api_data()[source]

Returns a dict to communicate with the server

Return type:

dict

class O365.utils.attachment.UploadSessionRequest(parent, attachment)[source]

Bases: ApiComponent

__init__(parent, attachment)[source]

Object initialization

Parameters:
  • protocol (Protocol) – A protocol class or instance to be used with this connection

  • main_resource (str) – main_resource to be used in these API communications

to_api_data()[source]