Python bindings for Apple's MailKit framework, enabling developers to create mail extensions that integrate with macOS Mail applications
—
Python bindings for Apple's MailKit framework, enabling developers to create mail extensions that integrate with macOS Mail applications. This framework provides comprehensive functionality for message handling, security operations (encryption/signing), compose session management, message actions (flagging, coloring), content blocking, and address annotation capabilities.
pip install pyobjc-framework-MailKitimport MailKitAccess specific classes:
from MailKit import (
MEMessage, MEComposeSession, MEMessageAction,
MEExtensionManager, MEMessageSecurityInformation,
MEDecodedMessage, MEEmailAddress
)import MailKit
# Create a message security information object
security_info = MailKit.MEMessageSecurityInformation.alloc().initWithSigners_isEncrypted_signingError_encryptionError_(
signers=[],
isEncrypted=True,
signingError=None,
encryptionError=None
)
# Create a decoded message with security information
message = MailKit.MEDecodedMessage.alloc().initWithData_securityInformation_context_(
data=message_data,
securityInformation=security_info,
context=context
)
# Check message encryption state
if message_encryption_state == MailKit.MEMessageEncryptionStateEncrypted:
print("Message is encrypted")
# Handle message actions
if action_flag == MailKit.MEMessageActionFlagRed:
print("Message has red flag")The MailKit framework follows Apple's Mail extension architecture:
Core classes for representing and manipulating mail messages, including message state, encryption information, and decoded message handling.
class MEMessage: ...
class MEDecodedMessage: ...
class MEEmailAddress: ...Comprehensive security functionality including message signing, encryption, security information management, and security handler protocols.
class MEMessageSecurityInformation:
def initWithSigners_isEncrypted_signingError_encryptionError_(
self, signers, isEncrypted: bool, signingError, encryptionError
): ...
def isEncrypted(self) -> bool: ...
def shouldBlockRemoteContent(self) -> bool: ...
class MEMessageSigner: ...
class MEEncodedOutgoingMessage: ...
class MEOutgoingMessageEncodingStatus: ...Message action handling including flagging, coloring, and custom action decision workflows.
class MEMessageAction: ...
class MEMessageActionDecision: ...
# Action flags
MEMessageActionFlagNone: int # = 0
MEMessageActionFlagDefaultColor: int # = 1
MEMessageActionFlagRed: int # = 2
MEMessageActionFlagOrange: int # = 3
MEMessageActionFlagYellow: int # = 4
MEMessageActionFlagGreen: int # = 5
MEMessageActionFlagBlue: int # = 6
MEMessageActionFlagPurple: int # = 7
MEMessageActionFlagGray: int # = 8
# Message colors
MEMessageActionMessageColorNone: int # = 0
MEMessageActionMessageColorGreen: int # = 1
MEMessageActionMessageColorYellow: int # = 2
MEMessageActionMessageColorOrange: int # = 3
MEMessageActionMessageColorRed: int # = 4
MEMessageActionMessageColorPurple: int # = 5
MEMessageActionMessageColorBlue: int # = 6
MEMessageActionMessageColorGray: int # = 7Email composition session handling including compose context, session handlers, and address annotation.
class MEComposeSession: ...
class MEComposeContext:
def isEncrypted(self) -> bool: ...
def shouldEncrypt(self) -> bool: ...
def isSigned(self) -> bool: ...
def shouldSign(self) -> bool: ...
class MEAddressAnnotation: ...Extension manager for controlling Mail extensions, reloading content blockers, and managing visible messages.
class MEExtensionManager:
def reloadContentBlockerWithIdentifier_completionHandler_(
self, identifier: str, completionHandler
): ...
def reloadVisibleMessagesWithCompletionHandler_(
self, completionHandler
): ...
class MEExtensionViewController: ...Protocol definitions for creating Mail extensions including message decoders, encoders, security handlers, action handlers, and content blockers.
# Protocol: MEMessageDecoder
def decodedMessageForMessageData_(self, messageData): ...
# Protocol: MEMessageEncoder
def encodeMessage_composeContext_completionHandler_(
self, message, composeContext, completionHandler
): ...
# Protocol: MEMessageSecurityHandler
def primaryActionClickedForMessageContext_completionHandler_(
self, messageContext, completionHandler
): ...
# Protocol: MEMessageActionHandler
def decideActionForMessage_completionHandler_(
self, message, completionHandler
): ...
# Protocol: MEContentBlocker
def contentRulesJSON(self): ...# Message States
MEMessageStateReceived: int # = 0
MEMessageStateDraft: int # = 1
MEMessageStateSending: int # = 2
# Encryption States
MEMessageEncryptionStateUnknown: int # = 0
MEMessageEncryptionStateNotEncrypted: int # = 1
MEMessageEncryptionStateEncrypted: int # = 2
# Compose User Actions
MEComposeUserActionNewMessage: int # = 1
MEComposeUserActionReply: int # = 2
MEComposeUserActionReplyAll: int # = 3
MEComposeUserActionForward: int # = 4
# Error Domains
MEComposeSessionErrorDomain: str
MEMessageSecurityErrorDomain: str
# Error Codes
MEComposeSessionErrorCodeInvalidRecipients: int # = 0
MEComposeSessionErrorCodeInvalidHeaders: int # = 1
MEComposeSessionErrorCodeInvalidBody: int # = 2
MEMessageSecurityEncodingError: int # = 0
MEMessageSecurityDecodingError: int # = 1
# Type annotations for enums
from typing import NewType
MEMessageSecurityErrorCode = NewType('MEMessageSecurityErrorCode', int)
MEMessageActionFlag = NewType('MEMessageActionFlag', int)
MEComposeSessionErrorCode = NewType('MEComposeSessionErrorCode', int)
MEMessageActionMessageColor = NewType('MEMessageActionMessageColor', int)
MEMessageEncryptionState = NewType('MEMessageEncryptionState', int)
MEMessageState = NewType('MEMessageState', int)
MEComposeUserAction = NewType('MEComposeUserAction', int)This framework enables developers to create sophisticated Mail app extensions that can handle all aspects of email processing, security, and user interaction within the macOS Mail ecosystem.
Install with Tessl CLI
npx tessl i tessl/pypi-pyobjc-framework-mailkit