add 25 MB per-file attachment size guard to MessageFormatter
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -71,10 +71,21 @@ public enum MessageFormatter: Sendable {
|
||||
}
|
||||
|
||||
/// Format a multipart/mixed message with attachments.
|
||||
/// Throws `MessageFormatterError.attachmentTooLarge` if any file exceeds 25 MB.
|
||||
public static func formatMultipart(
|
||||
_ message: OutgoingMessage,
|
||||
attachments: [(filename: String, mimeType: String, data: Data)]
|
||||
) -> String {
|
||||
) throws -> String {
|
||||
let maxSize = 25 * 1024 * 1024 // 25 MB
|
||||
for attachment in attachments {
|
||||
if attachment.data.count > maxSize {
|
||||
throw MessageFormatterError.attachmentTooLarge(
|
||||
filename: attachment.filename,
|
||||
size: attachment.data.count
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
let boundary = "=_MagnumOpus_\(UUID().uuidString)"
|
||||
|
||||
var headers: [(String, String)] = []
|
||||
@@ -184,3 +195,7 @@ public enum MessageFormatter: Sendable {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
public enum MessageFormatterError: Error {
|
||||
case attachmentTooLarge(filename: String, size: Int)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user