+int check_full_mail_match(char *current_mail_filename,
+ time_t mail_time,
+ int nb_search_conditions,
+ struct search_condition *search_conditions,
+ int nb_body_conditions,
+ int *hits,
+ int current_position_in_mail) {
+ int n, nb_fulfilled_body_conditions;
+
+ for(n = 0; n < nb_search_conditions; n++) {
+ if(search_conditions[n].db_key == ID_TIME_INTERVAL) {
+ hits[n] = (mail_time >= search_conditions[n].time_start &&
+ (search_conditions[n].time_stop == 0 ||
+ mail_time <= search_conditions[n].time_stop));
+ }
+ }
+
+ /* We first check all conditions but the body ones */
+
+ for(n = 0; n < nb_search_conditions &&
+ ((search_conditions[n].db_key == ID_BODY) ||
+ xor(hits[n], search_conditions[n].negation)); n++);
+
+ if(n == nb_search_conditions) {
+
+ /* Now check the body ones */
+
+ nb_fulfilled_body_conditions = 0;
+
+ if(nb_body_conditions > 0) {
+ update_body_hits(current_mail_filename, current_position_in_mail,
+ nb_search_conditions, search_conditions,
+ nb_body_conditions,
+ hits);
+
+ for(n = 0; n < nb_search_conditions; n++) {
+ if(search_conditions[n].db_key == ID_BODY &&
+ xor(hits[n], search_conditions[n].negation)) {
+ nb_fulfilled_body_conditions++;
+ }
+ }
+ }
+ return nb_body_conditions == nb_fulfilled_body_conditions;
+ } else {
+ return 0;
+ }
+}
+
+/* We use the mail leading line time by default, and if we should and
+ can, we update with the Date: field */
+
+void update_time(int db_key, const char *db_value, time_t *t) {
+ const char *c;
+ struct tm tm;
+
+ if(db_key == ID_LEADING_LINE) {
+ c = db_value;
+ while(*c && *c != ' ') c++; while(*c && *c == ' ') c++;
+ /* printf("From %s", db_value); */
+ strptime(c, "%a %b %e %k:%M:%S %Y", &tm);
+ *t = mktime(&tm);
+ } else {
+ if(!global_use_leading_time) {
+ if(db_key == ID_DATE) {
+ if(strptime(db_value, "%a, %d %b %Y %k:%M:%S", &tm) ||
+ strptime(db_value, "%d %b %Y %k:%M:%S", &tm)) {
+ /* printf("Date: %s", db_value); */
+ *t = mktime(&tm);
+ }
+ }
+ }
+ }
+}
+