CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyobjc-framework-mailkit

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

Pending
Overview
Eval results
Files

security-encryption.mddocs/

Security and Encryption

Comprehensive security functionality including message signing, encryption, security information management, and security handler protocols. This module provides the core security capabilities for Mail extensions.

Capabilities

MEMessageSecurityInformation

Contains security information for messages including encryption and signing details. This is the primary class for managing message security state.

class MEMessageSecurityInformation:
    def initWithSigners_isEncrypted_signingError_encryptionError_(
        self,
        signers,  # List: List of MEMessageSigner objects
        isEncrypted: bool,  # Whether message is encrypted
        signingError,  # NSError or None: Signing error if any
        encryptionError  # NSError or None: Encryption error if any
    ):
        """
        Initialize security information with basic parameters.
        
        Args:
            signers: List of message signers
            isEncrypted: Whether the message is encrypted
            signingError: Error that occurred during signing, if any
            encryptionError: Error that occurred during encryption, if any
            
        Returns:
            MEMessageSecurityInformation: Initialized security information
        """
    
    def initWithSigners_isEncrypted_signingError_encryptionError_shouldBlockRemoteContent_localizedRemoteContentBlockingReason_(
        self,
        signers,  # List: List of MEMessageSigner objects
        isEncrypted: bool,  # Whether message is encrypted
        signingError,  # NSError or None: Signing error if any
        encryptionError,  # NSError or None: Encryption error if any
        shouldBlockRemoteContent: bool,  # Whether to block remote content
        localizedRemoteContentBlockingReason: str  # Reason for blocking content
    ):
        """
        Initialize security information with extended parameters including remote content blocking.
        
        Args:
            signers: List of message signers
            isEncrypted: Whether the message is encrypted
            signingError: Error that occurred during signing, if any
            encryptionError: Error that occurred during encryption, if any
            shouldBlockRemoteContent: Whether remote content should be blocked
            localizedRemoteContentBlockingReason: Localized reason for blocking remote content
            
        Returns:
            MEMessageSecurityInformation: Initialized security information
        """
    
    def isEncrypted(self) -> bool:
        """
        Check if the message is encrypted.
        
        Returns:
            bool: True if the message is encrypted
        """
    
    def shouldBlockRemoteContent(self) -> bool:
        """
        Check if remote content should be blocked.
        
        Returns:
            bool: True if remote content should be blocked
        """

MEMessageSigner

Handles message signing operations and signer information. Represents an entity that has signed a message.

class MEMessageSigner:
    def initWithEmailAddresses_signatureLabel_context_(
        self,
        emailAddresses,  # List: List of MEEmailAddress objects
        signatureLabel: str,  # Label for the signature
        context  # Any: Additional context
    ):
        """
        Initialize a message signer.
        
        Args:
            emailAddresses: List of email addresses associated with the signer
            signatureLabel: Label describing the signature
            context: Additional context for the signer
            
        Returns:
            MEMessageSigner: Initialized message signer
        """

MEEncodedOutgoingMessage

Represents an encoded outgoing message with signing/encryption status. Used for messages being sent from the Mail application.

class MEEncodedOutgoingMessage:
    def initWithRawData_isSigned_isEncrypted_(
        self,
        rawData,  # NSData: The raw message data
        isSigned: bool,  # Whether message is signed
        isEncrypted: bool  # Whether message is encrypted
    ):
        """
        Initialize an encoded outgoing message.
        
        Args:
            rawData: The raw message data
            isSigned: Whether the message is signed
            isEncrypted: Whether the message is encrypted
            
        Returns:
            MEEncodedOutgoingMessage: Initialized encoded message
        """
    
    def isSigned(self) -> bool:
        """
        Check if the message is signed.
        
        Returns:
            bool: True if the message is signed
        """
    
    def isEncrypted(self) -> bool:
        """
        Check if the message is encrypted.
        
        Returns:
            bool: True if the message is encrypted
        """

MEOutgoingMessageEncodingStatus

Status information for outgoing message encoding operations. Indicates what security operations are possible for an outgoing message.

class MEOutgoingMessageEncodingStatus:
    def initWithCanSign_canEncrypt_securityError_addressesFailingEncryption_(
        self,
        canSign: bool,  # Whether message can be signed
        canEncrypt: bool,  # Whether message can be encrypted
        securityError,  # NSError or None: Security error if any
        addressesFailingEncryption  # List: Addresses that failed encryption
    ):
        """
        Initialize encoding status.
        
        Args:
            canSign: Whether the message can be signed
            canEncrypt: Whether the message can be encrypted
            securityError: Any security error that occurred
            addressesFailingEncryption: List of addresses that failed encryption
            
        Returns:
            MEOutgoingMessageEncodingStatus: Initialized encoding status
        """
    
    def canSign(self) -> bool:
        """
        Check if the message can be signed.
        
        Returns:
            bool: True if the message can be signed
        """
    
    def canEncrypt(self) -> bool:
        """
        Check if the message can be encrypted.
        
        Returns:
            bool: True if the message can be encrypted
        """

MEMessageEncodingResult

Contains results of message encoding operations including the encoded message and any errors that occurred.

class MEMessageEncodingResult:
    def initWithEncodedMessage_signingError_encryptionError_(
        self,
        encodedMessage,  # MEEncodedOutgoingMessage: The encoded message
        signingError,  # NSError or None: Signing error if any
        encryptionError  # NSError or None: Encryption error if any
    ):
        """
        Initialize message encoding result.
        
        Args:
            encodedMessage: The encoded outgoing message
            signingError: Error that occurred during signing, if any
            encryptionError: Error that occurred during encryption, if any
            
        Returns:
            MEMessageEncodingResult: Initialized encoding result
        """

Security Error Constants

# Error domains
MEMessageSecurityErrorDomain: str  # Error domain for security-related errors

# Error codes
MEMessageSecurityEncodingError: int  # = 0, Error during message encoding
MEMessageSecurityDecodingError: int  # = 1, Error during message decoding

Usage Examples

Creating Security Information

import MailKit

# Create basic security information
security_info = MailKit.MEMessageSecurityInformation.alloc().initWithSigners_isEncrypted_signingError_encryptionError_(
    signers=[],
    isEncrypted=True,
    signingError=None,
    encryptionError=None
)

# Check encryption status
if security_info.isEncrypted():
    print("Message is encrypted")

# Create extended security information with content blocking
extended_security_info = MailKit.MEMessageSecurityInformation.alloc().initWithSigners_isEncrypted_signingError_encryptionError_shouldBlockRemoteContent_localizedRemoteContentBlockingReason_(
    signers=[],
    isEncrypted=True,
    signingError=None,
    encryptionError=None,
    shouldBlockRemoteContent=True,
    localizedRemoteContentBlockingReason="Untrusted sender"
)

if extended_security_info.shouldBlockRemoteContent():
    print("Remote content will be blocked")

Working with Message Signers

import MailKit

# Create email addresses for signer
email_addresses = [
    MailKit.MEEmailAddress.alloc().initWithRawString_("signer@example.com")
]

# Create message signer
signer = MailKit.MEMessageSigner.alloc().initWithEmailAddresses_signatureLabel_context_(
    emailAddresses=email_addresses,
    signatureLabel="Digital Signature",
    context=None
)

Handling Outgoing Message Encoding

import MailKit

# Create encoding status
encoding_status = MailKit.MEOutgoingMessageEncodingStatus.alloc().initWithCanSign_canEncrypt_securityError_addressesFailingEncryption_(
    canSign=True,
    canEncrypt=True,
    securityError=None,
    addressesFailingEncryption=[]
)

# Check capabilities
if encoding_status.canSign():
    print("Message can be signed")

if encoding_status.canEncrypt():
    print("Message can be encrypted")

# Create encoded outgoing message
encoded_message = MailKit.MEEncodedOutgoingMessage.alloc().initWithRawData_isSigned_isEncrypted_(
    rawData=message_data,
    isSigned=True,
    isEncrypted=True
)

# Verify encoding
if encoded_message.isSigned() and encoded_message.isEncrypted():
    print("Message is both signed and encrypted")

# Create encoding result
encoding_result = MailKit.MEMessageEncodingResult.alloc().initWithEncodedMessage_signingError_encryptionError_(
    encodedMessage=encoded_message,
    signingError=None,
    encryptionError=None
)

Install with Tessl CLI

npx tessl i tessl/pypi-pyobjc-framework-mailkit

docs

compose-sessions.md

extension-management.md

index.md

message-actions.md

message-classes.md

protocols-handlers.md

security-encryption.md

tile.json