projects
/
mymail.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Cosmetics.
[mymail.git]
/
mymail.c
diff --git
a/mymail.c
b/mymail.c
index
b3f76d1
..
e802be1
100644
(file)
--- a/
mymail.c
+++ b/
mymail.c
@@
-46,14
+46,16
@@
#include <time.h>
#define MYMAIL_DB_MAGIC_TOKEN "mymail_index_file"
#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
#define BUFFER_SIZE 65536
#define TOKEN_BUFFER_SIZE 1024
#define MAX_NB_SEARCH_CONDITIONS 32
#define BUFFER_SIZE 65536
#define TOKEN_BUFFER_SIZE 1024
-#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$"
+#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\\) [ 0
123][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]\n$"
/* Global variables! */
/* Global variables! */
@@
-154,12
+156,15
@@
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;
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(*string == separator) { string++; }
- while(u < token_buffer + token_buffer_size - 1 && *string &&
-
*string != separator) {
+
+
while(u < token_buffer + token_buffer_size - 1 && *string &&
*string != separator) {
*(u++) = *(string++);
}
*(u++) = *(string++);
}
+
while(*string == separator) { string++; }
while(*string == separator) { string++; }
+
*u = '\0';
return string;
}
*u = '\0';
return string;
}
@@
-196,7
+201,7
@@
FILE *safe_fopen(const char *path, const char *mode, const char *comment) {
/*********************************************************************/
void print_version(FILE *out) {
/*********************************************************************/
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) {
}
void print_usage(FILE *out) {
@@
-224,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, " 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");
fprintf(out, " set the db filename for indexing\n");
fprintf(out, " -i, --index\n");
fprintf(out, " index mails\n");
@@
-290,9
+295,6
@@
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) {
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'); */
- /* if(last_mbox_line_was_empty) { header = 0; } */
-
if(raw_mbox_line[0] == '\n') { header = 0; }
if(!header) {
if(raw_mbox_line[0] == '\n') { header = 0; }
if(!header) {
@@
-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;
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);
mail_file = safe_fopen(mail_filename, "r", "mbox for mail extraction");
fseek(mail_file, position_in_mail, SEEK_SET);
@@
-328,8
+332,7
@@
void extract_mail(const char *mail_filename, unsigned long int position_in_mail,
fprintf(output_file, "%s", raw_mbox_line);
while(1) {
if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
fprintf(output_file, "%s", raw_mbox_line);
while(1) {
if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
- (is_a_leading_from_line(raw_mbox_line))
- )
+ is_a_leading_from_line(raw_mbox_line))
break;
fprintf(output_file, "%s", raw_mbox_line);
}
break;
fprintf(output_file, "%s", raw_mbox_line);
}
@@
-396,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++;
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 {
strptime(c, "%a %b %e %k:%M:%S %Y", &tm);
*t = mktime(&tm);
} else {
@@
-403,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)) {
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);
}
}
*t = mktime(&tm);
}
}
@@
-734,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' },
{ "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' },
{ "db-pattern", 1, 0, 'p' },
{ "db-root", 1, 0, 'r' },
{ "db-list", 1, 0, 'l' },
@@
-827,6
+832,7
@@
void init_condition(struct search_condition *condition, const char *full_string,
condition->time_stop = 0;
}
}
condition->time_stop = 0;
}
}
+
break;
}
}
break;
}
}
@@
-1075,7
+1081,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,
while(optind < argc) {
recursive_index_mbox(db_file,