+ 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]) {
+ nb_fulfilled_body_conditions++;
+ }
+ }
+ }
+ }
+
+ if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
+ (last_mbox_line_was_empty &&
+ is_a_leading_from_line(raw_mbox_line)))
+ 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' 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) ||
+ (last_mbox_line_was_empty &&
+ is_a_leading_from_line(raw_mbox_line))
+ )
+ break;
+ last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
+ fprintf(output_file, "%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);