Python bindings for Apple's MailKit framework, enabling developers to create mail extensions that integrate with macOS Mail applications
—
Core classes for representing and manipulating mail messages, including message state, encryption information, and decoded message handling. These classes form the foundation for working with mail messages in MailKit extensions.
Represents a mail message with state and encryption information. This is the primary class for working with mail messages in the MailKit framework.
class MEMessage:
"""
Represents a mail message.
Note: This class cannot be instantiated directly using init() or new().
Instances are provided by the Mail framework.
"""Represents a decoded message with security information and optional banner. Used for displaying processed messages with security context.
class MEDecodedMessage:
def initWithData_securityInformation_context_(
self,
data, # NSData: Message data
securityInformation, # MEMessageSecurityInformation: Security info
context # Any: Message context
):
"""
Initialize a decoded message with data, security information, and context.
Args:
data: The message data
securityInformation: Security information for the message
context: Additional context for the message
Returns:
MEDecodedMessage: Initialized decoded message
"""
def initWithData_securityInformation_context_banner_(
self,
data, # NSData: Message data
securityInformation, # MEMessageSecurityInformation: Security info
context, # Any: Message context
banner # MEDecodedMessageBanner: Optional banner
):
"""
Initialize a decoded message with data, security information, context, and banner.
Args:
data: The message data
securityInformation: Security information for the message
context: Additional context for the message
banner: Optional banner for the decoded message
Returns:
MEDecodedMessage: Initialized decoded message
"""Banner component for decoded messages with action capabilities. Provides UI elements for message banners with primary actions and dismissal options.
class MEDecodedMessageBanner:
def initWithTitle_primaryActionTitle_dismissable_(
self,
title: str, # Banner title
primaryActionTitle: str, # Primary action button title
dismissable: bool # Whether banner can be dismissed
):
"""
Initialize a decoded message banner.
Args:
title: The title text for the banner
primaryActionTitle: The text for the primary action button
dismissable: Whether the banner can be dismissed by the user
Returns:
MEDecodedMessageBanner: Initialized banner
"""
def isDismissable(self) -> bool:
"""
Check if the banner can be dismissed.
Returns:
bool: True if the banner can be dismissed
"""Handles email address representation and validation. Provides functionality for working with email addresses in the Mail framework.
class MEEmailAddress:
def initWithRawString_(self, rawString: str):
"""
Initialize an email address from a raw string.
Args:
rawString: The email address string
Returns:
MEEmailAddress: Initialized email address
"""Represents the result of message encoding operations. Contains information about the success or failure of encoding operations.
class MEMessageEncodingResult:
"""
Represents the result of a message encoding operation.
Note: This class cannot be instantiated directly using init() or new().
Instances are provided by the Mail framework during encoding operations.
"""Constants representing different message states:
MEMessageStateReceived: int # = 0, Message has been received
MEMessageStateDraft: int # = 1, Message is a draft
MEMessageStateSending: int # = 2, Message is being sentConstants representing message encryption states:
MEMessageEncryptionStateUnknown: int # = 0, Encryption state unknown
MEMessageEncryptionStateNotEncrypted: int # = 1, Message is not encrypted
MEMessageEncryptionStateEncrypted: int # = 2, Message is encryptedimport MailKit
# Create security information
security_info = MailKit.MEMessageSecurityInformation.alloc().initWithSigners_isEncrypted_signingError_encryptionError_(
signers=[],
isEncrypted=True,
signingError=None,
encryptionError=None
)
# Create decoded message
decoded_message = MailKit.MEDecodedMessage.alloc().initWithData_securityInformation_context_(
data=message_data,
securityInformation=security_info,
context=message_context
)import MailKit
# Create a dismissable banner with primary action
banner = MailKit.MEDecodedMessageBanner.alloc().initWithTitle_primaryActionTitle_dismissable_(
title="Security Warning",
primaryActionTitle="View Details",
dismissable=True
)
# Check if banner is dismissable
if banner.isDismissable():
print("Banner can be dismissed by user")import MailKit
# Create email address from string
email = MailKit.MEEmailAddress.alloc().initWithRawString_("user@example.com")import MailKit
# Check message state
if message_state == MailKit.MEMessageStateReceived:
print("Message has been received")
elif message_state == MailKit.MEMessageStateDraft:
print("Message is a draft")
elif message_state == MailKit.MEMessageStateSending:
print("Message is being sent")
# Check encryption state
if encryption_state == MailKit.MEMessageEncryptionStateEncrypted:
print("Message is encrypted")
elif encryption_state == MailKit.MEMessageEncryptionStateNotEncrypted:
print("Message is not encrypted")
else:
print("Encryption state unknown")Install with Tessl CLI
npx tessl i tessl/pypi-pyobjc-framework-mailkit