package limits import "errors" // Default mail body and attachment size limits (bytes unless noted). const ( MaxBodyFieldBytes = 4 << 20 // 4 MiB per body_text / body_html field MaxSendRequestBodyBytes = 5 << 20 // 5 MiB JSON send/draft request MaxAttachmentBytes = 25 << 20 // 25 MiB per attachment file MaxMultipartUploadBytes = 26 << 20 // 26 MiB multipart form (file + fields) MaxAttachmentsPerMessage = 50 MaxTotalAttachmentsPerMessageBytes = 100 << 20 // 100 MiB combined per message/draft ) var ( ErrAttachmentTooLarge = errors.New("attachment too large") ErrTooManyAttachments = errors.New("too many attachments") ErrAttachmentsTotalTooLarge = errors.New("attachments total size exceeded") ) // ValidateAttachmentSize rejects a single attachment larger than MaxAttachmentBytes. func ValidateAttachmentSize(size int64) error { if size > MaxAttachmentBytes { return ErrAttachmentTooLarge } return nil } // ValidateAttachmentQuota rejects when adding newSize would exceed per-message count or total size limits. func ValidateAttachmentQuota(existingCount int, existingTotalBytes int64, newSize int64) error { if existingCount >= MaxAttachmentsPerMessage { return ErrTooManyAttachments } if existingTotalBytes+newSize > MaxTotalAttachmentsPerMessageBytes { return ErrAttachmentsTotalTooLarge } return nil }