| 1 | package JMAP::Validation::Checks::Message; | ||
| 2 | |||
| 3 | use Test2::Bundle::Extended; | ||
| 4 | |||
| 5 | # record types {{{ | ||
| 6 | |||
| 7 | my %Message_checks = ( | ||
| 8 | id => $JMAP::Validation::Checks::String::is_id, | ||
| 9 | blobId => $JMAP::Validation::Checks::String::is_string, | ||
| 10 | threadId => $JMAP::Validation::Checks::String::is_string, | ||
| 11 | mailboxIds => array { all_items $JMAP::Validation::Checks::String::is_string }, | ||
| 12 | inReplyToMessageId => in_set($JMAP::Validation::Checks::String::is_string, U()), | ||
| 13 | isUnread => $JMAP::Validation::Checks::Boolean::is_boolean, | ||
| 14 | isFlagged => $JMAP::Validation::Checks::Boolean::is_boolean, | ||
| 15 | isAnswered => $JMAP::Validation::Checks::Boolean::is_boolean, | ||
| 16 | isDraft => $JMAP::Validation::Checks::Boolean::is_boolean, | ||
| 17 | hasAttachment => $JMAP::Validation::Checks::Boolean::is_boolean, | ||
| 18 | headers => hash { all_items $JMAP::Validation::Checks::String::is_string }, | ||
| 19 | sender => in_set($JMAP::Validation::Checks::Emaler::is_Emailer, U()), | ||
| 20 | from => in_set(array { all_items $JMAP::Validation::Checks::Emaler::is_Emailer }, U()), | ||
| 21 | to => in_set(array { all_items $JMAP::Validation::Checks::Emaler::is_Emailer }, U()), | ||
| 22 | cc => in_set(array { all_items $JMAP::Validation::Checks::Emaler::is_Emailer }, U()), | ||
| 23 | bcc => in_set(array { all_items $JMAP::Validation::Checks::Emaler::is_Emailer }, U()), | ||
| 24 | replyTo => in_set(array { all_items $JMAP::Validation::Checks::Emaler::is_Emailer }, U()), | ||
| 25 | subject => $JMAP::Validation::Checks::String::is_string, | ||
| 26 | date => $JMAP::Validation::Checks::String::is_datetime, | ||
| 27 | size => $JMAP::Validation::Checks::Number::is_number, | ||
| 28 | preview => $JMAP::Validation::Checks::String::is_string, | ||
| 29 | textBody => in_set($JMAP::Validation::Checks::String::is_string, U()), | ||
| 30 | htmlBody => in_set($JMAP::Validation::Checks::String::is_string, U()), | ||
| 31 | attachments => in_set(array { all_items $JMAP::Validation::Checks::Attachment::is_Attachment }, U()), | ||
| 32 | |||
| 33 | # TODO: ignore the recursive check for now | ||
| 34 | # attachedMessages => in_set( | ||
| 35 | # hash { | ||
| 36 | # all_keys $JMAP::Validation::Checks::String::is_id; | ||
| 37 | # all_values $is_Message_embedded; | ||
| 38 | # ), String[Message]|null | ||
| 39 | ); | ||
| 40 | |||
| 41 | our $is_Message_embedded = hash { | ||
| 42 | (field $_ => $Message_checks{$_}) for qw{ | ||
| 43 | headers | ||
| 44 | from | ||
| 45 | to | ||
| 46 | cc | ||
| 47 | bcc | ||
| 48 | replyTo | ||
| 49 | subject | ||
| 50 | date | ||
| 51 | textBody | ||
| 52 | htmlBody | ||
| 53 | attachments | ||
| 54 | attachedMessages | ||
| 55 | }; | ||
| 56 | |||
| 57 | # TODO: don't end() until recursive check works | ||
| 58 | #end(); | ||
| 59 | }; | ||
| 60 | |||
| 61 | our $is_Message = hash { | ||
| 62 | (field $_ => $Message_checks{$_}) for qw{ | ||
| 63 | id | ||
| 64 | blobId | ||
| 65 | threadId | ||
| 66 | mailboxIds | ||
| 67 | inReplyToMessageId | ||
| 68 | isUnread | ||
| 69 | isFlagged | ||
| 70 | isAnswered | ||
| 71 | isDraft | ||
| 72 | hasAttachment | ||
| 73 | headers | ||
| 74 | sender | ||
| 75 | }; | ||
| 76 | |||
| 77 | # TODO: don't end() until recursive check works | ||
| 78 | #end(); | ||
| 79 | }; | ||
| 80 | |||
| 81 | # }}} | ||
| 82 | |||
| 83 | # request {{{ | ||
| 84 | # }}} | ||
| 85 | |||
| 86 | # response types {{{ | ||
| 87 | # }}} | ||
| 88 | |||
| 89 | 1; |