GMime.Message

g GMime.Message GMime.Message GMime.Object GMime.Object GMime.Object->GMime.Message GObject.Object GObject.Object GObject.Object->GMime.Object

Subclasses:

None

Methods

Inherited:

GMime.Object (28), GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (pretty_headers)

add_mailbox (type, name, addr)

foreach (callback, *user_data)

get_addresses (type)

get_all_recipients ()

get_autocrypt_gossip_headers (now, flags, session_key)

get_autocrypt_gossip_headers_from_inner_part (now, inner_part)

get_autocrypt_header (now)

get_bcc ()

get_body ()

get_cc ()

get_date ()

get_from ()

get_message_id ()

get_mime_part ()

get_reply_to ()

get_sender ()

get_subject ()

get_to ()

partial_split_message (max_size)

set_date (date)

set_message_id (message_id)

set_mime_part (mime_part)

set_subject (subject, charset)

Virtual Methods

Inherited:

GMime.Object (8), GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

addrlists

GMime.InternetAddressList

r

a table of address lists

date

GLib.DateTime

r

Date value

marker

str

r

message_id

str

r

Message-Id string

mime_part

GMime.Object

r

toplevel MIME part

parent_object

GMime.Object

r

parent GMime.Object

subject

str

r

Subject string

Class Details

class GMime.Message(**kwargs)
Bases:

GMime.Object

Abstract:

No

Structure:

GMime.MessageClass

A MIME Message object.

classmethod new(pretty_headers)
Parameters:

pretty_headers (bool) – make pretty headers

Returns:

an empty GMime.Message object.

Return type:

GMime.Message

If pretty_headers is True, then the standard rfc822 headers are initialized so as to put headers in a nice friendly order. This is strictly a cosmetic thing, so if you are unsure, it is safe to say no (False).

add_mailbox(type, name, addr)
Parameters:

Add a mailbox of a chosen type to the MIME message.

Note: The name (and addr) strings should be in UTF-8.

foreach(callback, *user_data)
Parameters:
  • callback (GMime.ObjectForeachFunc) – function to call on each of the mime parts contained by the mime message

  • user_data (object or None) – user-supplied callback data

Recursively calls callback on each of the mime parts in the mime message.

get_addresses(type)
Parameters:

type (GMime.AddressType) – A GMime.AddressType

Returns:

a list of addresses of the specified type from the self.

Return type:

GMime.InternetAddressList

Gets a list of addresses of the specified type from the self.

get_all_recipients()
Returns:

a newly allocated GMime.InternetAddressList containing all recipients of the message or None if no recipients are set.

Return type:

GMime.InternetAddressList

Gets the complete list of recipients for self.

get_autocrypt_gossip_headers(now, flags, session_key)
Parameters:
Raises:

GLib.Error

Returns:

a new GMime.AutocryptHeaderList object, or None on error.

Return type:

GMime.AutocryptHeaderList or None

Creates a new GMime.AutocryptHeaderList of relevant headers of the given type based on the recipient(s) of an e-mail message.

Returns the same object as #g_mime_message_get_autocrypt_gossip_headers_with_inner_part , but handles decryption and cleanup automatically.

flags and session_key are passed through to GMime.MultipartEncrypted.decrypt, as needed.

If the message is not actually an encrypted message, returns None: it should be ignored for purposes of evaluating gossip.

If decryption fails, returns None. In this case, an exception will be set on err to provide information about the decryption failure.

get_autocrypt_gossip_headers_from_inner_part(now, inner_part)
Parameters:
Returns:

a new GMime.AutocryptHeaderList object, or None on error.

Return type:

GMime.AutocryptHeaderList or None

Creates a new GMime.AutocryptHeaderList of relevant headers of the given type based on the recipient(s) of an e-mail message.

You must pass the decrypted inner part of the message to this function, since Autocrypt-Gossip headers are only stored within the encrypted layer.

If you don’t already have the decrypted inner part available to you, you probably want to use GMime.Message.get_autocrypt_gossip_headers instead.

Each header in the returned list will:

  • have a valid address

  • be of the type requested

  • be complete

If no Autocrypt header is found for a recipient, no GMime.AutocryptHeader will be in the list associated with that e-mail address.

Note that the following types of Autocrypt headers will not be returned by this function:

  • headers of an unrequested type

  • headers that do not match an address in “From:”

  • unparseable headers

  • headers with unknown critical attributes

  • duplicate valid headers for a given address

On error (e.g. if this version of GMime cannot handle the requested Autocrypt type, or if a parameter is missing or malformed), returns None

The returned Autocrypt headers will have their effective_date set to the earliest of either:

  • the Date: header of the message or

  • now (or the current time, if now is None)

get_autocrypt_header(now)
Parameters:

now (GLib.DateTime) – a GLib.DateTime object, or None

Returns:

a new GMime.AutocryptHeader object, or None if the message should be ignored for purposes of Autocrypt.

Return type:

GMime.AutocryptHeader or None

Creates a new GMime.AutocryptHeader based on the relevant Autocrypt header associated with the sender of an e-mail message.

If the message has no sender in the From: field, or has more than one sender, then this function will return None. Autocrypt should ignore the message entirely.

If there is one sender, but no single Autocrypt header is found that matches that e-mail address, a GMime.AutocryptHeader will be returned for the sender, but it will be incomplete (see GMime.AutocryptHeader.is_complete).

Note that the following types of Autocrypt headers will not be returned by this function:

  • headers that do not match an address in “From:”

  • unparseable headers

  • headers with unknown critical attributes

  • duplicate valid headers for the sender’s address

The returned Autocrypt header will have its effective_date set to the earliest of either:

  • the Date: header of the message or

  • now (or the current time, if now is None)

get_bcc()
Returns:

the parsed list of addresses in the Bcc header(s).

Return type:

GMime.InternetAddressList

Gets combined list of parsed addresses in the Bcc header(s).

get_body()
Returns:

a GMime.Object containing the textual content that appears to be the main body of the message, or None if no body part has been set.

Note: This function is NOT guaranteed to always work as it makes some assumptions that are not necessarily true. It is recommended that you traverse the MIME structure yourself.

Return type:

GMime.Object or None

Attempts to identify the MIME part containing the body of the message.

get_cc()
Returns:

the parsed list of addresses in the Cc header(s).

Return type:

GMime.InternetAddressList

Gets combined list of parsed addresses in the Cc header(s).

get_date()
Returns:

a GLib.DateTime on success or None if the date could not be parsed.

Return type:

GLib.DateTime or None

Gets the parsed date and time value from the Date header.

get_from()
Returns:

the parsed list of addresses in the From header.

Return type:

GMime.InternetAddressList

Gets the parsed list of addresses in the From header.

get_message_id()
Returns:

the Message-Id of a message, or None if not specified.

Return type:

str or None

Gets the Message-Id header of self.

get_mime_part()
Returns:

the toplevel MIME part of self, or None if none is present.

Return type:

GMime.Object or None

Gets the toplevel MIME part contained within self.

get_reply_to()
Returns:

the parsed list of addresses in the Reply-To header.

Return type:

GMime.InternetAddressList

Gets the parsed list of addresses in the Reply-To header.

get_sender()
Returns:

the parsed list of addresses in the Sender header.

Return type:

GMime.InternetAddressList

Gets the parsed list of addresses in the Sender header.

get_subject()
Returns:

the subject of the self in a form suitable for display or None if no subject is set. If not None, the returned string will be in UTF-8.

Return type:

str or None

Gets the subject of the self.

get_to()
Returns:

the parsed list of addresses in the To header(s).

Return type:

GMime.InternetAddressList

Gets combined list of parsed addresses in the To header(s).

partial_split_message(max_size)
Parameters:

max_size (int) – max size

Returns:

an array of GMime.Message objects and sets nparts to the number of messages returned or None on fail.

nparts:

number of parts

Return type:

(GMime.Message or None, nparts: int)

Splits self into an array of GMime.Message objects each containing a single GMime.MessagePartial object containing max_size bytes or fewer. nparts is set to the number of GMime.MessagePartial objects created.

set_date(date)
Parameters:

date (GLib.DateTime) – a date to be used in the Date header

Sets the Date header on a MIME Message.

set_message_id(message_id)
Parameters:

message_id (str) – message-id (addr-spec portion)

Set the Message-Id on a message.

set_mime_part(mime_part)
Parameters:

mime_part (GMime.Object) – The root-level MIME Part

Set the root-level MIME part of the message.

set_subject(subject, charset)
Parameters:
  • subject (str) – Subject string

  • charset (str) – The charset to use for encoding the subject or None to use the default

Set the subject of a self.

Note: The subject string should be in UTF-8.