X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=mymail.git;a=blobdiff_plain;f=mymail.c;h=6fa18140c17872fb422026bbea7a120df621f085;hp=c1b09be84869c7fe58f395aceb4bd753e6da6241;hb=406c3891838fc77131dbbbd29423b61259cd789d;hpb=1ed39d135312a0c698adf82d81a1723a9141bca3 diff --git a/mymail.c b/mymail.c index c1b09be..6fa1814 100644 --- a/mymail.c +++ b/mymail.c @@ -21,11 +21,13 @@ /* - This command is a dumb mail indexer. It can either (1) scan - 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, to create a resulting mbox file. + mymail is a simple mail indexer. It can: + + (1) scan mbox files, and create a db file containing for each mail a + list of fields computed from its header. + + (2) read such a db file, gets all the mails matching regexp-defined + conditions on the fields, and generates a resulting mbox file. It is low-tech, simple, light and fast. @@ -84,6 +86,8 @@ enum { ID_PARTICIPANT, ID_BODY, ID_TIME_INTERVAL, + ID_MAIL_ID, + ID_REFERENCE_ID, MAX_ID }; @@ -96,7 +100,9 @@ static char *field_keys[] = { "date", "part", "body", - "interval" + "interval", + "mailid", + "references" }; /********************************************************************/ @@ -153,6 +159,20 @@ static struct parsable_field fields_to_parse[] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { + ID_MAIL_ID, + REG_ICASE, + "^message-id: ", + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + }, + + { + ID_REFERENCE_ID, + REG_ICASE, + "^\\(in-reply-to\\|references\\): ", + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + }, + }; /********************************************************************/ @@ -200,7 +220,7 @@ void *safe_malloc(size_t n) { void *p = malloc(n); if(!p && n != 0) { fprintf(stderr, - "selector: cannot allocate memory: %s\n", strerror(errno)); + "mymail: cannot allocate memory: %s\n", strerror(errno)); exit(EXIT_FAILURE); } return p; @@ -212,8 +232,9 @@ FILE *safe_fopen(const char *path, const char *mode, const char *comment) { return result; } else { fprintf(stderr, - "mymail: Cannot open file '%s' (%s) with mode \"%s\".\n", - path, comment, mode); + "mymail: Cannot open file '%s' (%s) with mode \"%s\": %s\n", + path, comment, mode, + strerror(errno)); exit(EXIT_FAILURE); } } @@ -505,6 +526,12 @@ int search_in_db(const char *db_filename, while(nb_extracted_mails < global_nb_mails_max && fgets(raw_db_line, BUFFER_SIZE, db_file)) { + + /* Removes the CR */ + char *s = raw_db_line; + while(*s && *s != '\n') { s++; } + *s = '\0'; + db_value = parse_token(db_key_string, TOKEN_BUFFER_SIZE, ' ', raw_db_line); if(strcmp("mail", db_key_string) == 0) { @@ -520,7 +547,7 @@ int search_in_db(const char *db_filename, for(n = 0; n < nb_search_conditions; n++) { hits[n] = 0; } db_value = parse_token(position_in_file_string, TOKEN_BUFFER_SIZE, ' ', db_value); - db_value = parse_token(current_mail_filename, PATH_MAX+1, '\n', db_value); + strncpy(current_mail_filename, db_value, PATH_MAX + 1); current_position_in_mail = atol(position_in_file_string); } @@ -1145,6 +1172,16 @@ int main(int argc, char **argv) { } } + if(error) { + print_usage(stderr); + exit(EXIT_FAILURE); + } + + if(show_help) { + print_usage(stdout); + exit(EXIT_SUCCESS); + } + /* Set all the values that may defined in the arguments, through environment variables, or hard-coded */ @@ -1168,18 +1205,6 @@ int main(int argc, char **argv) { "MYMAIL_MBOX_PATTERN", 0); - /* Start the processing */ - - if(error) { - print_usage(stderr); - exit(EXIT_FAILURE); - } - - if(show_help) { - print_usage(stdout); - exit(EXIT_SUCCESS); - } - /* mbox indexing */ if(action_index) {