Mailbox

class O365.mailbox.Folder(*, parent=None, con=None, **kwargs)[source]

Bases: O365.utils.utils.ApiComponent

A Mail Folder representation

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

Create an instance to represent the specified folder un given parent folder

Parameters
  • parent (mailbox.Folder or Account) – parent folder/account for this folder

  • con (Connection) – connection to use if no parent specified

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

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

  • name (str) – name of the folder to get under the parent (kwargs)

  • folder_id (str) – id of the folder to get under the parent (kwargs)

copy_folder(to_folder)[source]

Copy this folder and it’s contents to into another folder

Parameters

to_folder (mailbox.Folder or str) – the destination Folder/folder_id to copy into

Returns

The new folder after copying

Return type

mailbox.Folder or None

create_child_folder(folder_name)[source]

Creates a new child folder under this folder

Parameters

folder_name (str) – name of the folder to add

Returns

newly created folder

Return type

mailbox.Folder or None

delete()[source]

Deletes this folder

Returns

Deleted or Not

Return type

bool

delete_message(message)[source]

Deletes a stored message

Parameters

message (Message or str) – message/message_id to delete

Returns

Success / Failure

Return type

bool

get_folder(*, folder_id=None, folder_name=None)[source]

Get a folder by it’s id or name

Parameters
  • folder_id (str) – the folder_id to be retrieved. Can be any folder Id (child or not)

  • folder_name (str) – the folder name to be retrieved. Must be a child of this folder.

Returns

a single folder

Return type

mailbox.Folder or None

get_folders(limit=None, *, query=None, order_by=None, batch=None)[source]

Returns a list of child folders matching the query

Parameters
  • limit (int) – max no. of folders to get. Over 999 uses batch.

  • query (Query or str) – applies a filter to the request such as “displayName eq ‘HelloFolder’”

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns

list of folders

Return type

list[mailbox.Folder] or Pagination

get_message(object_id=None, query=None, *, download_attachments=False)[source]
Get one message from the query result.

A shortcut to get_messages with limit=1

Parameters
  • object_id – the message id to be retrieved.

  • query (Query or str) – applies a filter to the request such as “displayName eq ‘HelloFolder’”

  • download_attachments (bool) – whether or not to download attachments

Returns

one Message

Return type

Message or None

get_messages(limit=25, *, query=None, order_by=None, batch=None, download_attachments=False)[source]

Downloads messages from this folder

Parameters
  • limit (int) – limits the result set. Over 999 uses batch.

  • query (Query or str) – applies a filter to the request such as “displayName eq ‘HelloFolder’”

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

  • download_attachments (bool) – whether or not to download attachments

Returns

list of messages

Return type

list[Message] or Pagination

get_parent_folder()[source]

Get the parent folder from attribute self.parent or getting it from the cloud

Returns

Parent Folder

Return type

mailbox.Folder or None

message_constructor

alias of O365.message.Message

move_folder(to_folder, *, update_parent_if_changed=True)[source]

Move this folder to another folder

Parameters
  • to_folder (mailbox.Folder or str) – the destination Folder/folder_id to move into

  • update_parent_if_changed (bool) – updates self.parent with the new parent Folder if changed

Returns

The new folder after copying

Return type

mailbox.Folder or None

new_message()[source]

Creates a new draft message under this folder

Returns

new Message

Return type

Message

refresh_folder(update_parent_if_changed=False)[source]

Re-download folder data Inbox Folder will be unable to download its own data (no folder_id)

Parameters

update_parent_if_changed (bool) – updates self.parent with new parent Folder if changed

Returns

Refreshed or Not

Return type

bool

update_folder_name(name, update_folder_data=True)[source]

Change this folder name

Parameters
  • name (str) – new name to change to

  • update_folder_data (bool) – whether or not to re-fetch the data

Returns

Updated or Not

Return type

bool

class O365.mailbox.MailBox(*, parent=None, con=None, **kwargs)[source]

Bases: O365.mailbox.Folder

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

Create an instance to represent the specified folder un given parent folder

Parameters
  • parent (mailbox.Folder or Account) – parent folder/account for this folder

  • con (Connection) – connection to use if no parent specified

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

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

  • name (str) – name of the folder to get under the parent (kwargs)

  • folder_id (str) – id of the folder to get under the parent (kwargs)

archive_folder()[source]

Shortcut to get Archive Folder instance

Return type

mailbox.Folder

deleted_folder()[source]

Shortcut to get DeletedItems Folder instance

Return type

mailbox.Folder

drafts_folder()[source]

Shortcut to get Drafts Folder instance

Return type

mailbox.Folder

folder_constructor

alias of Folder

inbox_folder()[source]

Shortcut to get Inbox Folder instance

Return type

mailbox.Folder

junk_folder()[source]

Shortcut to get Junk Folder instance

Return type

mailbox.Folder

outbox_folder()[source]

Shortcut to get Outbox Folder instance

Return type

mailbox.Folder

sent_folder()[source]

Shortcut to get SentItems Folder instance

Return type

mailbox.Folder