Mailbox - dylandoamaral/ggmail GitHub Wiki

What is a mailbox ?

A Mailbox is a folder containing your emails. By default gmail provides you many mailboxes such as trash or sent. You can also create your own custom mailboxes and deal with it using GGmail.

ℹ️ You can have a nested mailbox. Nested mailbox are defined using named composed by / separator. As an example, Parent/MyMailbox will create a mailbox MyMailbox inside the Parent mailbox.

Rename a mailbox

You can rename a custom mailbox, this will not affect the path of the mailbox.

mailbox = account.mailbox_from_path("Parent/MyCustomMailbox")
mailbox.rename("MyMailbox") # Mailbox at Parent/MyMailbox

Move a mailbox

You can move a custom mailbox, this will affect the path of the mailbox.

mailbox = account.mailbox_from_path("Parent/MyCustomMailbox")
mailbox.rename("MyMailbox") # Mailbox at MyMailbox

Select a mailbox

You can select a mailbox, for some mailbox specific operations, it is important to select it before performing it.

mailbox = account.inbox()
mailbox.select() # Every mailbox specific operations will be for inbox

Search from a mailbox

You can search messages from a particular mailbox. It uses policies to retrieve a subset of the messages.

from ggmail.policy import all_

mailbox = account.inbox()
messages = mailbox.search(all_) # Retrieve all messages from inbox

Since v0.2.0, you can search messages using their uids. Uids are unique message identifiers for the selected mailbox.

Sometimes, you don't need to retrieve all message information. For example, if you want to unstar all mails, you don't need to know their names and so one and you can just use their uids.

from ggmail.policy import all_
from ggmail.flag import Flag

mailbox = account.inbox()
message_uids = mailbox.search_uids(Flag.FLAGGED) # Retrieve flagged messages uids
account.remove_flag_messages_using_uids(message_uids, Flag.FLAGGED) # Unstar every messages