From: Francois Fleuret Date: Fri, 8 Feb 2013 17:27:30 +0000 (+0100) Subject: Cosmetics + increased version number. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=bfdc0f26c78c8a47c7ddb23998dbc6ab8cc2384f;p=mymail.git Cosmetics + increased version number. --- diff --git a/mymail.c b/mymail.c index 54febff..cc55261 100644 --- a/mymail.c +++ b/mymail.c @@ -46,13 +46,15 @@ #include #define MYMAIL_DB_MAGIC_TOKEN "mymail_index_file" -#define VERSION "0.9.1" +#define VERSION "0.9.2" #define MAX_NB_SEARCH_CONDITIONS 10 #define BUFFER_SIZE 65536 #define TOKEN_BUFFER_SIZE 1024 +#define LEADING_FROM_LINE_REGEXP "^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$" + regex_t leading_from_line_regexp; /* Global variables! */ @@ -60,6 +62,7 @@ regex_t leading_from_line_regexp; int paranoid; int quiet; char *default_search_field; +int ignore_dot_files; /********************************************************************/ @@ -228,12 +231,12 @@ time_t time_for_past_day(int day) { int ignore_entry(const char *name) { return - /* strcmp(name, ".") == 0 || */ - /* strcmp(name, "..") == 0 || */ - (name[0] == '.' && name[1] != '/'); + strcmp(name, ".") == 0 || + strcmp(name, "..") == 0 || + (ignore_dot_files && name[0] == '.' && name[1] != '/'); } -int is_a_leading_from_line(int last_mbox_line_was_empty, char *mbox_line) { +int is_a_leading_from_line(char *mbox_line) { return /* @@ -246,7 +249,6 @@ int is_a_leading_from_line(int last_mbox_line_was_empty, char *mbox_line) { */ - /* last_mbox_line_was_empty && */ strncmp(mbox_line, "From ", 5) == 0 && regexec(&leading_from_line_regexp, mbox_line, 0, 0, 0) == 0; } @@ -300,7 +302,6 @@ void update_body_hits(char *mail_filename, int position_in_mail, int *hits) { FILE *mail_file; int header, n; - int last_mbox_line_was_empty; char raw_mbox_line[BUFFER_SIZE]; int nb_body_hits; @@ -320,9 +321,10 @@ void update_body_hits(char *mail_filename, int position_in_mail, if(fgets(raw_mbox_line, BUFFER_SIZE, mail_file)) { while(nb_body_hits < nb_body_conditions) { - last_mbox_line_was_empty = (raw_mbox_line[0] == '\n'); + /* last_mbox_line_was_empty = (raw_mbox_line[0] == '\n'); */ + /* if(last_mbox_line_was_empty) { header = 0; } */ - if(last_mbox_line_was_empty) { header = 0; } + if(raw_mbox_line[0] == '\n') { header = 0; } if(!header) { for(n = 0; n < nb_search_conditions; n++) { @@ -337,7 +339,7 @@ void update_body_hits(char *mail_filename, int position_in_mail, } if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) || - (is_a_leading_from_line(last_mbox_line_was_empty, raw_mbox_line))) + (is_a_leading_from_line(raw_mbox_line))) break; } } @@ -348,7 +350,6 @@ void update_body_hits(char *mail_filename, int position_in_mail, void write_mail(const char *mail_filename, unsigned long int position_in_mail, FILE *output_file) { char raw_mbox_line[BUFFER_SIZE]; - int last_mbox_line_was_empty; FILE *mail_file; mail_file = fopen(mail_filename, "r"); @@ -363,14 +364,12 @@ void write_mail(const char *mail_filename, unsigned long int position_in_mail, fseek(mail_file, 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) || - (is_a_leading_from_line(last_mbox_line_was_empty, raw_mbox_line)) + (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); } } @@ -572,7 +571,7 @@ void index_mbox(const char *mbox_filename, char raw_mbox_line[BUFFER_SIZE], full_line[BUFFER_SIZE]; char *end_of_full_line; FILE *file; - int in_header, new_header, last_mbox_line_was_empty; + int in_header, new_header; unsigned long int position_in_file; file = fopen(mbox_filename, "r"); @@ -589,10 +588,9 @@ void index_mbox(const char *mbox_filename, position_in_file = 0; end_of_full_line = 0; full_line[0] = '\0'; - last_mbox_line_was_empty = 1; while(fgets(raw_mbox_line, BUFFER_SIZE, file)) { - if(is_a_leading_from_line(last_mbox_line_was_empty, raw_mbox_line)) { + if(is_a_leading_from_line(raw_mbox_line)) { if(in_header) { fprintf(stderr, "Got a ^\"From \" in the header in %s:%lu.\n", @@ -606,8 +604,6 @@ void index_mbox(const char *mbox_filename, if(in_header) { in_header = 0; } } - last_mbox_line_was_empty = (raw_mbox_line[0] == '\n'); - if(in_header) { if(new_header) { fprintf(db_file, "mail %lu %s\n", position_in_file, mbox_filename); @@ -880,9 +876,7 @@ int main(int argc, char **argv) { FILE *output_file; struct search_condition search_conditions[MAX_NB_SEARCH_CONDITIONS]; - if(regcomp(&leading_from_line_regexp, - "^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$", - 0)) { + if(regcomp(&leading_from_line_regexp, LEADING_FROM_LINE_REGEXP, 0)) { fprintf(stderr, "mymail: Cannot compile leading \"from\" line regexp. That is strange.\n"); exit(EXIT_FAILURE); @@ -896,6 +890,7 @@ int main(int argc, char **argv) { db_filename_list = 0; quiet = 0; default_search_field = 0; + ignore_dot_files = 1; setlocale(LC_ALL, "");