My agentic slop goes here. Not intended for anyone else!
at main 7.6 kB view raw
1(** JMAP Email Validation Rules. 2 3 This module implements comprehensive validation rules for JMAP email objects 4 and related entities as specified in RFC 8621. Provides validation functions 5 for ensuring data integrity and RFC compliance. 6 7 @see <https://www.rfc-editor.org/rfc/rfc8621.html> RFC 8621: JMAP for Mail 8*) 9 10(** {1 Email Object Validation} *) 11 12(** Validation error types *) 13type validation_error = [ 14 | `InvalidKeyword of string * string (** Invalid keyword format with keyword and reason *) 15 | `InvalidEmailAddress of string (** Invalid email address format *) 16 | `InvalidSize of int * int (** Size exceeds limit (actual, max) *) 17 | `InvalidMailboxId of string (** Invalid mailbox ID format *) 18 | `InvalidMessageId of string (** Invalid Message-ID format *) 19 | `InvalidHeader of string * string (** Invalid header name/value *) 20 | `InvalidDate of string (** Invalid date format *) 21 | `DuplicateRole of string (** Duplicate mailbox role *) 22 | `InvalidRole of string (** Invalid mailbox role *) 23 | `MailboxHierarchyCycle of string list (** Circular mailbox hierarchy *) 24 | `InvalidIdentityPermission of string (** Invalid identity permission *) 25 | `InvalidSubmissionTime of string (** Invalid email submission time *) 26] 27 28(** Format validation error for display *) 29val string_of_validation_error : validation_error -> string 30 31(** {1 Keywords Validation} *) 32 33(** Validate email keywords according to RFC 8621 Section 4.1.1. 34 35 Keywords must be: 36 - Lowercase ASCII characters only 37 - No whitespace or control characters 38 - Maximum length of 255 characters 39 - Valid UTF-8 encoding 40 41 @param keywords Keywords to validate 42 @return Ok () if valid, Error with invalid keywords *) 43val validate_keywords : Jmap_email.Keywords.t -> (unit, validation_error list) result 44 45(** Validate a single keyword string format. 46 47 @param keyword Keyword string to validate 48 @return Ok () if valid, Error with reason *) 49val validate_keyword_format : string -> (unit, validation_error) result 50 51(** Check if a keyword is a standard system keyword. 52 53 @param keyword Keyword to check 54 @return true if it's a standard system keyword *) 55val is_system_keyword : string -> bool 56 57(** Get list of all standard system keywords. 58 59 @return List of standard JMAP keywords *) 60val standard_keywords : string list 61 62(** {1 Email Address Validation} *) 63 64(** Validate email address format according to RFC 5322. 65 66 @param address Email address to validate 67 @return Ok () if valid, Error with reason *) 68val validate_email_address : Jmap_email.Address.t -> (unit, validation_error) result 69 70(** Validate email address string format. 71 72 @param addr_str Email address string to validate 73 @return Ok () if valid, Error with reason *) 74val validate_email_address_string : string -> (unit, validation_error) result 75 76(** {1 Size Constraints Validation} *) 77 78(** Validate email object size constraints. 79 80 Checks various size limits according to RFC 8621: 81 - Maximum email size 82 - Maximum header size 83 - Maximum attachment count 84 85 @param email Email object to validate 86 @return Ok () if valid, Error with constraint violations *) 87val validate_size_constraints : Jmap_email.Email.Email.t -> (unit, validation_error list) result 88 89(** Validate mailbox name size constraints. 90 91 @param name Mailbox name to validate 92 @return Ok () if valid, Error with reason *) 93val validate_mailbox_name_size : string -> (unit, validation_error) result 94 95(** {1 Mailbox Validation} *) 96 97(** Validate mailbox role uniqueness within an account. 98 99 Each account should have at most one mailbox of each standard role. 100 101 @param mailboxes List of mailboxes in the account 102 @return Ok () if valid, Error with duplicate roles *) 103val validate_mailbox_role_uniqueness : Jmap_email.Mailbox.Mailbox.t list -> (unit, validation_error list) result 104 105(** Validate mailbox hierarchy for cycles. 106 107 Ensures parent-child relationships don't create circular references. 108 109 @param mailboxes List of mailboxes to check 110 @return Ok () if valid, Error with cycle information *) 111val validate_mailbox_hierarchy : Jmap_email.Mailbox.Mailbox.t list -> (unit, validation_error list) result 112 113(** Validate mailbox name collision rules. 114 115 @param mailboxes List of mailboxes to check 116 @return Ok () if valid, Error with name collisions *) 117val validate_mailbox_name_collisions : Jmap_email.Mailbox.Mailbox.t list -> (unit, validation_error list) result 118 119(** {1 Email Submission Validation} *) 120 121(** Validate SMTP envelope format. 122 123 @param envelope SMTP envelope to validate 124 @return Ok () if valid, Error with validation issues *) 125val validate_smtp_envelope : Jmap_email.Submission.Envelope.t -> (unit, validation_error list) result 126 127(** Validate email send-time constraints. 128 129 @param send_at Optional send time to validate 130 @return Ok () if valid, Error with constraint violation *) 131val validate_send_time_constraints : Jmap.Date.t option -> (unit, validation_error) result 132 133(** Validate identity permission for sending. 134 135 @param identity Identity to validate 136 @param sender_email Sender email address 137 @return Ok () if valid, Error with permission issue *) 138val validate_identity_permission : Jmap_email.Identity.Identity.t -> string -> (unit, validation_error) result 139 140(** {1 Header Validation} *) 141 142(** Validate email header format and content. 143 144 @param header Header to validate 145 @return Ok () if valid, Error with validation issue *) 146val validate_header : Jmap_email.Header.t -> (unit, validation_error) result 147 148(** Validate Message-ID header format. 149 150 @param message_id Message-ID value to validate 151 @return Ok () if valid, Error with format issue *) 152val validate_message_id : string -> (unit, validation_error) result 153 154(** Validate References header format. 155 156 @param references References header value to validate 157 @return Ok () if valid, Error with format issue *) 158val validate_references : string -> (unit, validation_error) result 159 160(** {1 Date Validation} *) 161 162(** Validate date format and constraints. 163 164 @param date Date to validate 165 @return Ok () if valid, Error with validation issue *) 166val validate_date : Jmap.Date.t -> (unit, validation_error) result 167 168(** Validate date string format. 169 170 @param date_str Date string to validate 171 @return Ok () if valid, Error with format issue *) 172val validate_date_string : string -> (unit, validation_error) result 173 174(** {1 Comprehensive Validation} *) 175 176(** Validate complete email object with all constraints. 177 178 Performs comprehensive validation including: 179 - Keywords format 180 - Email addresses 181 - Size constraints 182 - Headers 183 - Dates 184 185 @param email Email object to validate 186 @return Ok () if valid, Error with all validation issues *) 187val validate_email_complete : Jmap_email.Email.Email.t -> (unit, validation_error list) result 188 189(** Validate complete mailbox object with all constraints. 190 191 @param mailbox Mailbox object to validate 192 @return Ok () if valid, Error with validation issues *) 193val validate_mailbox_complete : Jmap_email.Mailbox.Mailbox.t -> (unit, validation_error list) result 194 195(** Validate complete email submission with all constraints. 196 197 @param submission Email submission to validate 198 @return Ok () if valid, Error with validation issues *) 199val validate_submission_complete : Jmap_email.Submission.EmailSubmission.t -> (unit, validation_error list) result