1 #ifndef MAIL_SEARCH_MIMEPART_H 2 #define MAIL_SEARCH_MIMEPART_H 3 4 enum mail_search_mime_arg_type { 5 SEARCH_MIME_OR, 6 SEARCH_MIME_SUB, 7 8 /* sizes */ 9 SEARCH_MIME_SIZE_EQUAL, 10 SEARCH_MIME_SIZE_LARGER, 11 SEARCH_MIME_SIZE_SMALLER, 12 13 /* part properties */ 14 SEARCH_MIME_DESCRIPTION, 15 SEARCH_MIME_DISPOSITION_TYPE, 16 SEARCH_MIME_DISPOSITION_PARAM, 17 SEARCH_MIME_ENCODING, 18 SEARCH_MIME_ID, 19 SEARCH_MIME_LANGUAGE, 20 SEARCH_MIME_LOCATION, 21 SEARCH_MIME_MD5, 22 23 /* content-type */ 24 SEARCH_MIME_TYPE, 25 SEARCH_MIME_SUBTYPE, 26 SEARCH_MIME_PARAM, 27 28 /* headers */ 29 SEARCH_MIME_HEADER, 30 31 /* body */ 32 SEARCH_MIME_BODY, 33 SEARCH_MIME_TEXT, 34 35 /* message */ 36 SEARCH_MIME_CC, 37 SEARCH_MIME_BCC, 38 SEARCH_MIME_FROM, 39 SEARCH_MIME_IN_REPLY_TO, 40 SEARCH_MIME_MESSAGE_ID, 41 SEARCH_MIME_REPLY_TO, 42 SEARCH_MIME_SENDER, 43 SEARCH_MIME_SENTBEFORE, 44 SEARCH_MIME_SENTON, /* time must point to beginning of the day */ 45 SEARCH_MIME_SENTSINCE, 46 SEARCH_MIME_SUBJECT, 47 SEARCH_MIME_TO, 48 49 /* relations */ 50 SEARCH_MIME_PARENT, 51 SEARCH_MIME_CHILD, 52 53 /* position */ 54 SEARCH_MIME_DEPTH_EQUAL, 55 SEARCH_MIME_DEPTH_MIN, 56 SEARCH_MIME_DEPTH_MAX, 57 SEARCH_MIME_INDEX, 58 59 /* filename */ 60 SEARCH_MIME_FILENAME_IS, 61 SEARCH_MIME_FILENAME_CONTAINS, 62 SEARCH_MIME_FILENAME_BEGINS, 63 SEARCH_MIME_FILENAME_ENDS 64 }; 65 66 struct mail_search_mime_arg { 67 /* NOTE: when adding new fields, make sure mail_search_mime_arg_dup_one() 68 and mail_search_mime_arg_one_equals() are updated. */ 69 struct mail_search_mime_arg *next; 70 71 enum mail_search_mime_arg_type type; 72 union { 73 struct mail_search_mime_arg *subargs; 74 const char *str; 75 time_t time; 76 uoff_t size; 77 unsigned int number; 78 } value; 79 80 void *context; 81 const char *field_name; /* for SEARCH_HEADER* */ 82 bool match_not:1; /* result = !result */ 83 bool match_always:1; /* result = 1 always */ 84 bool nonmatch_always:1; /* result = 0 always */ 85 86 int result; /* -1 = unknown, 0 = unmatched, 1 = matched */ 87 }; 88 89 struct mail_search_mime_part { 90 struct mail_search_mime_arg *args; 91 92 bool simplified:1; 93 }; 94 95 typedef void 96 mail_search_mime_foreach_callback_t(struct mail_search_mime_arg *arg, 97 void *context); 98 99 /* Returns TRUE if the two mimepart search keys are fully compatible. */ 100 bool mail_search_mime_parts_equal(const struct mail_search_mime_part *mpart1, 101 const struct mail_search_mime_part *mpart2); 102 /* Same as mail_search_mime_part_equal(), but for individual 103 mail_search_mime_arg structs. All the siblings of arg1 and arg2 are 104 also compared. */ 105 bool mail_search_mime_arg_equals(const struct mail_search_mime_arg *arg1, 106 const struct mail_search_mime_arg *arg2); 107 /* Same as mail_search_mime_arg_equals(), but don't compare siblings. */ 108 bool mail_search_mime_arg_one_equals(const struct mail_search_mime_arg *arg1, 109 const struct mail_search_mime_arg *arg2); 110 111 struct mail_search_mime_part * 112 mail_search_mime_part_dup(pool_t pool, 113 const struct mail_search_mime_part *mpart); 114 struct mail_search_mime_arg * 115 mail_search_mime_arg_dup(pool_t pool, 116 const struct mail_search_mime_arg *arg); 117 118 /* Reset the results in search arguments. match_always is reset only if 119 full_reset is TRUE. */ 120 void mail_search_mime_args_reset(struct mail_search_mime_arg *args, 121 bool full_reset); 122 123 /* goes through arguments in list that don't have a result yet. 124 Returns 1 = search matched, 0 = search unmatched, -1 = don't know yet */ 125 int mail_search_mime_args_foreach(struct mail_search_mime_arg *args, 126 mail_search_mime_foreach_callback_t *callback, 127 void *context) ATTR_NULL(3); 128 #define mail_search_mime_args_foreach(args, callback, context) \ 129 mail_search_mime_args_foreach(args - \ 130 CALLBACK_TYPECHECK(callback, void (*)( \ 131 struct mail_search_mime_arg *, typeof(context))), \ 132 (mail_search_mime_foreach_callback_t *)callback, context) 133 134 /* Simplify/optimize search arguments. Afterwards all OR/SUB args are 135 guaranteed to have match_not=FALSE. */ 136 void mail_search_mime_simplify(struct mail_search_mime_part *args); 137 138 /* Appends MIMEPART search key to the dest string and returns TRUE. */ 139 bool mail_search_mime_part_to_imap(string_t *dest, 140 const struct mail_search_mime_part *mpart, const char **error_r); 141 /* Like mail_search_mime_part_to_imap(), but append only a single MIMEPART 142 key. */ 143 bool mail_search_mime_arg_to_imap(string_t *dest, 144 const struct mail_search_mime_arg *arg, const char **error_r); 145 146 #endif 147