directories containing mbox files, and create a db file containing
for each mail a list of fields computed from the header, or (2)
read such a db file and get all the mails matching regexp-defined
- conditions on the fields.
+ conditions on the fields, to create a resulting mbox file.
It is low-tech, simple, light and fast.
fclose(mail_file);
}
-void search_in_db(const char *db_filename,
- int nb_search_conditions,
- struct search_condition *search_conditions,
- FILE *output_file) {
+int search_in_db(const char *db_filename,
+ int nb_search_conditions,
+ struct search_condition *search_conditions,
+ FILE *output_file) {
int hits[MAX_NB_SEARCH_CONDITIONS];
char raw_db_line[BUFFER_SIZE];
int already_written, m, n;
int nb_body_conditions, nb_fulfilled_body_conditions;
FILE *db_file;
+ int nb_extracted_mails;
+
+ nb_extracted_mails = 0;
if(!quiet) {
printf("Searching in '%s' ... ", db_filename);
}
if(nb_body_conditions == nb_fulfilled_body_conditions) {
+ nb_extracted_mails++;
extract_mail(current_mail_filename, current_position_in_mail, output_file);
}
}
printf("done.\n");
fflush(stdout);
}
+
+ return nb_extracted_mails;
}
-void recursive_search_in_db(const char *entry_name, regex_t *db_filename_regexp,
- int nb_search_conditions,
- struct search_condition *search_conditions,
- FILE *output_file) {
+int recursive_search_in_db(const char *entry_name, regex_t *db_filename_regexp,
+ int nb_search_conditions,
+ struct search_condition *search_conditions,
+ FILE *output_file) {
DIR *dir;
struct dirent *dir_e;
struct stat sb;
char subname[PATH_MAX + 1];
+ int nb_extracted_mails = 0;
if(lstat(entry_name, &sb) != 0) {
fprintf(stderr,
while((dir_e = readdir(dir))) {
if(!ignore_entry(dir_e->d_name)) {
snprintf(subname, PATH_MAX, "%s/%s", entry_name, dir_e->d_name);
- recursive_search_in_db(subname, db_filename_regexp,
- nb_search_conditions, search_conditions,
- output_file);
+ nb_extracted_mails += recursive_search_in_db(subname, db_filename_regexp,
+ nb_search_conditions, search_conditions,
+ output_file);
}
}
closedir(dir);
while(*s) { if(*s == '/') { filename = s+1; } s++; }
if(regexec(db_filename_regexp, filename, 0, 0, 0) == 0) {
- search_in_db(entry_name, nb_search_conditions, search_conditions, output_file);
+ nb_extracted_mails +=
+ search_in_db(entry_name, nb_search_conditions, search_conditions, output_file);
}
}
+
+ return nb_extracted_mails;
}
/*********************************************************************/
}
else {
+ int nb_extracted_mails = 0;
if(nb_search_conditions > 0) {
exit(EXIT_FAILURE);
}
- recursive_search_in_db(db_root_path, &db_filename_regexp,
- nb_search_conditions, search_conditions,
- output_file);
+ nb_extracted_mails += recursive_search_in_db(db_root_path, &db_filename_regexp,
+ nb_search_conditions, search_conditions,
+ output_file);
regfree(&db_filename_regexp);
}
s = parse_token(db_filename, PATH_MAX + 1, ';', s);
if(db_filename[0]) {
- search_in_db(db_filename, nb_search_conditions, search_conditions, output_file);
+ nb_extracted_mails +=
+ search_in_db(db_filename, nb_search_conditions, search_conditions, output_file);
}
}
}
/* Search in all db files listed in the command arguments */
while(optind < argc) {
- search_in_db(argv[optind], nb_search_conditions, search_conditions, output_file);
+ nb_extracted_mails +=
+ search_in_db(argv[optind], nb_search_conditions, search_conditions, output_file);
optind++;
}
}
+
+ if(!quiet) {
+ if(nb_extracted_mails > 0) {
+ printf("Found %d matching mails.\n", nb_extracted_mails);
+ } else {
+ printf("No matching mail found.\n");
+ }
+ }
+
}
for(n = 0; n < nb_search_conditions; n++) {