-
- if(current_mail_filename[0]) {
-
- /* We first check all conditions but the body ones */
-
- for(n = 0; n < nb_search_conditions &&
- ((search_conditions[n].field_id == ID_BODY) ||
- xor(hits[n], search_conditions[n].negation)); n++);
-
- if(n == nb_search_conditions) {
-
- /* all conditions but the body ones are fine, check the body
- ones */
-
- if(nb_body_conditions > 0) {
- update_body_hits(current_mail_filename, current_position_in_mail,
- nb_search_conditions, search_conditions,
- nb_body_conditions,
- hits);
- }
-
- nb_fulfilled_body_conditions = 0;
-
- for(n = 0; n < nb_search_conditions; n++) {
- if(search_conditions[n].field_id == ID_BODY &&
- xor(hits[n], search_conditions[n].negation)) {
- nb_fulfilled_body_conditions++;
- }
- }
-
- if(nb_body_conditions == nb_fulfilled_body_conditions) {
- FILE *mail_file;
-
- mail_file = fopen(current_mail_filename, "r");
-
- if(!mail_file) {
- fprintf(stderr,
- "mymail: Cannot open mbox '%s' for mail extraction.\n",
- current_mail_filename);
- exit(EXIT_FAILURE);
- }
-
- fseek(mail_file, current_position_in_mail, SEEK_SET);
-
- if(fgets(raw_mbox_line, BUFFER_SIZE, mail_file)) {
- last_mbox_line_was_empty = 0;
- fprintf(output_file, "%s", raw_mbox_line);
- while(1) {
- if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
- (is_a_leading_from_line(last_mbox_line_was_empty, raw_mbox_line))
- )
- break;
- last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
- fprintf(output_file, "%s", raw_mbox_line);
- }
- }
-
- fclose(mail_file);
- }
- }
+ if(current_mail_filename[0] &&
+ check_full_mail_match(current_mail_filename,
+ nb_search_conditions, search_conditions,
+ nb_body_conditions, hits, current_position_in_mail)) {
+ nb_extracted_mails++;
+ extract_mail(current_mail_filename, current_position_in_mail, output_file);