class Gmail extends ServiceWrapper

Gmail helper

Provides helper functions to Gmail API

Constants

GMAIL_INBOX

GMAIL_DRAFT

GMAIL_UNREAD

GMAIL_IMPORTANT

GMAIL_STARRED

GMAIL_SPAM

GMAIL_TRASH

GMAIL_SENT

Properties

protected Google_Service $_service from ServiceWrapper

Methods

mixed
__call(string $name, mixed[] $arguments)

Magic method to transfer method calls to underlying Google service (except for method defined here)

mixed
__get(string $k)

Magic method to get a property from underlying Google service (except for properties defined here)

__construct(Google_Service $service)

Constructor of service helper

Google_Service_Gmail_Message[]
listAllUsersMessages(string $userid, string[] $optparams = array())

Get a list of messages IDs, with optional parameters (query)

string
getMessageAttachmentDecoded(string $userid, string $mid, string $aid, string[] $optparams = array())

Get a message attachment and decode it (as Gmail encodes it with base64)

string
getMessageAttachment(string $userid, string $mid, string $aid, string[] $optparams = array())

Get a message attachment (encoded by Gmail with base64)

static string
base64RFC4648Decode(string $data)

Helper method to decode quoted printable rfc4648.

static string|string[]|false
getMessageHeader(Google_Service_Gmail_Message $email, string $header)

Look for a particular header in the message headers list

static string|string[]|false
getMessagePartHeader(Google_Service_Gmail_MessagePart $part, string $header)

Look for a particular header in a message part headers list

static string|string[]|false
getHeader(array $headers, string $header)

Look for a particular header in a headers list

static Google_Service_Gmail_MessagePart
getMessagePart(Google_Service_Gmail_Message $email, string $searchFor)

Get a specific message part, identified by its Mime-type

static MessageBody|null
getMessageBody(Google_Service_Gmail_Message $email, string[] $contentTypes = array('text/html', 'text/plain'))

Get a message body (usaually text/html or text/plain) and decode it (as Google always encodes it to base64)

static string
getMessageSubject(Google_Service_Gmail_Message $email)

Get message subject ; shortcut to Gmail::getMessageHeader($email, 'Subject')

static int|string|null
getMessageDate(Google_Service_Gmail_Message $email)

Get message send date/time

static MessageAttachment[]|null
getMessageAttachments(Google_Service_Gmail_Message $email)

Get a list of attachments for a message

static MessageAttachment[]|null
getMessageInlineAttachments(Google_Service_Gmail_Message $email)

Get a list of inline attachments (usually embedded images such as logos or signatures) for a message

getMessageBodyWithInlineAttachments(Google_Service_Gmail_Message $email, string $userid, string[] $contentTypes = array('text/html', 'text/plain'))

Get a message body with its inline attachments converted to inline images (HTML tags with IMG SRC attribute set to data:image/jpeg;base64,.

Details

in ServiceWrapper at line 32
mixed __call(string $name, mixed[] $arguments)

Magic method to transfer method calls to underlying Google service (except for method defined here)

Parameters

string $name Method name
mixed[] $arguments Array of parameters (indexed array, not associative)

Return Value

mixed

in ServiceWrapper at line 47
mixed __get(string $k)

Magic method to get a property from underlying Google service (except for properties defined here)

Parameters

string $k Property name

Return Value

mixed

in ServiceWrapper at line 61
__construct(Google_Service $service)

Constructor of service helper

Parameters

Google_Service $service Google service to send requests to

at line 47
Google_Service_Gmail_Message[] listAllUsersMessages(string $userid, string[] $optparams = array())

Get a list of messages IDs, with optional parameters (query)

Don't make a mistake by thinking 'listAllUsersMessages' means listing all email with no filtering options. 'All' means we want to fetch the entire list in one call, and not bother with page tokens. To select emails to include, use any filter available through the $optparams parameter (see API reference for a list of filters and syntax).

Moreover, this method only returns messages IDs, not actual content. You have to fetch each the email content by calling $service->users_messages->get($userid, $messageid).

Parameters

string $userid User ID concerned (email) or 'me' to indicate the authenticated user
string[] $optparams Array of parameters for request, as defined in the API protocol reference

Return Value

Google_Service_Gmail_Message[] An array of emails entries with messages IDs only

at line 88
string getMessageAttachmentDecoded(string $userid, string $mid, string $aid, string[] $optparams = array())

Get a message attachment and decode it (as Gmail encodes it with base64)

Parameters

string $userid User ID concerned (email) or 'me' to indicate the authenticated user
string $mid Message ID
string $aid Attachment ID
string[] $optparams Array of parameters for request, as defined in the API protocol reference

Return Value

string The decoded attachment as a string

at line 103
string getMessageAttachment(string $userid, string $mid, string $aid, string[] $optparams = array())

Get a message attachment (encoded by Gmail with base64)

Parameters

string $userid User ID concerned (email) or 'me' to indicate the authenticated user
string $mid Message ID
string $aid Attachment ID
string[] $optparams Array of parameters for request, as defined in the API protocol reference

Return Value

string The attachment as a base64-encoded string

at line 117
static string base64RFC4648Decode(string $data)

Helper method to decode quoted printable rfc4648.

Before decoding from base64 we have to replace _ by / and - by +, as Google API does those suspicious replacements after encoding to base64

Parameters

string $data Base64 encoded string

Return Value

string Decoded string

at line 130
static string|string[]|false getMessageHeader(Google_Service_Gmail_Message $email, string $header)

Look for a particular header in the message headers list

Parameters

Google_Service_Gmail_Message $email Message object
string $header Header name to look for

Return Value

string|string[]|false Return the header value or an array of header values if multiple headers with name $header are found ; if not found, returns FALSE

at line 143
static string|string[]|false getMessagePartHeader(Google_Service_Gmail_MessagePart $part, string $header)

Look for a particular header in a message part headers list

Parameters

Google_Service_Gmail_MessagePart $part Message part object
string $header Header name to look for

Return Value

string|string[]|false Return the header value or an array of header values if multiple headers with name $header are found ; if not found, returns FALSE

at line 157
static string|string[]|false getHeader(array $headers, string $header)

Look for a particular header in a headers list

Parameters

array $headers List of headers (as array of objects with name & value properties)
string $header Header name to look for

Return Value

string|string[]|false Return the header value or an array of header values if multiple headers with name $header are found ; if not found, returns FALSE

Exceptions

Exception Thrown if $headers is not an array of Google_Service_Gmail_MessagePartHeader objects

at line 187
static Google_Service_Gmail_MessagePart getMessagePart(Google_Service_Gmail_Message $email, string $searchFor)

Get a specific message part, identified by its Mime-type

The message part is returned as provided by the API, that is to say it is still base64 encoded. To get a specific message part and decode it, call getMessageBody() method instead with the appropriate suitable content-types.

Parameters

Google_Service_Gmail_Message $email Message object
string $searchFor Part Content-type to look for

Return Value

Google_Service_Gmail_MessagePart Returns the part object if found, FALSE otherwise

at line 220
static MessageBody|null getMessageBody(Google_Service_Gmail_Message $email, string[] $contentTypes = array('text/html', 'text/plain'))

Get a message body (usaually text/html or text/plain) and decode it (as Google always encodes it to base64)

Parameters

Google_Service_Gmail_Message $email Message object
string[] $contentTypes Array of suitable content-types. The first content-type found in the message is used. So you may set it to ['text/html', 'text/plain'] and not ['text/plain', 'text/html'].

Return Value

MessageBody|null Returns the part content as a Gmail\MessageBody object ; returns NULL if no suitable part is found

at line 243
static string getMessageSubject(Google_Service_Gmail_Message $email)

Get message subject ; shortcut to Gmail::getMessageHeader($email, 'Subject')

Parameters

Google_Service_Gmail_Message $email

Return Value

string The email subject as a string

at line 255
static int|string|null getMessageDate(Google_Service_Gmail_Message $email)

Get message send date/time

Parameters

Google_Service_Gmail_Message $email

Return Value

int|string|null Returns a UNIX timestamp with local timezone ; returns a string with Date header if the date format cannot be parsed ; returns NULL if no Date header

at line 291
static MessageAttachment[]|null getMessageAttachments(Google_Service_Gmail_Message $email)

Get a list of attachments for a message

Parameters

Google_Service_Gmail_Message $email

Return Value

MessageAttachment[]|null Returns an array of attachements objects or NULL if email has no attachments

at line 333
static MessageAttachment[]|null getMessageInlineAttachments(Google_Service_Gmail_Message $email)

Get a list of inline attachments (usually embedded images such as logos or signatures) for a message

Parameters

Google_Service_Gmail_Message $email

Return Value

MessageAttachment[]|null Returns an array of inline attachements objects or NULL if email has no attachments

at line 376
MessageBody getMessageBodyWithInlineAttachments(Google_Service_Gmail_Message $email, string $userid, string[] $contentTypes = array('text/html', 'text/plain'))

Get a message body with its inline attachments converted to inline images (HTML tags with IMG SRC attribute set to data:image/jpeg;base64,.

...)

Parameters

Google_Service_Gmail_Message $email Message object
string $userid User id or special value 'me' (required to fetch attachments : we have to send a request to the API)
string[] $contentTypes Array of suitable content-types. The first content-type found in the message is used. So you may set it to ['text/html', 'text/plain'] and not ['text/plain', 'text/html'].

Return Value

MessageBody Returns the body content with inline embeddings converted to IMG tags with base64 content in their SRC attribute