or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

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

security-encryption.mddocs/

0

# Security and Encryption

1

2

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

3

4

## Capabilities

5

6

### MEMessageSecurityInformation

7

8

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

9

10

```python { .api }

11

class MEMessageSecurityInformation:

12

def initWithSigners_isEncrypted_signingError_encryptionError_(

13

self,

14

signers, # List: List of MEMessageSigner objects

15

isEncrypted: bool, # Whether message is encrypted

16

signingError, # NSError or None: Signing error if any

17

encryptionError # NSError or None: Encryption error if any

18

):

19

"""

20

Initialize security information with basic parameters.

21

22

Args:

23

signers: List of message signers

24

isEncrypted: Whether the message is encrypted

25

signingError: Error that occurred during signing, if any

26

encryptionError: Error that occurred during encryption, if any

27

28

Returns:

29

MEMessageSecurityInformation: Initialized security information

30

"""

31

32

def initWithSigners_isEncrypted_signingError_encryptionError_shouldBlockRemoteContent_localizedRemoteContentBlockingReason_(

33

self,

34

signers, # List: List of MEMessageSigner objects

35

isEncrypted: bool, # Whether message is encrypted

36

signingError, # NSError or None: Signing error if any

37

encryptionError, # NSError or None: Encryption error if any

38

shouldBlockRemoteContent: bool, # Whether to block remote content

39

localizedRemoteContentBlockingReason: str # Reason for blocking content

40

):

41

"""

42

Initialize security information with extended parameters including remote content blocking.

43

44

Args:

45

signers: List of message signers

46

isEncrypted: Whether the message is encrypted

47

signingError: Error that occurred during signing, if any

48

encryptionError: Error that occurred during encryption, if any

49

shouldBlockRemoteContent: Whether remote content should be blocked

50

localizedRemoteContentBlockingReason: Localized reason for blocking remote content

51

52

Returns:

53

MEMessageSecurityInformation: Initialized security information

54

"""

55

56

def isEncrypted(self) -> bool:

57

"""

58

Check if the message is encrypted.

59

60

Returns:

61

bool: True if the message is encrypted

62

"""

63

64

def shouldBlockRemoteContent(self) -> bool:

65

"""

66

Check if remote content should be blocked.

67

68

Returns:

69

bool: True if remote content should be blocked

70

"""

71

```

72

73

### MEMessageSigner

74

75

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

76

77

```python { .api }

78

class MEMessageSigner:

79

def initWithEmailAddresses_signatureLabel_context_(

80

self,

81

emailAddresses, # List: List of MEEmailAddress objects

82

signatureLabel: str, # Label for the signature

83

context # Any: Additional context

84

):

85

"""

86

Initialize a message signer.

87

88

Args:

89

emailAddresses: List of email addresses associated with the signer

90

signatureLabel: Label describing the signature

91

context: Additional context for the signer

92

93

Returns:

94

MEMessageSigner: Initialized message signer

95

"""

96

```

97

98

### MEEncodedOutgoingMessage

99

100

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

101

102

```python { .api }

103

class MEEncodedOutgoingMessage:

104

def initWithRawData_isSigned_isEncrypted_(

105

self,

106

rawData, # NSData: The raw message data

107

isSigned: bool, # Whether message is signed

108

isEncrypted: bool # Whether message is encrypted

109

):

110

"""

111

Initialize an encoded outgoing message.

112

113

Args:

114

rawData: The raw message data

115

isSigned: Whether the message is signed

116

isEncrypted: Whether the message is encrypted

117

118

Returns:

119

MEEncodedOutgoingMessage: Initialized encoded message

120

"""

121

122

def isSigned(self) -> bool:

123

"""

124

Check if the message is signed.

125

126

Returns:

127

bool: True if the message is signed

128

"""

129

130

def isEncrypted(self) -> bool:

131

"""

132

Check if the message is encrypted.

133

134

Returns:

135

bool: True if the message is encrypted

136

"""

137

```

138

139

### MEOutgoingMessageEncodingStatus

140

141

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

142

143

```python { .api }

144

class MEOutgoingMessageEncodingStatus:

145

def initWithCanSign_canEncrypt_securityError_addressesFailingEncryption_(

146

self,

147

canSign: bool, # Whether message can be signed

148

canEncrypt: bool, # Whether message can be encrypted

149

securityError, # NSError or None: Security error if any

150

addressesFailingEncryption # List: Addresses that failed encryption

151

):

152

"""

153

Initialize encoding status.

154

155

Args:

156

canSign: Whether the message can be signed

157

canEncrypt: Whether the message can be encrypted

158

securityError: Any security error that occurred

159

addressesFailingEncryption: List of addresses that failed encryption

160

161

Returns:

162

MEOutgoingMessageEncodingStatus: Initialized encoding status

163

"""

164

165

def canSign(self) -> bool:

166

"""

167

Check if the message can be signed.

168

169

Returns:

170

bool: True if the message can be signed

171

"""

172

173

def canEncrypt(self) -> bool:

174

"""

175

Check if the message can be encrypted.

176

177

Returns:

178

bool: True if the message can be encrypted

179

"""

180

```

181

182

### MEMessageEncodingResult

183

184

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

185

186

```python { .api }

187

class MEMessageEncodingResult:

188

def initWithEncodedMessage_signingError_encryptionError_(

189

self,

190

encodedMessage, # MEEncodedOutgoingMessage: The encoded message

191

signingError, # NSError or None: Signing error if any

192

encryptionError # NSError or None: Encryption error if any

193

):

194

"""

195

Initialize message encoding result.

196

197

Args:

198

encodedMessage: The encoded outgoing message

199

signingError: Error that occurred during signing, if any

200

encryptionError: Error that occurred during encryption, if any

201

202

Returns:

203

MEMessageEncodingResult: Initialized encoding result

204

"""

205

```

206

207

## Security Error Constants

208

209

```python { .api }

210

# Error domains

211

MEMessageSecurityErrorDomain: str # Error domain for security-related errors

212

213

# Error codes

214

MEMessageSecurityEncodingError: int # = 0, Error during message encoding

215

MEMessageSecurityDecodingError: int # = 1, Error during message decoding

216

```

217

218

## Usage Examples

219

220

### Creating Security Information

221

222

```python

223

import MailKit

224

225

# Create basic security information

226

security_info = MailKit.MEMessageSecurityInformation.alloc().initWithSigners_isEncrypted_signingError_encryptionError_(

227

signers=[],

228

isEncrypted=True,

229

signingError=None,

230

encryptionError=None

231

)

232

233

# Check encryption status

234

if security_info.isEncrypted():

235

print("Message is encrypted")

236

237

# Create extended security information with content blocking

238

extended_security_info = MailKit.MEMessageSecurityInformation.alloc().initWithSigners_isEncrypted_signingError_encryptionError_shouldBlockRemoteContent_localizedRemoteContentBlockingReason_(

239

signers=[],

240

isEncrypted=True,

241

signingError=None,

242

encryptionError=None,

243

shouldBlockRemoteContent=True,

244

localizedRemoteContentBlockingReason="Untrusted sender"

245

)

246

247

if extended_security_info.shouldBlockRemoteContent():

248

print("Remote content will be blocked")

249

```

250

251

### Working with Message Signers

252

253

```python

254

import MailKit

255

256

# Create email addresses for signer

257

email_addresses = [

258

MailKit.MEEmailAddress.alloc().initWithRawString_("signer@example.com")

259

]

260

261

# Create message signer

262

signer = MailKit.MEMessageSigner.alloc().initWithEmailAddresses_signatureLabel_context_(

263

emailAddresses=email_addresses,

264

signatureLabel="Digital Signature",

265

context=None

266

)

267

```

268

269

### Handling Outgoing Message Encoding

270

271

```python

272

import MailKit

273

274

# Create encoding status

275

encoding_status = MailKit.MEOutgoingMessageEncodingStatus.alloc().initWithCanSign_canEncrypt_securityError_addressesFailingEncryption_(

276

canSign=True,

277

canEncrypt=True,

278

securityError=None,

279

addressesFailingEncryption=[]

280

)

281

282

# Check capabilities

283

if encoding_status.canSign():

284

print("Message can be signed")

285

286

if encoding_status.canEncrypt():

287

print("Message can be encrypted")

288

289

# Create encoded outgoing message

290

encoded_message = MailKit.MEEncodedOutgoingMessage.alloc().initWithRawData_isSigned_isEncrypted_(

291

rawData=message_data,

292

isSigned=True,

293

isEncrypted=True

294

)

295

296

# Verify encoding

297

if encoded_message.isSigned() and encoded_message.isEncrypted():

298

print("Message is both signed and encrypted")

299

300

# Create encoding result

301

encoding_result = MailKit.MEMessageEncodingResult.alloc().initWithEncodedMessage_signingError_encryptionError_(

302

encodedMessage=encoded_message,

303

signingError=None,

304

encryptionError=None

305

)

306

```