From 6c8770e146420bb7651c8e10e279402f45ff1c3d Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sat, 9 Feb 2013 10:32:30 +0100 Subject: [PATCH 01/16] Cosmetics. --- mymail-vm.el | 2 +- mymail.1 | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mymail-vm.el b/mymail-vm.el index 5d9d50c..dc1976c 100644 --- a/mymail-vm.el +++ b/mymail-vm.el @@ -42,7 +42,7 @@ prefaced with \\." (mapcar (lambda (searche-request) (if (not (string= searche-request "")) - (list "-s" searche-request))) + (list "--search" searche-request))) (if (string= (substring param 0 1) "\\") (split-string (substring param 1 nil) ",") (split-string (concat param "," mymail/default-search-request) ",")) diff --git a/mymail.1 b/mymail.1 index 0fff226..82b35b5 100644 --- a/mymail.1 +++ b/mymail.1 @@ -41,8 +41,9 @@ set the db root path for recursive search \fB-l \fR, \fB--db-list \fR set the semicolon-separated list of db files for search .TP -\fB-s \fR, \fB--search \fR -search for matching mails in the db file +\fB-s \fR, \fB--search \fR search for +matching mails in the db file. Multiple search requests can be +combined, and only mails fulfilling all of them will be extracted. .TP \fB-d \fR, \fB--db-file \fR set the db filename for indexing @@ -51,8 +52,8 @@ set the db filename for indexing index mails in the mailboxes located recursively anywhere in the directories following the options on the command lines .TP -\fB-o \fR, \fB--output \fR -set the db filename pattern for recursive search +\fB-o \fR, \fB--output \fR set the +result mbox filename. If it is not set, the standard output is used .TP \fB-a \fR, \fB--default-search \fR set the default search field: If a search request is not understood, -- 2.20.1 From 248736d0d3900bce18c1c6afd9f3dc2d93df2cae Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sat, 9 Feb 2013 11:33:56 +0100 Subject: [PATCH 02/16] Update. --- mymail.1 | 78 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/mymail.1 b/mymail.1 index 82b35b5..b79b4b9 100644 --- a/mymail.1 +++ b/mymail.1 @@ -10,16 +10,15 @@ mymail \- A simple command line utility for indexing and searching mbox files .SH "SYNOPSIS" -\fBmymail\fP [\fIoptions\fR] [\fI\fR [\fI\fR ... ]|\fI\fR [\fI\fR ... ]]\n"); +\fBmymail\fP [\fIoptions\fR] [\fI\fR [\fI\fR ... ]|\fI\fR [\fI\fR ... ]] .SH "DESCRIPTION" -\fBmymail\fP is a command line utility to index mbox files and perform -quick searches based on sender, subject, etc. +\fBmymail\fP is a command line utility to index mbox files, search for +mails based on sender, subject, etc. and generate result mbox files. -It is similar in spirit to other existing software such as mu or -notmuch, but does not use a real database backend to store and query -the index. +It is similar in spirit to other tools such as mu or notmuch, but is +overall simpler. .SH "OPTIONS" .TP @@ -56,7 +55,7 @@ directories following the options on the command lines result mbox filename. If it is not set, the standard output is used .TP \fB-a \fR, \fB--default-search \fR -set the default search field: If a search request is not understood, +set the default search field. If a search request is not understood, it is interpreted as the regexp with this default search field .SH "ENVIRONMENT VARIABLES" @@ -82,43 +81,47 @@ is prefaced by the character "!" it is negated, and has to be false for a mail to be selected. .TP -\fBf \fR (from) selects mails whose leading line From, or -fields From:, Sender:, Reply-To:, or Return-Path: matches the regexp. +\fBf \fR (from) +selects mails whose leading line From, or fields From:, Sender:, +Reply-To:, or Return-Path: matches the regexp. .TP -\fBt \fR (to) selects mails whose field To:, Cc:, or Bcc: matches the regexp. +\fBt \fR (to) +selects mails whose field To:, Cc:, or Bcc: matches the regexp. .TP -\fBp \fR (participant) selects mails that would be selected by \fBf\fR or \fBt\fR. +\fBp \fR (participant) +selects mails that would be selected by \fBf\fR or \fBt\fR. .TP -\fBs \fR (subject) selects mails whose field Subject: matches the regexp. +\fBs \fR (subject) +selects mails whose field Subject: matches the regexp. .TP -\fBd \fR (date) selects mails whose field Date: matches the regexp. +\fBd \fR (date) +selects mails whose field Date: matches the regexp. .TP -\fBb \fR (body) selects mails whose body matches the -regexp. Evaluatin such a condition requires to read the original -mboxes completely, which can be slow. However, header conditions are -checked first to read the bodies only for mails which fulfill them -entirely. +\fBb \fR (body) +selects mails whose body matches the regexp. Evaluating such a +condition requires to read the original mboxes completely, which can +be slow. However, header conditions are checked first to read the +bodies only for mails which fulfill them entirely. .TP \fB8h\fR, \fBtoday\fR, \fB24h\fR, \fBweek\fR, \fBmonth\fR, and -\fByear\fR selects mails received during the last 8, 24, 24, 7 * 24 -hours, 31 * 24 hours, and 365 * 24 hours respectively. +\fByear\fR +selects mails received during the last 8, 24, 24, 7 * 24 hours, 31 * +24 hours, and 365 * 24 hours respectively. .TP -\fByesterday\fR selects mails received between 48h and 24h ago. +\fByesterday\fR +selects mails received between 48h and 24h ago. .TP -\fBmonday\fR, \fBtuesday\fR, ..., \fBsunday\fR selects mails received -the most recent such day +\fBmonday\fR, \fBtuesday\fR, ..., \fBsunday\fR +selects mails received the most recent such day of the week .SH "EXAMPLES" The command -.RS -.EX -mymail --db-file /tmp/mymail/2010-2011/mymail.db \\ - --index \\ - ~/archives/mails/2010 ~/archives/mails/2011 -.EE -.RE +.nf +.B mymail --db-file /tmp/mymail/2010-2011/mymail.db \e +.B --index \e +.B ~/archives/mails/2010 ~/archives/mails/2011 will index all the mbox files present in the directories ~/archives/mails/2010 and ~/archives/mails/2011 (recursively) and @@ -126,15 +129,12 @@ create an index file /tmp/mymail/2010-2011/mymail.db And -.RS -.EX -mymail --db-pattern '\.db$' --db-root /tmp/mymail \\ - --output /tmp/mymail.mbox \\ - --search 'p bob.something' \\ - --search '!s spam' \\ - --search 'month' -.EE -.RE +.nf +.B mymail --db-pattern '\.db$' --db-root /tmp/mymail \e +.B --output /tmp/mymail.mbox \e +.B --search 'p bob.something' \e +.B --search '!s spam' \e +.B --search 'month' will search in all the database files *.db located (recursively) in /tmp/mymail, for all the mails having "bob.something" as sender or -- 2.20.1 From 3ca38393b46c2bbba39f7b0bd4ca3ea918384b1d Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sat, 9 Feb 2013 11:41:43 +0100 Subject: [PATCH 03/16] Spacing cosmetics. --- mymail.1 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mymail.1 b/mymail.1 index b79b4b9..e48633b 100644 --- a/mymail.1 +++ b/mymail.1 @@ -118,24 +118,28 @@ selects mails received the most recent such day of the week The command +.P .nf .B mymail --db-file /tmp/mymail/2010-2011/mymail.db \e -.B --index \e -.B ~/archives/mails/2010 ~/archives/mails/2011 +.B \ \ \ \ \ \ \ --index \e +.B \ \ \ \ \ \ \ ~/archives/mails/2010 ~/archives/mails/2011 +.fi will index all the mbox files present in the directories ~/archives/mails/2010 and ~/archives/mails/2011 (recursively) and create an index file /tmp/mymail/2010-2011/mymail.db And +.P .nf .B mymail --db-pattern '\.db$' --db-root /tmp/mymail \e -.B --output /tmp/mymail.mbox \e -.B --search 'p bob.something' \e -.B --search '!s spam' \e -.B --search 'month' +.B \ \ \ \ \ \ \ --output /tmp/mymail.mbox \e +.B \ \ \ \ \ \ \ --search 'p bob.something' \e +.B \ \ \ \ \ \ \ --search '!s spam' \e +.B \ \ \ \ \ \ \ --search 'month' +.fi will search in all the database files *.db located (recursively) in /tmp/mymail, for all the mails having "bob.something" as sender or recipient, without "spam" in the subject, received over the last 31 -- 2.20.1 From 5b468174fa4d6629faf3069e254a17c72bd18545 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 10 Feb 2013 12:49:04 +0100 Subject: [PATCH 04/16] Added the --mbox-pattern option. --- mymail.1 | 5 ++- mymail.c | 119 ++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 100 insertions(+), 24 deletions(-) diff --git a/mymail.1 b/mymail.1 index e48633b..95b83f0 100644 --- a/mymail.1 +++ b/mymail.1 @@ -40,11 +40,14 @@ set the db root path for recursive search \fB-l \fR, \fB--db-list \fR set the semicolon-separated list of db files for search .TP +\fB-m \fR, \fB--mbox-pattern \fR +set the mbox filename pattern for recursive search +.TP \fB-s \fR, \fB--search \fR search for matching mails in the db file. Multiple search requests can be combined, and only mails fulfilling all of them will be extracted. .TP -\fB-d \fR, \fB--db-file \fR +\fB-d \fR, \fB--db-file-generate \fR set the db filename for indexing .TP \fB-i\fR, \fB--index\fR diff --git a/mymail.c b/mymail.c index f9b0148..5287301 100644 --- a/mymail.c +++ b/mymail.c @@ -203,9 +203,11 @@ void print_usage(FILE *out) { fprintf(out, " set the db root path for recursive search\n"); fprintf(out, " -l , --db-list \n"); fprintf(out, " set the semicolon-separated list of db files for search\n"); + fprintf(out, " -m , --mbox-pattern \n"); + fprintf(out, " set the mbox filename pattern for recursive search\n"); fprintf(out, " -s , --search \n"); fprintf(out, " search for matching mails in the db file\n"); - fprintf(out, " -d , --db-file \n"); + fprintf(out, " -d , --db-file-generate \n"); fprintf(out, " set the db filename for indexing\n"); fprintf(out, " -i, --index\n"); fprintf(out, " index mails\n"); @@ -663,7 +665,7 @@ void index_mbox(const char *mbox_filename, } void recursive_index_mbox(FILE *db_file, - const char *entry_name, + const char *entry_name, regex_t *mbox_filename_regexp, int nb_fields_to_parse, struct parsable_field *fields_to_parse) { DIR *dir; struct dirent *dir_e; @@ -684,12 +686,17 @@ void recursive_index_mbox(FILE *db_file, 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_index_mbox(db_file, subname, nb_fields_to_parse, fields_to_parse); + recursive_index_mbox(db_file, subname, mbox_filename_regexp, + nb_fields_to_parse, fields_to_parse); } } closedir(dir); } else { - index_mbox(entry_name, nb_fields_to_parse, fields_to_parse, db_file); + const char *s = entry_name, *filename = s; + while(*s) { if(*s == '/') { filename = s+1; }; s++; } + if(!mbox_filename_regexp || regexec(mbox_filename_regexp, filename, 0, 0, 0) == 0) { + index_mbox(entry_name, nb_fields_to_parse, fields_to_parse, db_file); + } } } @@ -705,10 +712,11 @@ static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "quiet", no_argument, 0, 'q' }, - { "db-file", 1, 0, 'd' }, + { "db-file-generate", 1, 0, 'd' }, { "db-pattern", 1, 0, 'p' }, { "db-root", 1, 0, 'r' }, { "db-list", 1, 0, 'l' }, + { "mbox-pattern", 1, 0, 'm' }, { "search", 1, 0, 's' }, { "index", 0, 0, 'i' }, { "output", 1, 0, 'o' }, @@ -876,6 +884,7 @@ int main(int argc, char **argv) { char *db_filename_regexp_string; char *db_root_path; char *db_filename_list; + char *mbox_filename_regexp_string; char output_filename[PATH_MAX + 1]; int action_index; int error = 0, show_help = 0; @@ -883,7 +892,6 @@ int main(int argc, char **argv) { char c; int f, n; int nb_search_conditions; - FILE *output_file; struct search_condition search_conditions[MAX_NB_SEARCH_CONDITIONS]; if(regcomp(&leading_from_line_regexp, LEADING_FROM_LINE_REGEXP, 0)) { @@ -898,6 +906,7 @@ int main(int argc, char **argv) { db_filename_regexp_string = 0; db_root_path = 0; db_filename_list = 0; + mbox_filename_regexp_string = 0; quiet = 0; default_search_field = 0; ignore_dot_files = 1; @@ -928,22 +937,46 @@ int main(int argc, char **argv) { break; case 'd': + if(db_filename) { + fprintf(stderr, "mymail: Can not set the db filename twice.\n"); + exit(EXIT_FAILURE); + } db_filename = strdup(optarg); break; case 'p': + if(db_filename_regexp_string) { + fprintf(stderr, "mymail: Can not set the db filename pattern twice.\n"); + exit(EXIT_FAILURE); + } db_filename_regexp_string = strdup(optarg); break; + case 'm': + if(mbox_filename_regexp_string) { + fprintf(stderr, "mymail: Can not set the mbox filename pattern twice.\n"); + exit(EXIT_FAILURE); + } + mbox_filename_regexp_string = strdup(optarg); + break; + case 'o': strncpy(output_filename, optarg, PATH_MAX); break; case 'r': + if(db_root_path) { + fprintf(stderr, "mymail: Can not set the db root path twice.\n"); + exit(EXIT_FAILURE); + } db_root_path = strdup(optarg); break; case 'l': + if(db_filename_list) { + fprintf(stderr, "mymail: Can not set the db filename list twice.\n"); + exit(EXIT_FAILURE); + } db_filename_list = strdup(optarg); break; @@ -966,6 +999,9 @@ int main(int argc, char **argv) { } } + /* Set all the values that may defined in the arguments, through + environment variables, or hard-coded */ + if(!db_filename) { char *default_db_filename = getenv("MYMAIL_DB_FILE"); @@ -1002,21 +1038,16 @@ int main(int argc, char **argv) { } } - if(output_filename[0]) { - output_file = fopen(output_filename, "w"); + if(!mbox_filename_regexp_string) { + char *default_mbox_filename_regexp_string = getenv("MYMAIL_MBOX_PATTERN"); - if(!output_file) { - fprintf(stderr, - "mymail: Cannot open result file \"%s\" for writing: %s\n", - output_filename, - strerror(errno)); - exit(EXIT_FAILURE); + if(default_mbox_filename_regexp_string) { + mbox_filename_regexp_string = strdup(default_mbox_filename_regexp_string); } - } else { - output_file = stdout; - quiet = 1; } + /* Start the processing */ + if(error) { print_usage(stderr); exit(EXIT_FAILURE); @@ -1027,8 +1058,26 @@ int main(int argc, char **argv) { exit(EXIT_SUCCESS); } + /* mbox indexing */ + if(action_index) { FILE *db_file; + regex_t mbox_filename_regexp_static; + regex_t *mbox_filename_regexp; + + if(mbox_filename_regexp_string) { + if(regcomp(&mbox_filename_regexp_static, + mbox_filename_regexp_string, + 0)) { + fprintf(stderr, + "mymail: Syntax error in regexp \"%s\".\n", + mbox_filename_regexp_string); + exit(EXIT_FAILURE); + } + mbox_filename_regexp = &mbox_filename_regexp_static; + } else { + mbox_filename_regexp = 0; + } db_file = fopen(db_filename, "w"); @@ -1056,7 +1105,7 @@ int main(int argc, char **argv) { while(optind < argc) { recursive_index_mbox(db_file, - argv[optind], + argv[optind], mbox_filename_regexp, nb_fields_to_parse, fields_to_parse); optind++; } @@ -1064,14 +1113,37 @@ int main(int argc, char **argv) { fflush(db_file); fclose(db_file); + if(mbox_filename_regexp) { + regfree(mbox_filename_regexp); + } + for(f = 0; f < nb_fields_to_parse; f++) { regfree(&fields_to_parse[f].regexp); } } + /* Mail search */ + else { + + FILE *output_file; int nb_extracted_mails = 0; + if(output_filename[0]) { + output_file = fopen(output_filename, "w"); + + if(!output_file) { + fprintf(stderr, + "mymail: Cannot open result file \"%s\" for writing: %s\n", + output_filename, + strerror(errno)); + exit(EXIT_FAILURE); + } + } else { + output_file = stdout; + quiet = 1; + } + if(nb_search_conditions > 0) { /* Recursive search if db_root_path is set */ @@ -1129,21 +1201,22 @@ int main(int argc, char **argv) { } } + fflush(output_file); + + if(output_file != stdout) { + fclose(output_file); + } } for(n = 0; n < nb_search_conditions; n++) { free_condition(&search_conditions[n]); } - if(output_file != stdout) { - fflush(output_file); - fclose(output_file); - } - free(db_filename); free(db_filename_regexp_string); free(db_root_path); free(db_filename_list); + free(mbox_filename_regexp_string); regfree(&leading_from_line_regexp); -- 2.20.1 From bdd9b1ab5a4326f9203c9cd8118cbcd24ddf31fd Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 12 Feb 2013 08:55:15 +0100 Subject: [PATCH 05/16] Cosmetics. --- mymail.c | 75 +++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/mymail.c b/mymail.c index 5287301..5fb92be 100644 --- a/mymail.c +++ b/mymail.c @@ -53,7 +53,7 @@ #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$" +#define LEADING_FROM_LINE_REGEXP_STRING "^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; @@ -165,6 +165,23 @@ char *parse_token(char *token_buffer, size_t token_buffer_size, return string; } +char *default_value(char *current_value, + const char *env_variable, + const char *hard_default_value) { + if(current_value) { + return current_value; + } else { + char *env_value = getenv(env_variable); + if(env_value) { + return strdup(env_value); + } else if(hard_default_value) { + return strdup(hard_default_value); + } else { + return 0; + } + } +} + /********************************************************************/ /* malloc with error checking. */ @@ -894,7 +911,7 @@ int main(int argc, char **argv) { int nb_search_conditions; struct search_condition search_conditions[MAX_NB_SEARCH_CONDITIONS]; - if(regcomp(&leading_from_line_regexp, LEADING_FROM_LINE_REGEXP, 0)) { + if(regcomp(&leading_from_line_regexp, LEADING_FROM_LINE_REGEXP_STRING, 0)) { fprintf(stderr, "mymail: Cannot compile leading \"from\" line regexp. That is strange.\n"); exit(EXIT_FAILURE); @@ -1002,49 +1019,25 @@ int main(int argc, char **argv) { /* Set all the values that may defined in the arguments, through environment variables, or hard-coded */ - if(!db_filename) { - char *default_db_filename = getenv("MYMAIL_DB_FILE"); - - if(!default_db_filename) { - default_db_filename = "mymail.db"; - } - - db_filename = strdup(default_db_filename); - } - - if(!db_filename_regexp_string) { - char *default_db_filename_regexp_string = getenv("MYMAIL_DB_PATTERN"); + db_filename = default_value(db_filename, + "MYMAIL_DB_FILE", + "mymail.db"); - if(!default_db_filename_regexp_string) { - default_db_filename_regexp_string = "^mymail.db$"; - } - - db_filename_regexp_string = strdup(default_db_filename_regexp_string); - } - - if(!db_root_path) { - char *default_db_root_path = getenv("MYMAIL_DB_ROOT"); - - if(default_db_root_path) { - db_root_path = strdup(default_db_root_path); - } - } - - if(!db_filename_list) { - char *default_db_filename_list = getenv("MYMAIL_DB_LIST"); + db_filename_regexp_string = default_value(db_filename_regexp_string, + "MYMAIL_DB_FILE", + "^mymail.db$"); - if(default_db_filename_list) { - db_filename_list = strdup(default_db_filename_list); - } - } + db_root_path = default_value(db_root_path, + "MYMAIL_DB_ROOT", + 0); - if(!mbox_filename_regexp_string) { - char *default_mbox_filename_regexp_string = getenv("MYMAIL_MBOX_PATTERN"); + db_filename_list = default_value(db_filename_list, + "MYMAIL_DB_LIST", + 0); - if(default_mbox_filename_regexp_string) { - mbox_filename_regexp_string = strdup(default_mbox_filename_regexp_string); - } - } + mbox_filename_regexp_string = default_value(mbox_filename_regexp_string, + "MYMAIL_MBOX_PATTERN", + "mbox$"); /* Start the processing */ -- 2.20.1 From 874926dc3a56a9127e32c757db0c32a4388c958b Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 12 Feb 2013 09:01:22 +0100 Subject: [PATCH 06/16] Added safe_fopen. --- mymail.c | 73 ++++++++++---------------------------------------------- 1 file changed, 13 insertions(+), 60 deletions(-) diff --git a/mymail.c b/mymail.c index 5fb92be..fd200a1 100644 --- a/mymail.c +++ b/mymail.c @@ -182,18 +182,16 @@ char *default_value(char *current_value, } } -/********************************************************************/ - -/* malloc with error checking. */ - -void *safe_malloc(size_t n) { - void *p = malloc(n); - if(!p && n != 0) { +FILE *safe_fopen(const char *path, const char *mode, const char *comment) { + FILE *result = fopen(path, mode); + if(result) { + return result; + } else { fprintf(stderr, - "mymail: cannot allocate memory: %s\n", strerror(errno)); + "mymail: Cannot open file '%s' (%s) with mode \"%s\".\n", + path, comment, mode); exit(EXIT_FAILURE); } - return p; } /*********************************************************************/ @@ -327,14 +325,7 @@ void update_body_hits(char *mail_filename, int position_in_mail, nb_body_hits = 0; header = 1; - mail_file = fopen(mail_filename, "r"); - - if(!mail_file) { - fprintf(stderr, - "mymail: Cannot open mbox '%s' for body scan.\n", - mail_filename); - exit(EXIT_FAILURE); - } + mail_file = safe_fopen(mail_filename, "r", "mbox for body scan"); fseek(mail_file, position_in_mail, SEEK_SET); @@ -371,15 +362,7 @@ void extract_mail(const char *mail_filename, unsigned long int position_in_mail, char raw_mbox_line[BUFFER_SIZE]; FILE *mail_file; - mail_file = fopen(mail_filename, "r"); - - if(!mail_file) { - fprintf(stderr, - "mymail: Cannot open mbox '%s' for mail extraction.\n", - mail_filename); - exit(EXIT_FAILURE); - } - + mail_file = safe_fopen(mail_filename, "r", "mbox for mail extraction"); fseek(mail_file, position_in_mail, SEEK_SET); if(fgets(raw_mbox_line, BUFFER_SIZE, mail_file)) { @@ -419,15 +402,7 @@ int search_in_db(const char *db_filename, fflush(stdout); } - db_file = fopen(db_filename, "r"); - - if(!db_file) { - fprintf(stderr, - "mymail: Cannot open \"%s\" for reading: %s\n", - db_filename, - strerror(errno)); - exit(EXIT_FAILURE); - } + db_file = safe_fopen(db_filename, "r", "index file for search"); /* First, check the db file leading line integrity */ @@ -603,13 +578,7 @@ void index_mbox(const char *mbox_filename, int in_header, new_header; unsigned long int position_in_file; - file = fopen(mbox_filename, "r"); - - if(!file) { - fprintf(stderr, "mymail: Cannot open '%s'.\n", mbox_filename); - if(paranoid) { exit(EXIT_FAILURE); } - return; - } + file = safe_fopen(mbox_filename, "r", "mbox for indexing"); in_header = 0; new_header = 0; @@ -1072,15 +1041,7 @@ int main(int argc, char **argv) { mbox_filename_regexp = 0; } - db_file = fopen(db_filename, "w"); - - if(!db_file) { - fprintf(stderr, - "mymail: Cannot open \"%s\" for writing: %s\n", - db_filename, - strerror(errno)); - exit(EXIT_FAILURE); - } + db_file = safe_fopen(db_filename, "w", "index file for indexing"); for(f = 0; f < nb_fields_to_parse; f++) { if(regcomp(&fields_to_parse[f].regexp, @@ -1123,15 +1084,7 @@ int main(int argc, char **argv) { int nb_extracted_mails = 0; if(output_filename[0]) { - output_file = fopen(output_filename, "w"); - - if(!output_file) { - fprintf(stderr, - "mymail: Cannot open result file \"%s\" for writing: %s\n", - output_filename, - strerror(errno)); - exit(EXIT_FAILURE); - } + output_file = safe_fopen(output_filename, "w", "result mbox"); } else { output_file = stdout; quiet = 1; -- 2.20.1 From 25be1ba3ca97913b1e15eefeb124daa5c34ea5be Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 12 Feb 2013 09:13:51 +0100 Subject: [PATCH 07/16] Cosmetics. --- mymail.c | 61 +++++++++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/mymail.c b/mymail.c index fd200a1..8926cd5 100644 --- a/mymail.c +++ b/mymail.c @@ -61,7 +61,6 @@ regex_t leading_from_line_regexp; int paranoid; int quiet; -char *default_search_field; int ignore_dot_files; /********************************************************************/ @@ -153,8 +152,8 @@ int xor(int a, int b) { return (a && !b) || (!a && b); } -char *parse_token(char *token_buffer, size_t token_buffer_size, - char separator, char *string) { +const char *parse_token(char *token_buffer, size_t token_buffer_size, + char separator, const char *string) { char *u = token_buffer; while(u < token_buffer + token_buffer_size - 1 && *string && *string != separator) { @@ -184,6 +183,7 @@ char *default_value(char *current_value, FILE *safe_fopen(const char *path, const char *mode, const char *comment) { FILE *result = fopen(path, mode); + /* printf("Opening '%s' with mode \"%s\"\n", path, mode); */ if(result) { return result; } else { @@ -255,27 +255,16 @@ int ignore_entry(const char *name) { int is_a_leading_from_line(char *mbox_line) { return - - /* - - The mbox man page in qmail documentation states: - - > The reader should not attempt to take advantage of the fact - > that every From_ line (past the beginning of the file) is - > preceded by a blank line. - - */ - strncmp(mbox_line, "From ", 5) == 0 && regexec(&leading_from_line_regexp, mbox_line, 0, 0, 0) == 0; } int mbox_line_match_search(struct search_condition *condition, - int mbox_id, char *mbox_value) { + int mbox_id, const char *mbox_value) { if(condition->field_id == ID_INTERVAL) { if(mbox_id == ID_LEADING_LINE) { - char *c; + const char *c; time_t t; struct tm tm; @@ -388,7 +377,8 @@ int search_in_db(const char *db_filename, char raw_db_line[BUFFER_SIZE]; char current_mail_filename[PATH_MAX + 1]; unsigned long int current_position_in_mail; - char mbox_name[TOKEN_BUFFER_SIZE], *mbox_value; + char mbox_name[TOKEN_BUFFER_SIZE]; + const char *mbox_value; int mbox_id; int already_written, m, n; int nb_body_conditions, nb_fulfilled_body_conditions; @@ -527,6 +517,8 @@ int recursive_search_in_db(const char *entry_name, regex_t *db_filename_regexp, exit(EXIT_FAILURE); } + /* printf("recursive_search_in_db %s\n", entry_name); */ + dir = opendir(entry_name); if(dir) { @@ -712,10 +704,11 @@ static struct option long_options[] = { /*********************************************************************/ -void init_condition(struct search_condition *condition, char *full_string) { +void init_condition(struct search_condition *condition, const char *full_string, + const char *default_search_field) { char full_search_field[TOKEN_BUFFER_SIZE], *search_field; int m; - char *string; + const char *string; string = parse_token(full_search_field, TOKEN_BUFFER_SIZE, ' ', full_string); search_field = full_search_field; @@ -866,13 +859,14 @@ void free_condition(struct search_condition *condition) { /*********************************************************************/ int main(int argc, char **argv) { - char *db_filename; - char *db_filename_regexp_string; - char *db_root_path; - char *db_filename_list; - char *mbox_filename_regexp_string; + char *db_filename = 0; + char *db_filename_regexp_string = 0; + char *db_root_path = 0; + char *db_filename_list = 0; + char *mbox_filename_regexp_string = 0; + char *default_search_field; char output_filename[PATH_MAX + 1]; - int action_index; + int action_index = 0; int error = 0, show_help = 0; const int nb_fields_to_parse = sizeof(fields_to_parse) / sizeof(struct parsable_field); char c; @@ -887,21 +881,16 @@ int main(int argc, char **argv) { } paranoid = 0; - action_index = 0; - db_filename = 0; - db_filename_regexp_string = 0; - db_root_path = 0; - db_filename_list = 0; - mbox_filename_regexp_string = 0; quiet = 0; default_search_field = 0; ignore_dot_files = 1; + strncpy(output_filename, "", PATH_MAX); setlocale(LC_ALL, ""); nb_search_conditions = 0; - while ((c = getopt_long(argc, argv, "hvqip:s:d:r:l:o:a:", + while ((c = getopt_long(argc, argv, "hvqip:s:d:r:l:o:a:m:", long_options, NULL)) != -1) { switch(c) { @@ -971,7 +960,7 @@ int main(int argc, char **argv) { fprintf(stderr, "mymail: Too many search patterns.\n"); exit(EXIT_FAILURE); } - init_condition(&search_conditions[nb_search_conditions], optarg); + init_condition(&search_conditions[nb_search_conditions], optarg, default_search_field); nb_search_conditions++; break; @@ -994,7 +983,7 @@ int main(int argc, char **argv) { db_filename_regexp_string = default_value(db_filename_regexp_string, "MYMAIL_DB_FILE", - "^mymail.db$"); + "\.db$"); db_root_path = default_value(db_root_path, "MYMAIL_DB_ROOT", @@ -1006,7 +995,7 @@ int main(int argc, char **argv) { mbox_filename_regexp_string = default_value(mbox_filename_regexp_string, "MYMAIL_MBOX_PATTERN", - "mbox$"); + 0); /* Start the processing */ @@ -1116,7 +1105,7 @@ int main(int argc, char **argv) { if(db_filename_list) { char db_filename[PATH_MAX + 1]; - char *s; + const char *s; s = db_filename_list; -- 2.20.1 From 32a03eca0ebb48facce97a8740993e2df893d518 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 12 Feb 2013 09:19:07 +0100 Subject: [PATCH 08/16] Typo. --- mymail.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mymail.c b/mymail.c index 8926cd5..67f076b 100644 --- a/mymail.c +++ b/mymail.c @@ -983,7 +983,7 @@ int main(int argc, char **argv) { db_filename_regexp_string = default_value(db_filename_regexp_string, "MYMAIL_DB_FILE", - "\.db$"); + "\\.db$"); db_root_path = default_value(db_root_path, "MYMAIL_DB_ROOT", -- 2.20.1 From 592f082bf057a152b394a2c331241063be96e2d9 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 12 Feb 2013 18:23:10 +0100 Subject: [PATCH 09/16] Debugged and cleaned up the time-related queries. --- mymail.c | 173 ++++++++++++++++++++++--------------------------------- 1 file changed, 70 insertions(+), 103 deletions(-) diff --git a/mymail.c b/mymail.c index 67f076b..ef6e5c1 100644 --- a/mymail.c +++ b/mymail.c @@ -234,18 +234,6 @@ void print_usage(FILE *out) { /*********************************************************************/ -time_t time_for_past_day(int day) { - time_t t; - struct tm *tm; - int delta_day; - t = time(0); - tm = localtime(&t); - delta_day = (7 + tm->tm_wday - day) % 7 + 1; - return t - delta_day * 3600 * 24 + tm->tm_sec + 60 * tm->tm_min + 3600 * tm->tm_hour; -} - -/*********************************************************************/ - int ignore_entry(const char *name) { return strcmp(name, ".") == 0 || @@ -548,10 +536,11 @@ int recursive_search_in_db(const char *entry_name, regex_t *db_filename_regexp, /*********************************************************************/ -void index_one_mbox_line(int nb_fields_to_parse, struct parsable_field *fields_to_parse, +void index_one_mbox_line(unsigned int nb_fields_to_parse, + struct parsable_field *fields_to_parse, char *raw_mbox_line, FILE *db_file) { regmatch_t matches; - int f; + unsigned int f; for(f = 0; f < nb_fields_to_parse; f++) { if(regexec(&fields_to_parse[f].regexp, raw_mbox_line, 1, &matches, 0) == 0) { fprintf(db_file, "%s %s\n", @@ -702,12 +691,52 @@ static struct option long_options[] = { { 0, 0, 0, 0 } }; +struct time_criterion { + char *label; + int start_hour, end_hour; + int past_week_day; +}; + +/*********************************************************************/ + +static struct time_criterion time_criteria[] = { + + { "8h", 8, -1, -1 }, + { "today", 24, -1, -1 }, + { "24h", 24, -1, -1 }, + { "week", 24 * 7, -1, -1 }, + { "month", 24 * 31, -1, -1 }, + { "year", 24 * 365, -1, -1 }, + + { "yesterday", 48, 24, -1 }, + + { "monday", -1, -1, 1 }, + { "tuesday", -1, -1, 2 }, + { "wednesday", -1, -1, 3 }, + { "thursday", -1, -1, 4 }, + { "friday", -1, -1, 5 }, + { "saturday", -1, -1, 6 }, + { "sunday", -1, -1, 7 }, + +}; + /*********************************************************************/ +time_t time_for_past_day(int day) { + time_t t; + struct tm *tm; + int delta_day; + t = time(0); + tm = localtime(&t); + delta_day = (7 + tm->tm_wday - day) % 7; + if(delta_day == 0) { delta_day = 7; } + return t - (delta_day * 3600 * 24 + tm->tm_sec + 60 * tm->tm_min + 3600 * tm->tm_hour); +} + void init_condition(struct search_condition *condition, const char *full_string, const char *default_search_field) { char full_search_field[TOKEN_BUFFER_SIZE], *search_field; - int m; + unsigned int k, m; const char *string; string = parse_token(full_search_field, TOKEN_BUFFER_SIZE, ' ', full_string); @@ -720,96 +749,31 @@ void init_condition(struct search_condition *condition, const char *full_string, condition->negation = 0; } - /* Recently */ - - if(strcmp(search_field, "8h") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time(0) - 3600 * 8; - condition->interval_stop = 0; - } + condition->field_id = -1; - else if(strcmp(search_field, "24h") == 0 || - strcmp(search_field, "today") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time(0) - 3600 * 24; - condition->interval_stop = 0; - } - - else if(strcmp(search_field, "week") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time(0) - 3600 * 24 * 7; - condition->interval_stop = 0; - } - - else if(strcmp(search_field, "month") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time(0) - 3600 * 24 * 31; - condition->interval_stop = 0; - } - - else if(strcmp(search_field, "year") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time(0) - 3600 * 24 * 365; - condition->interval_stop = 0; - } - - /* Yesterday */ - - else if(strcmp(search_field, "yesterday") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time(0) - 2 * 3600 * 24; - condition->interval_stop = condition->interval_start + 3600 * 24; - } - - /* Week days */ - - else if(strcmp(search_field, "monday") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time_for_past_day(1); - condition->interval_stop = condition->interval_start + 3600 * 24; - } - - else if(strcmp(search_field, "tuesday") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time_for_past_day(2); - condition->interval_stop = condition->interval_start + 3600 * 24; - } - - else if(strcmp(search_field, "wednesday") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time_for_past_day(3); - condition->interval_stop = condition->interval_start + 3600 * 24; - } - - else if(strcmp(search_field, "thursday") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time_for_past_day(4); - condition->interval_stop = condition->interval_start + 3600 * 24; - } - - else if(strcmp(search_field, "friday") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time_for_past_day(5); - condition->interval_stop = condition->interval_start + 3600 * 24; - } - - else if(strcmp(search_field, "saturday") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time_for_past_day(6); - condition->interval_stop = condition->interval_start + 3600 * 24; - } + /* Recently */ - else if(strcmp(search_field, "sunday") == 0) { - condition->field_id = ID_INTERVAL; - condition->interval_start = time_for_past_day(7); - condition->interval_stop = condition->interval_start + 3600 * 24; + for(k = 0; k < sizeof(time_criteria) / sizeof(struct time_criterion); k++) { + if(strcmp(time_criteria[k].label, search_field) == 0) { + condition->field_id = ID_INTERVAL; + if(time_criteria[k].past_week_day < 0) { + condition->interval_start = time(0) - 3600 * time_criteria[k].start_hour; + if(time_criteria[k].end_hour >= 0) { + condition->interval_stop = time(0) - 3600 * time_criteria[k].end_hour; + } else { + condition->interval_stop = 0; + } + } else { + condition->interval_start = time_for_past_day(time_criteria[k].past_week_day); + condition->interval_stop = condition->interval_start + 3600 * 24; + } + break; + } } - else { - - /* header-related conditions */ + if(condition->field_id == -1) { - condition->field_id = -1; + /* No time condition matched, look for the search fields */ for(m = 0; (m < MAX_ID) && condition->field_id == -1; m++) { if(strncmp(field_names[m], search_field, strlen(search_field)) == 0) { @@ -817,6 +781,8 @@ void init_condition(struct search_condition *condition, const char *full_string, } } + /* None match, if there is a default search field, re-run the search with it */ + if(condition->field_id == -1) { if(default_search_field) { for(m = 0; (m < MAX_ID) && condition->field_id == -1; m++) { @@ -868,10 +834,11 @@ int main(int argc, char **argv) { char output_filename[PATH_MAX + 1]; int action_index = 0; int error = 0, show_help = 0; - const int nb_fields_to_parse = sizeof(fields_to_parse) / sizeof(struct parsable_field); + const unsigned int nb_fields_to_parse = + sizeof(fields_to_parse) / sizeof(struct parsable_field); char c; - int f, n; - int nb_search_conditions; + unsigned int f, n; + unsigned int nb_search_conditions; struct search_condition search_conditions[MAX_NB_SEARCH_CONDITIONS]; if(regcomp(&leading_from_line_regexp, LEADING_FROM_LINE_REGEXP_STRING, 0)) { -- 2.20.1 From 32a6e5613bc88b99aae6ebae35ad87e8dc9c471b Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 12 Feb 2013 19:01:12 +0100 Subject: [PATCH 10/16] Cosmetics. --- mymail.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mymail.c b/mymail.c index ef6e5c1..325562e 100644 --- a/mymail.c +++ b/mymail.c @@ -55,14 +55,14 @@ #define LEADING_FROM_LINE_REGEXP_STRING "^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! */ int paranoid; int quiet; int ignore_dot_files; +regex_t leading_from_line_regexp; + /********************************************************************/ enum { @@ -183,7 +183,6 @@ char *default_value(char *current_value, FILE *safe_fopen(const char *path, const char *mode, const char *comment) { FILE *result = fopen(path, mode); - /* printf("Opening '%s' with mode \"%s\"\n", path, mode); */ if(result) { return result; } else { -- 2.20.1 From 46359032040466742b597614ca5b353948993b98 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 12 Feb 2013 23:02:21 +0100 Subject: [PATCH 11/16] Cosmetics. --- mymail.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mymail.c b/mymail.c index 325562e..b7e46ba 100644 --- a/mymail.c +++ b/mymail.c @@ -155,11 +155,12 @@ int xor(int a, int b) { const char *parse_token(char *token_buffer, size_t token_buffer_size, char separator, const char *string) { char *u = token_buffer; + while(*string == separator) { string++; } while(u < token_buffer + token_buffer_size - 1 && *string && *string != separator) { *(u++) = *(string++); } - while(*string == separator) string++; + while(*string == separator) { string++; } *u = '\0'; return string; } -- 2.20.1 From b70085e4312ec224a92e696efdb6a0667cbd0faf Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 12 Feb 2013 23:22:43 +0100 Subject: [PATCH 12/16] Increased the version number to 0.9.5. --- mymail.1 | 2 +- mymail.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mymail.1 b/mymail.1 index 95b83f0..b6edee0 100644 --- a/mymail.1 +++ b/mymail.1 @@ -1,4 +1,4 @@ -.TH "MYMAIL" "0.9.2" "February 2013" "Francois Fleuret" "User Commands" +.TH "MYMAIL" "0.9.5" "February 2013" "Francois Fleuret" "User Commands" \" This man page was written by Francois Fleuret \" and is distributed under a Creative Commons Attribution-Share Alike diff --git a/mymail.c b/mymail.c index b7e46ba..3718157 100644 --- a/mymail.c +++ b/mymail.c @@ -46,7 +46,7 @@ #include #define MYMAIL_DB_MAGIC_TOKEN "mymail_index_file" -#define VERSION "0.9.2" +#define VERSION "0.9.5" #define MAX_NB_SEARCH_CONDITIONS 32 -- 2.20.1 From 0b0fa4842f3caddfb46758e81abe44e0207e2ea2 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Wed, 13 Feb 2013 21:25:12 +0100 Subject: [PATCH 13/16] Added the "48h" criterion and some clarifications in the man page. --- mymail.1 | 7 +++++-- mymail.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mymail.1 b/mymail.1 index b6edee0..e0f89f1 100644 --- a/mymail.1 +++ b/mymail.1 @@ -83,6 +83,9 @@ space and a regexp, which can itself contain spaces. If the condition is prefaced by the character "!" it is negated, and has to be false for a mail to be selected. +The time-based condition use as reference the time indicated in the +heading From line, and not in the Date: field. + .TP \fBf \fR (from) selects mails whose leading line From, or fields From:, Sender:, @@ -106,9 +109,9 @@ condition requires to read the original mboxes completely, which can be slow. However, header conditions are checked first to read the bodies only for mails which fulfill them entirely. .TP -\fB8h\fR, \fBtoday\fR, \fB24h\fR, \fBweek\fR, \fBmonth\fR, and +\fB8h\fR, \fBtoday\fR, \fB24h\fR, \fB48h\fR, \fBweek\fR, \fBmonth\fR, and \fByear\fR -selects mails received during the last 8, 24, 24, 7 * 24 hours, 31 * +selects mails received during the last 8, 24, 24, 48, 7 * 24 hours, 31 * 24 hours, and 365 * 24 hours respectively. .TP \fByesterday\fR diff --git a/mymail.c b/mymail.c index 3718157..6e3f5cc 100644 --- a/mymail.c +++ b/mymail.c @@ -704,6 +704,7 @@ static struct time_criterion time_criteria[] = { { "8h", 8, -1, -1 }, { "today", 24, -1, -1 }, { "24h", 24, -1, -1 }, + { "48h", 48, -1, -1 }, { "week", 24 * 7, -1, -1 }, { "month", 24 * 31, -1, -1 }, { "year", 24 * 365, -1, -1 }, -- 2.20.1 From 8702faa9b8718133b6daf349f61fee7b77348182 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 17 Feb 2013 11:36:44 +0100 Subject: [PATCH 14/16] Cosmetics. --- mymail.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mymail.c b/mymail.c index 6e3f5cc..df64b5a 100644 --- a/mymail.c +++ b/mymail.c @@ -432,19 +432,19 @@ int search_in_db(const char *db_filename, /* Now check the body ones */ + nb_fulfilled_body_conditions = 0; + if(nb_body_conditions > 0) { update_body_hits(current_mail_filename, current_position_in_mail, nb_search_conditions, search_conditions, nb_body_conditions, hits); - } - - nb_fulfilled_body_conditions = 0; - for(n = 0; n < nb_search_conditions; n++) { - if(search_conditions[n].field_id == ID_BODY && - xor(hits[n], search_conditions[n].negation)) { - nb_fulfilled_body_conditions++; + for(n = 0; n < nb_search_conditions; n++) { + if(search_conditions[n].field_id == ID_BODY && + xor(hits[n], search_conditions[n].negation)) { + nb_fulfilled_body_conditions++; + } } } -- 2.20.1 From 0b0531480a17cdf846eb03ae361e076a3840c93e Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sat, 23 Feb 2013 14:11:00 +0100 Subject: [PATCH 15/16] Update with groups for defcustom, cosmetics, and mymail/default-search-request. --- mymail-vm.el | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/mymail-vm.el b/mymail-vm.el index dc1976c..840bd93 100644 --- a/mymail-vm.el +++ b/mymail-vm.el @@ -16,23 +16,45 @@ ;; You should have received a copy of the GNU General Public License ;; along with mymail. If not, see . -(add-to-list 'recentf-exclude "/tmp/mymail-vm-.*\.mbox") +;; You may want to add +;; +;; (add-to-list 'recentf-exclude "/tmp/mymail-vm-.*\.mbox") +;; +;; to your .emacs + +(defgroup mymail () + "Command to visit a folder build on-the-fly with mymail" + :version "0.9.5") -(defcustom mymail/default-search-request "" - "Default request to add to any search" - :type 'string) +(defcustom mymail/default-additional-search-requests "" + "Comma-separated list of search requests to add to any search" + :type 'string + :group 'mymail) + +(defcustom mymail/default-search-request nil + "Default request to use in place of the empty search" + :type 'string + :group 'mymail) (defun mymail/vm-visit-folder (param) "Read a comma-separated list of search requests for mymail, create a temporary mbox with the resulting mails, and open it in vm with `vm-visit-folder'. -The string `mymail/default-search-request' is automatically +If the request string is empty, use +`mymail/default-search-request' instead. + +The string `mymail/default-additional-search-requests' is automatically concatenated to the provided request, except if the request is prefaced with \\." (interactive (list (read-string "mymail-vm: " nil 'mymail-vm-history))) + (if (string= param "") + (if mymail/default-search-request + (setq param mymail/default-search-request) + (error "mymail error: empty search"))) + (let ((n 1) (mbox-name nil) @@ -45,7 +67,7 @@ prefaced with \\." (list "--search" searche-request))) (if (string= (substring param 0 1) "\\") (split-string (substring param 1 nil) ",") - (split-string (concat param "," mymail/default-search-request) ",")) + (split-string (concat param "," mymail/default-additional-search-requests) ",")) ))) ) -- 2.20.1 From 753b7cb9dd8e1929b9f52400a28a9aab0062cad3 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 24 Feb 2013 15:54:54 +0100 Subject: [PATCH 16/16] Simplified a bit. --- mymail.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mymail.c b/mymail.c index df64b5a..219f6a3 100644 --- a/mymail.c +++ b/mymail.c @@ -57,9 +57,7 @@ /* Global variables! */ -int paranoid; int quiet; -int ignore_dot_files; regex_t leading_from_line_regexp; @@ -238,7 +236,7 @@ int ignore_entry(const char *name) { return strcmp(name, ".") == 0 || strcmp(name, "..") == 0 || - (ignore_dot_files && name[0] == '.' && name[1] != '/'); + (name[0] == '.' && name[1] != '/'); } int is_a_leading_from_line(char *mbox_line) { @@ -575,7 +573,6 @@ void index_mbox(const char *mbox_filename, "Got a ^\"From \" in the header in %s:%lu.\n", mbox_filename, position_in_file); fprintf(stderr, "%s", raw_mbox_line); - if(paranoid) { exit(EXIT_FAILURE); } } in_header = 1; new_header = 1; @@ -848,10 +845,8 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - paranoid = 0; quiet = 0; default_search_field = 0; - ignore_dot_files = 1; strncpy(output_filename, "", PATH_MAX); setlocale(LC_ALL, ""); -- 2.20.1