or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

compose-sessions.mdextension-management.mdindex.mdmessage-actions.mdmessage-classes.mdprotocols-handlers.mdsecurity-encryption.md
tile.json

tessl/pypi-pyobjc-framework-mailkit

Python bindings for Apple's MailKit framework, enabling developers to create mail extensions that integrate with macOS Mail applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyobjc-framework-mailkit@10.3.x

To install, run

npx @tessl/cli install tessl/pypi-pyobjc-framework-mailkit@10.3.0

index.mddocs/

pyobjc-framework-MailKit

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.

Package Information

  • Package Name: pyobjc-framework-MailKit
  • Language: Python
  • Installation: pip install pyobjc-framework-MailKit
  • Requirements: macOS 12.0+, pyobjc-core, pyobjc-framework-Cocoa

Core Imports

import MailKit

Access specific classes:

from MailKit import (
    MEMessage, MEComposeSession, MEMessageAction,
    MEExtensionManager, MEMessageSecurityInformation,
    MEDecodedMessage, MEEmailAddress
)

Basic Usage

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")

Architecture

The MailKit framework follows Apple's Mail extension architecture:

  • Extension Types: Message decoders, encoders, security handlers, action handlers, content blockers, and compose handlers
  • Protocol-Based Design: Extensive use of protocols for defining extension capabilities
  • Asynchronous Operations: Completion handler pattern for long-running operations
  • Security Integration: Built-in support for message encryption, signing, and validation
  • Mail App Integration: Direct integration with macOS Mail application workflows

Capabilities

Message Classes

Core classes for representing and manipulating mail messages, including message state, encryption information, and decoded message handling.

class MEMessage: ...
class MEDecodedMessage: ...
class MEEmailAddress: ...

Message Classes

Security and Encryption

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: ...

Security and Encryption

Message Actions and Flags

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     # = 7

Message Actions

Compose Session Management

Email 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: ...

Compose Sessions

Extension Management

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: ...

Extension Management

Protocols and Handlers

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): ...

Protocols and Handlers

Constants and Enumerations

# 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.