+ nb_fulfilled_body_conditions = 0;
+
+ if(nb_body_conditions > 0) {
+ FILE *mail_file;
+ int header;
+
+ header = 1;
+ mail_file = fopen(current_mail_filename, "r");
+
+ if(!mail_file) {
+ fprintf(stderr, "mymail: Cannot open mbox '%s'.\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)) {
+ while(nb_fulfilled_body_conditions < nb_body_conditions) {
+ last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
+
+ if(last_mbox_line_was_empty) { header = 0; }
+
+ if(!header) {
+ for(n = 0; n < nb_search_conditions; n++) {
+ if(search_conditions[n].field_id == ID_BODY && !hits[n]) {
+ hits[n] =
+ (regexec(&search_conditions[n].regexp, raw_mbox_line, 0, 0, 0) == 0);
+ if(hits[n]) {
+ fprintf(stderr, "** %d %s", header, raw_mbox_line);
+ nb_fulfilled_body_conditions++;
+ }
+ }
+ }
+ }
+
+ if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
+ (last_mbox_line_was_empty && strncmp(raw_mbox_line, "From ", 5) == 0)) break;
+ }
+ }
+
+ fclose(mail_file);
+ }
+
+ 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'.\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 = 1;
+ printf("%s", raw_mbox_line);
+ while(1) {
+ if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
+ (last_mbox_line_was_empty && strncmp(raw_mbox_line, "From ", 5) == 0)) break;
+ last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
+ printf("%s", raw_mbox_line);
+ }
+ }
+
+ fclose(mail_file);
+ }
+ }
+
+ for(n = 0; n < nb_search_conditions; n++) { hits[n] = 0; }
+
+ position_in_file_string = mbox_value;
+ mail_filename = segment_next_field(mbox_value);