Added the "trimester" request.
[mymail.git] / mymail.c
index e6a2687..88c01f5 100644 (file)
--- a/mymail.c
+++ b/mymail.c
@@ -46,7 +46,9 @@
 #include <time.h>
 
 #define MYMAIL_DB_MAGIC_TOKEN "mymail_index_file"
-#define VERSION "0.9.6"
+#define MYMAIL_VERSION "0.9.8"
+
+#define MYMAIL_DB_FORMAT_VERSION 1
 
 #define MAX_NB_SEARCH_CONDITIONS 32
 
@@ -199,7 +201,7 @@ FILE *safe_fopen(const char *path, const char *mode, const char *comment) {
 /*********************************************************************/
 
 void print_version(FILE *out) {
-  fprintf(out, "mymail version %s (%s)\n", VERSION, UNAME);
+  fprintf(out, "mymail version %s (%s)\n", MYMAIL_VERSION, UNAME);
 }
 
 void print_usage(FILE *out) {
@@ -227,7 +229,7 @@ void print_usage(FILE *out) {
   fprintf(out, "         set the mbox filename pattern for recursive search\n");
   fprintf(out, " -s <search pattern>, --search <search pattern>\n");
   fprintf(out, "         search for matching mails in the db file\n");
-  fprintf(out, " -d <db filename>, --db-file-generate <db filename>\n");
+  fprintf(out, " -d <db filename>, --db-file-output <db filename>\n");
   fprintf(out, "         set the db filename for indexing\n");
   fprintf(out, " -i, --index\n");
   fprintf(out, "         index mails\n");
@@ -321,6 +323,8 @@ void extract_mail(const char *mail_filename, unsigned long int position_in_mail,
   char raw_mbox_line[BUFFER_SIZE];
   FILE *mail_file;
 
+  /* printf("Extract\n"); */
+
   mail_file = safe_fopen(mail_filename, "r", "mbox for mail extraction");
   fseek(mail_file, position_in_mail, SEEK_SET);
 
@@ -395,6 +399,7 @@ void update_time(int db_key, const char *db_value, time_t *t) {
   if(db_key == ID_LEADING_LINE) {
     c = db_value;
     while(*c && *c != ' ') c++; while(*c && *c == ' ') c++;
+    /* printf("From %s", db_value); */
     strptime(c, "%a %b %e %k:%M:%S %Y", &tm);
     *t = mktime(&tm);
   } else {
@@ -402,6 +407,7 @@ void update_time(int db_key, const char *db_value, time_t *t) {
       if(db_key == ID_DATE) {
         if(strptime(db_value, "%a, %d %b %Y %k:%M:%S", &tm) ||
            strptime(db_value, "%d %b %Y %k:%M:%S", &tm)) {
+          /* printf("Date: %s", db_value); */
           *t = mktime(&tm);
         }
       }
@@ -733,7 +739,7 @@ static struct option long_options[] = {
   { "version", no_argument, 0, 'v' },
   { "quiet", no_argument, 0, 'q' },
   { "use-leading-time", no_argument, 0, 't' },
-  { "db-file-generate", 1, 0, 'd' },
+  { "db-file-output", 1, 0, 'd' },
   { "db-pattern", 1, 0, 'p' },
   { "db-root", 1, 0, 'r' },
   { "db-list", 1, 0, 'l' },
@@ -761,6 +767,7 @@ static struct time_criterion time_criteria[] = {
   { "48h",       0, 48,       -1, -1 },
   { "week",      0, 24 *   7, -1, -1 },
   { "month",     0, 24 *  31, -1, -1 },
+  { "trimester", 0, 24 *  92, -1, -1 },
   { "year",      0, 24 * 365, -1, -1 },
 
   { "yesterday", 1, -1,       -1, -1 },
@@ -826,6 +833,7 @@ void init_condition(struct search_condition *condition, const char *full_string,
           condition->time_stop = 0;
         }
       }
+
       break;
     }
   }
@@ -1074,7 +1082,7 @@ int main(int argc, char **argv) {
       }
     }
 
-    fprintf(db_file, "%s version_%s raw\n", MYMAIL_DB_MAGIC_TOKEN, VERSION);
+    fprintf(db_file, "%s version_%s format_%d raw\n", MYMAIL_DB_MAGIC_TOKEN, MYMAIL_VERSION, MYMAIL_DB_FORMAT_VERSION);
 
     while(optind < argc) {
       recursive_index_mbox(db_file,