3 * Copyright (c) 2013 Francois Fleuret
4 * Written by Francois Fleuret <francois@fleuret.org>
6 * This file is part of mymail.
8 * mymail is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 3 as
10 * published by the Free Software Foundation.
12 * mymail is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with mymail. If not, see <http://www.gnu.org/licenses/>.
24 This command is a dumb mail indexer. It can either (1) scan
25 directories containing mbox files, and create a db file containing
26 for each mail a list of fields computed from the header, or (2)
27 read such a db file and get all the mails matching regexp-defined
28 conditions on the fields.
30 It is low-tech, simple, light and fast.
48 #define MYMAIL_DB_MAGIC_TOKEN "mymail_index_file"
49 #define VERSION "0.9.1"
51 #define MAX_NB_SEARCH_CONDITIONS 10
53 #define BUFFER_SIZE 65536
54 #define TOKEN_BUFFER_SIZE 1024
56 regex_t leading_from_line_regexp;
58 /* Global variables! */
63 /********************************************************************/
78 static char *field_names[] = {
90 /********************************************************************/
92 struct search_condition {
96 time_t interval_start, interval_stop;
99 /********************************************************************/
101 struct parsable_field {
107 static struct parsable_field fields_to_parse[] = {
111 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
116 "^\\([Ff][Rr][Oo][Mm]:\\|[Rr][Ee][Pp][Ll][Yy]-[Tt][Oo]:\\|[Ss][Ee][Nn][Dd][Ee][Rr]:\\)",
117 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
122 "^\\([Tt][Oo]\\|[Cc][Cc]\\|[Bb][Cc][Cc]\\): ",
123 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
128 "^[Ss][Uu][Bb][Jj][Ee][Cc][Tt]: ",
129 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
134 "^[Dd][Aa][Tt][Ee]: ",
135 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
140 /********************************************************************/
142 int xor(int a, int b) {
143 return (a && !b) || (!a && b);
146 char *parse_token(char *token_buffer, size_t token_buffer_size,
147 char separator, char *string) {
148 char *u = token_buffer;
149 while(u < token_buffer + token_buffer_size - 1 && *string &&
150 *string != separator) {
151 *(u++) = *(string++);
153 while(*string == separator) string++;
158 void remove_eof(char *c) {
159 while(*c && *c != '\n' && *c != '\r') c++;
163 /********************************************************************/
165 /* malloc with error checking. */
167 void *safe_malloc(size_t n) {
171 "mymail: cannot allocate memory: %s\n", strerror(errno));
177 /*********************************************************************/
179 void print_version(FILE *out) {
180 fprintf(out, "mymail version %s (%s)\n", VERSION, UNAME);
183 void print_usage(FILE *out) {
185 fprintf(out, "Written by Francois Fleuret <francois@fleuret.org>.\n");
187 fprintf(out, "Usage: mymail [options] [<mbox dir1> [<mbox dir2> ...]|<db file1> [<db file2> ...]]\n");
189 fprintf(out, " -h, --help\n");
190 fprintf(out, " show this help\n");
191 fprintf(out, " -v, --version\n");
192 fprintf(out, " print the version number\n");
193 fprintf(out, " -q, --quiet\n");
194 fprintf(out, " do not print information during search\n");
195 fprintf(out, " -p <db filename pattern>, --db-pattern <db filename pattern>\n");
196 fprintf(out, " set the db filename pattern for recursive search\n");
197 fprintf(out, " -r <db root path>, --db-root <db root path>\n");
198 fprintf(out, " set the db root path for recursive search\n");
199 fprintf(out, " -l <db filename list>, --db-list <db filename list>\n");
200 fprintf(out, " set the semicolon-separated list of db files for search\n");
201 fprintf(out, " -s <search pattern>, --search <search pattern>\n");
202 fprintf(out, " search for matching mails in the db file\n");
203 fprintf(out, " -d <db filename>, --db-file <db filename>\n");
204 fprintf(out, " set the db filename for indexing\n");
205 fprintf(out, " -i, --index\n");
206 fprintf(out, " index mails\n");
207 fprintf(out, " -o <output filename>, --output <output filename>\n");
208 fprintf(out, " set the result file, use stdout if unset\n");
211 /*********************************************************************/
213 time_t time_for_past_day(int day) {
219 delta_day = (7 + tm->tm_wday - day) % 7 + 1;
220 return t - delta_day * 3600 * 24 + tm->tm_sec + 60 * tm->tm_min + 3600 * tm->tm_hour;
223 /*********************************************************************/
225 int ignore_entry(const char *name) {
227 /* strcmp(name, ".") == 0 || */
228 /* strcmp(name, "..") == 0 || */
229 (name[0] == '.' && name[1] != '/');
232 int is_a_leading_from_line(char *s) {
233 return strncmp(s, "From ", 5) == 0 &&
234 regexec(&leading_from_line_regexp, s, 0, 0, 0) == 0;
237 int mbox_line_match_search(struct search_condition *condition,
238 int mbox_id, char *mbox_value) {
240 if(condition->field_id == ID_INTERVAL) {
241 if(mbox_id == ID_LEADING_LINE) {
247 while(*c && *c != ' ') c++; while(*c && *c == ' ') c++;
248 strptime(c, "%a %b %e %k:%M:%S %Y", &tm);
251 return (t >= condition->interval_start &&
252 (condition->interval_stop == 0 ||
253 t <= condition->interval_stop));
261 (condition->field_id == mbox_id)
265 (condition->field_id == ID_PARTICIPANT && (mbox_id == ID_LEADING_LINE ||
266 mbox_id == ID_FROM ||
270 (condition->field_id == ID_FROM && mbox_id == ID_LEADING_LINE)
274 regexec(&condition->regexp, mbox_value, 0, 0, 0) == 0;
278 void update_body_hits(char *mail_filename, int position_in_mail,
279 int nb_search_conditions, struct search_condition *search_conditions,
280 int nb_body_conditions,
284 int last_mbox_line_was_empty;
285 char raw_mbox_line[BUFFER_SIZE];
291 mail_file = fopen(mail_filename, "r");
295 "mymail: Cannot open mbox '%s' for body scan.\n",
300 fseek(mail_file, position_in_mail, SEEK_SET);
302 if(fgets(raw_mbox_line, BUFFER_SIZE, mail_file)) {
303 while(nb_body_hits < nb_body_conditions) {
304 last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
306 if(last_mbox_line_was_empty) { header = 0; }
309 for(n = 0; n < nb_search_conditions; n++) {
310 if(search_conditions[n].field_id == ID_BODY && !hits[n]) {
312 (regexec(&search_conditions[n].regexp, raw_mbox_line, 0, 0, 0) == 0);
320 if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
321 (last_mbox_line_was_empty &&
322 is_a_leading_from_line(raw_mbox_line)))
330 void search_in_db(const char *db_filename,
331 int nb_search_conditions,
332 struct search_condition *search_conditions,
335 int hits[MAX_NB_SEARCH_CONDITIONS];
336 char raw_db_line[BUFFER_SIZE];
337 char raw_mbox_line[BUFFER_SIZE];
338 char current_mail_filename[PATH_MAX + 1];
339 unsigned long int current_position_in_mail;
340 char mbox_name[TOKEN_BUFFER_SIZE], *mbox_value;
342 int already_written, m, n;
343 int last_mbox_line_was_empty;
344 int nb_body_conditions, nb_fulfilled_body_conditions;
348 printf("Searching in '%s' ... ", db_filename);
352 db_file = fopen(db_filename, "r");
356 "mymail: Cannot open \"%s\" for reading: %s\n",
362 if(fgets(raw_db_line, BUFFER_SIZE, db_file)) {
363 if(strncmp(raw_db_line, MYMAIL_DB_MAGIC_TOKEN, strlen(MYMAIL_DB_MAGIC_TOKEN))) {
365 "mymail: Header line in '%s' does not match the mymail db format.\n",
371 "mymail: Cannot read the header line in '%s'.\n",
376 current_position_in_mail = 0;
379 for(n = 0; n < nb_search_conditions; n++) { hits[n] = 0; }
381 nb_body_conditions = 0;
382 for(n = 0; n < nb_search_conditions; n++) {
383 if(search_conditions[n].field_id == ID_BODY) {
384 nb_body_conditions++;
388 strcpy(current_mail_filename, "");
390 while(fgets(raw_db_line, BUFFER_SIZE, db_file)) {
391 mbox_value = parse_token(mbox_name, TOKEN_BUFFER_SIZE, ' ', raw_db_line);
393 if(strcmp("mail", mbox_name) == 0) {
394 char position_in_file_string[TOKEN_BUFFER_SIZE];
396 if(current_mail_filename[0]) {
398 /* We first check all conditions but the body ones */
400 for(n = 0; n < nb_search_conditions &&
401 ((search_conditions[n].field_id == ID_BODY) ||
402 xor(hits[n], search_conditions[n].negation)); n++);
404 if(n == nb_search_conditions) {
406 /* all conditions but the body ones are fine, check the body
409 if(nb_body_conditions > 0) {
410 update_body_hits(current_mail_filename, current_position_in_mail,
411 nb_search_conditions, search_conditions,
416 nb_fulfilled_body_conditions = 0;
418 for(n = 0; n < nb_search_conditions; n++) {
419 if(search_conditions[n].field_id == ID_BODY &&
420 xor(hits[n], search_conditions[n].negation)) {
421 nb_fulfilled_body_conditions++;
425 if(nb_body_conditions == nb_fulfilled_body_conditions) {
428 mail_file = fopen(current_mail_filename, "r");
432 "mymail: Cannot open mbox '%s' for mail extraction.\n",
433 current_mail_filename);
437 fseek(mail_file, current_position_in_mail, SEEK_SET);
439 if(fgets(raw_mbox_line, BUFFER_SIZE, mail_file)) {
440 last_mbox_line_was_empty = 0;
441 fprintf(output_file, "%s", raw_mbox_line);
443 if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
444 (last_mbox_line_was_empty &&
445 is_a_leading_from_line(raw_mbox_line))
448 last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
449 fprintf(output_file, "%s", raw_mbox_line);
458 for(n = 0; n < nb_search_conditions; n++) { hits[n] = 0; }
460 mbox_value = parse_token(position_in_file_string, TOKEN_BUFFER_SIZE, ' ', mbox_value);
461 mbox_value = parse_token(current_mail_filename, TOKEN_BUFFER_SIZE, ' ', mbox_value);
462 current_position_in_mail = atol(position_in_file_string);
463 remove_eof(current_mail_filename);
469 for(m = 0; (m < MAX_ID) && mbox_id == -1; m++) {
470 if(strncmp(field_names[m], mbox_name, strlen(mbox_name)) == 0) {
474 for(n = 0; n < nb_search_conditions; n++) {
475 hits[n] |= mbox_line_match_search(&search_conditions[n],
476 mbox_id, mbox_value);
489 void recursive_search_in_db(const char *entry_name, regex_t *db_filename_regexp,
490 int nb_search_conditions,
491 struct search_condition *search_conditions,
494 struct dirent *dir_e;
496 char subname[PATH_MAX + 1];
498 if(lstat(entry_name, &sb) != 0) {
500 "mymail: Cannot stat \"%s\": %s\n",
506 dir = opendir(entry_name);
509 while((dir_e = readdir(dir))) {
510 if(!ignore_entry(dir_e->d_name)) {
511 snprintf(subname, PATH_MAX, "%s/%s", entry_name, dir_e->d_name);
512 recursive_search_in_db(subname, db_filename_regexp,
513 nb_search_conditions, search_conditions,
521 const char *s = entry_name, *filename = entry_name;
522 while(*s) { if(*s == '/') { filename = s+1; } s++; }
524 if(regexec(db_filename_regexp, filename, 0, 0, 0) == 0) {
525 search_in_db(entry_name, nb_search_conditions, search_conditions, output_file);
530 /*********************************************************************/
532 void index_one_mbox_line(int nb_fields_to_parse, struct parsable_field *fields_to_parse,
533 char *raw_mbox_line, FILE *db_file) {
536 for(f = 0; f < nb_fields_to_parse; f++) {
537 if(regexec(&fields_to_parse[f].regexp, raw_mbox_line, 1, &matches, 0) == 0) {
538 fprintf(db_file, "%s %s\n",
539 field_names[fields_to_parse[f].id],
540 raw_mbox_line + matches.rm_eo);
545 void index_mbox(const char *mbox_filename,
546 int nb_fields_to_parse, struct parsable_field *fields_to_parse,
548 char raw_mbox_line[BUFFER_SIZE], full_line[BUFFER_SIZE];
549 char *end_of_full_line;
551 int in_header, new_header, last_mbox_line_was_empty;
552 unsigned long int position_in_file;
554 file = fopen(mbox_filename, "r");
557 fprintf(stderr, "mymail: Cannot open '%s'.\n", mbox_filename);
558 if(paranoid) { exit(EXIT_FAILURE); }
565 position_in_file = 0;
566 end_of_full_line = 0;
568 last_mbox_line_was_empty = 1;
570 while(fgets(raw_mbox_line, BUFFER_SIZE, file)) {
571 if(last_mbox_line_was_empty &&
572 is_a_leading_from_line(raw_mbox_line)) {
575 "Got a ^\"From \" in the header in %s:%lu.\n",
576 mbox_filename, position_in_file);
577 fprintf(stderr, "%s", raw_mbox_line);
578 if(paranoid) { exit(EXIT_FAILURE); }
582 } else if(raw_mbox_line[0] == '\n') {
583 if(in_header) { in_header = 0; }
586 last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
590 fprintf(db_file, "mail %lu %s\n", position_in_file, mbox_filename);
594 if(raw_mbox_line[0] == ' ' || raw_mbox_line[0] == '\t') {
595 char *start = raw_mbox_line;
596 while(*start == ' ' || *start == '\t') start++;
597 *(end_of_full_line++) = ' ';
598 strcpy(end_of_full_line, start);
599 while(*end_of_full_line && *end_of_full_line != '\n') {
602 *end_of_full_line = '\0';
607 if(!((raw_mbox_line[0] >= 'a' && raw_mbox_line[0] <= 'z') ||
608 (raw_mbox_line[0] >= 'A' && raw_mbox_line[0] <= 'Z'))) {
610 "Header line syntax error %s:%lu.\n",
611 mbox_filename, position_in_file);
612 fprintf(stderr, "%s", raw_mbox_line);
617 index_one_mbox_line(nb_fields_to_parse, fields_to_parse, full_line, db_file);
620 end_of_full_line = full_line;
621 strcpy(end_of_full_line, raw_mbox_line);
622 while(*end_of_full_line && *end_of_full_line != '\n') {
625 *end_of_full_line = '\0';
630 position_in_file += strlen(raw_mbox_line);
636 void recursive_index_mbox(FILE *db_file,
637 const char *entry_name,
638 int nb_fields_to_parse, struct parsable_field *fields_to_parse) {
640 struct dirent *dir_e;
642 char subname[PATH_MAX + 1];
644 if(lstat(entry_name, &sb) != 0) {
646 "mymail: Cannot stat \"%s\": %s\n",
652 dir = opendir(entry_name);
655 while((dir_e = readdir(dir))) {
656 if(!ignore_entry(dir_e->d_name)) {
657 snprintf(subname, PATH_MAX, "%s/%s", entry_name, dir_e->d_name);
658 recursive_index_mbox(db_file, subname, nb_fields_to_parse, fields_to_parse);
663 index_mbox(entry_name, nb_fields_to_parse, fields_to_parse, db_file);
667 /*********************************************************************/
669 /* For long options that have no equivalent short option, use a
670 non-character as a pseudo short option, starting with CHAR_MAX + 1. */
672 OPT_BASH_MODE = CHAR_MAX + 1
675 static struct option long_options[] = {
676 { "help", no_argument, 0, 'h' },
677 { "version", no_argument, 0, 'v' },
678 { "quiet", no_argument, 0, 'q' },
679 { "db-file", 1, 0, 'd' },
680 { "db-pattern", 1, 0, 'p' },
681 { "db-root", 1, 0, 'r' },
682 { "db-list", 1, 0, 'l' },
683 { "search", 1, 0, 's' },
684 { "index", 0, 0, 'i' },
685 { "output", 1, 0, 'o' },
689 /*********************************************************************/
691 void init_condition(struct search_condition *condition, char *string) {
692 char full_search_field[TOKEN_BUFFER_SIZE], *search_field;
695 string = parse_token(full_search_field, TOKEN_BUFFER_SIZE, ' ', string);
696 search_field = full_search_field;
698 if(search_field[0] == '!') {
700 condition->negation = 1;
702 condition->negation = 0;
707 if(strcmp(search_field, "8h") == 0) {
708 condition->field_id = ID_INTERVAL;
709 condition->interval_start = time(0) - 3600 * 8;
710 condition->interval_stop = 0;
713 else if(strcmp(search_field, "week") == 0) {
714 condition->field_id = ID_INTERVAL;
715 condition->interval_start = time(0) - 3600 * 24 * 7;
716 condition->interval_stop = 0;
719 /* Today and yesterday */
721 else if(strcmp(search_field, "24h") == 0 ||
722 strcmp(search_field, "today") == 0) {
723 condition->field_id = ID_INTERVAL;
724 condition->interval_start = time(0) - 3600 * 24;
725 condition->interval_stop = 0;
728 else if(strcmp(search_field, "yesterday") == 0) {
729 condition->field_id = ID_INTERVAL;
730 condition->interval_start = time(0) - 2 * 3600 * 24;
731 condition->interval_stop = condition->interval_start + 3600 * 24;
736 else if(strcmp(search_field, "monday") == 0) {
737 condition->field_id = ID_INTERVAL;
738 condition->interval_start = time_for_past_day(1);
739 condition->interval_stop = condition->interval_start + 3600 * 24;
742 else if(strcmp(search_field, "tuesday") == 0) {
743 condition->field_id = ID_INTERVAL;
744 condition->interval_start = time_for_past_day(2);
745 condition->interval_stop = condition->interval_start + 3600 * 24;
748 else if(strcmp(search_field, "wednesday") == 0) {
749 condition->field_id = ID_INTERVAL;
750 condition->interval_start = time_for_past_day(3);
751 condition->interval_stop = condition->interval_start + 3600 * 24;
754 else if(strcmp(search_field, "thursday") == 0) {
755 condition->field_id = ID_INTERVAL;
756 condition->interval_start = time_for_past_day(4);
757 condition->interval_stop = condition->interval_start + 3600 * 24;
760 else if(strcmp(search_field, "friday") == 0) {
761 condition->field_id = ID_INTERVAL;
762 condition->interval_start = time_for_past_day(5);
763 condition->interval_stop = condition->interval_start + 3600 * 24;
766 else if(strcmp(search_field, "saturday") == 0) {
767 condition->field_id = ID_INTERVAL;
768 condition->interval_start = time_for_past_day(6);
769 condition->interval_stop = condition->interval_start + 3600 * 24;
772 else if(strcmp(search_field, "sunday") == 0) {
773 condition->field_id = ID_INTERVAL;
774 condition->interval_start = time_for_past_day(7);
775 condition->interval_stop = condition->interval_start + 3600 * 24;
779 condition->field_id = -1;
781 for(m = 0; (m < MAX_ID) && condition->field_id == -1; m++) {
782 if(strncmp(field_names[m], search_field, strlen(search_field)) == 0) {
783 condition->field_id = m;
787 if(condition->field_id == -1) {
789 "mymail: Syntax error in field name \"%s\".\n",
794 if(regcomp(&condition->regexp,
798 "mymail: Syntax error in regexp \"%s\" for field \"%s\".\n",
800 field_names[condition->field_id]);
806 void free_condition(struct search_condition *condition) {
807 if(condition->field_id != ID_INTERVAL) {
808 regfree(&condition->regexp);
812 /*********************************************************************/
813 /*********************************************************************/
814 /*********************************************************************/
816 int main(int argc, char **argv) {
818 char *db_filename_regexp_string;
820 char *db_filename_list;
821 char output_filename[PATH_MAX + 1];
824 int error = 0, show_help = 0;
825 const int nb_fields_to_parse = sizeof(fields_to_parse) / sizeof(struct parsable_field);
828 int nb_search_conditions;
830 struct search_condition search_conditions[MAX_NB_SEARCH_CONDITIONS];
832 if(regcomp(&leading_from_line_regexp,
833 "^From [^ ]* \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\) \\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\) [ 123][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]\n$",
836 "mymail: Cannot compile leading \"from\" line regexp. That is strange.\n");
843 db_filename_regexp_string = 0;
845 db_filename_list = 0;
848 setlocale(LC_ALL, "");
850 nb_search_conditions = 0;
852 while ((c = getopt_long(argc, argv, "hvqip:s:d:r:l:o:",
853 long_options, NULL)) != -1) {
862 print_version(stdout);
874 db_filename = strdup(optarg);
878 db_filename_regexp_string = strdup(optarg);
882 strncpy(output_filename, optarg, PATH_MAX);
886 db_root_path = strdup(optarg);
890 db_filename_list = strdup(optarg);
894 if(nb_search_conditions == MAX_NB_SEARCH_CONDITIONS) {
895 fprintf(stderr, "mymail: Too many search patterns.\n");
898 init_condition(&search_conditions[nb_search_conditions], optarg);
899 nb_search_conditions++;
909 char *default_db_filename = getenv("MYMAIL_DB_FILE");
911 if(!default_db_filename) {
912 default_db_filename = "mymail.db";
915 db_filename = strdup(default_db_filename);
918 if(!db_filename_regexp_string) {
919 char *default_db_filename_regexp_string = getenv("MYMAIL_DB_PATTERN");
921 if(!default_db_filename_regexp_string) {
922 default_db_filename_regexp_string = "^mymail.db$";
925 db_filename_regexp_string = strdup(default_db_filename_regexp_string);
929 char *default_db_root_path = getenv("MYMAIL_DB_ROOT");
931 if(default_db_root_path) {
932 db_root_path = strdup(default_db_root_path);
936 if(!db_filename_list) {
937 char *default_db_filename_list = getenv("MYMAIL_DB_LIST");
939 if(default_db_filename_list) {
940 db_filename_list = strdup(default_db_filename_list);
944 if(output_filename[0]) {
945 output_file = fopen(output_filename, "w");
949 "mymail: Cannot open result file \"%s\" for writing: %s\n",
955 output_file = stdout;
972 db_file = fopen(db_filename, "w");
976 "mymail: Cannot open \"%s\" for writing: %s\n",
982 for(f = 0; f < nb_fields_to_parse; f++) {
983 if(regcomp(&fields_to_parse[f].regexp,
984 fields_to_parse[f].regexp_string,
987 "mymail: Syntax error in regexp \"%s\" for field \"%s\".\n",
988 fields_to_parse[f].regexp_string,
989 field_names[fields_to_parse[f].id]);
994 fprintf(db_file, "%s version_%s raw\n", MYMAIL_DB_MAGIC_TOKEN, VERSION);
996 while(optind < argc) {
997 recursive_index_mbox(db_file,
999 nb_fields_to_parse, fields_to_parse);
1006 for(f = 0; f < nb_fields_to_parse; f++) {
1007 regfree(&fields_to_parse[f].regexp);
1013 if(nb_search_conditions > 0) {
1015 /* Recursive search if db_root_path is set */
1018 regex_t db_filename_regexp;
1019 if(regcomp(&db_filename_regexp,
1020 db_filename_regexp_string,
1023 "mymail: Syntax error in regexp \"%s\".\n",
1024 db_filename_regexp_string);
1028 recursive_search_in_db(db_root_path, &db_filename_regexp,
1029 nb_search_conditions, search_conditions,
1032 regfree(&db_filename_regexp);
1035 /* Search in all db files listed in db_filename_list */
1037 if(db_filename_list) {
1038 char db_filename[PATH_MAX + 1];
1041 s = db_filename_list;
1044 s = parse_token(db_filename, PATH_MAX + 1, ';', s);
1046 if(db_filename[0]) {
1047 search_in_db(db_filename, nb_search_conditions, search_conditions, output_file);
1052 /* Search in all db files listed in the command arguments */
1054 while(optind < argc) {
1055 search_in_db(argv[optind], nb_search_conditions, search_conditions, output_file);
1061 for(n = 0; n < nb_search_conditions; n++) {
1062 free_condition(&search_conditions[n]);
1065 if(output_file != stdout) {
1066 fflush(output_file);
1067 fclose(output_file);
1071 free(db_filename_regexp_string);
1073 free(db_filename_list);
1075 regfree(&leading_from_line_regexp);