Commit b47025b2 authored by Kim Vandry's avatar Kim Vandry

Introduced MTY_IMAP message type. Not yet used.

parent 49df3747
...@@ -134,12 +134,13 @@ static void check_message_path_integrity(struct database *db)/*{{{*/ ...@@ -134,12 +134,13 @@ static void check_message_path_integrity(struct database *db)/*{{{*/
/* TODO : for now only checks integrity of non-mbox paths. */ /* TODO : for now only checks integrity of non-mbox paths. */
/* Check there are no duplicates */ /* Check there are no duplicates */
int i; int i;
int n; int n, imap_n;
int has_duplicate = 0; int has_duplicate = 0;
char **paths; char **paths, **imaps;
paths = new_array(char *, db->n_msgs); paths = new_array(char *, db->n_msgs);
for (i=0, n=0; i<db->n_msgs; i++) { imaps = new_array(char *, db->n_msgs);
for (i=0, n=0, imap_n=0; i<db->n_msgs; i++) {
switch (db->type[i]) { switch (db->type[i]) {
case MTY_DEAD: case MTY_DEAD:
case MTY_MBOX: case MTY_MBOX:
...@@ -147,10 +148,14 @@ static void check_message_path_integrity(struct database *db)/*{{{*/ ...@@ -147,10 +148,14 @@ static void check_message_path_integrity(struct database *db)/*{{{*/
case MTY_FILE: case MTY_FILE:
paths[n++] = db->msgs[i].src.mpf.path; paths[n++] = db->msgs[i].src.mpf.path;
break; break;
case MTY_IMAP:
imaps[imap_n++] = db->msgs[i].src.mpf.path;
break;
} }
} }
qsort(paths, n, sizeof(char *), compare_strings); qsort(paths, n, sizeof(char *), compare_strings);
qsort(imaps, imap_n, sizeof(char *), compare_strings);
for (i=1; i<n; i++) { for (i=1; i<n; i++) {
if (!strcmp(paths[i-1], paths[i])) { if (!strcmp(paths[i-1], paths[i])) {
...@@ -158,11 +163,18 @@ static void check_message_path_integrity(struct database *db)/*{{{*/ ...@@ -158,11 +163,18 @@ static void check_message_path_integrity(struct database *db)/*{{{*/
has_duplicate = 1; has_duplicate = 1;
} }
} }
for (i=1; i<imap_n; i++) {
if (!strcmp(imaps[i-1], imaps[i])) {
fprintf(stderr, "IMAP message <%s> repeated\n", imaps[i]);
has_duplicate = 1;
}
}
fflush(stderr); fflush(stderr);
assert(!has_duplicate); assert(!has_duplicate);
free(paths); free(paths);
free(imaps);
return; return;
} }
/*}}}*/ /*}}}*/
...@@ -241,6 +253,7 @@ void free_database(struct database *db)/*{{{*/ ...@@ -241,6 +253,7 @@ void free_database(struct database *db)/*{{{*/
case MTY_MBOX: case MTY_MBOX:
break; break;
case MTY_FILE: case MTY_FILE:
case MTY_IMAP:
assert(db->msgs[i].src.mpf.path); assert(db->msgs[i].src.mpf.path);
free(db->msgs[i].src.mpf.path); free(db->msgs[i].src.mpf.path);
break; break;
...@@ -469,6 +482,12 @@ struct database *new_database_from_file(char *db_filename, int do_integrity_chec ...@@ -469,6 +482,12 @@ struct database *new_database_from_file(char *db_filename, int do_integrity_chec
result->msgs[i].src.mpf.mtime = input->mtime_table[i]; result->msgs[i].src.mpf.mtime = input->mtime_table[i];
result->msgs[i].src.mpf.size = input->size_table[i]; result->msgs[i].src.mpf.size = input->size_table[i];
break; break;
case DB_MSG_IMAP:
result->type[i] = MTY_IMAP;
result->msgs[i].src.mpf.path = new_string(input->data + input->path_offsets[i]);
result->msgs[i].src.mpf.mtime = 0;
result->msgs[i].src.mpf.size = 0;
break;
case DB_MSG_MBOX: case DB_MSG_MBOX:
{ {
unsigned int mbi, msgi; unsigned int mbi, msgi;
...@@ -725,6 +744,7 @@ static void scan_new_messages(struct database *db, int start_at)/*{{{*/ ...@@ -725,6 +744,7 @@ static void scan_new_messages(struct database *db, int start_at)/*{{{*/
switch (db->type[i]) { switch (db->type[i]) {
case MTY_DEAD: case MTY_DEAD:
case MTY_IMAP: /* Not yet implemented */
assert(0); assert(0);
break; break;
case MTY_MBOX: case MTY_MBOX:
...@@ -881,10 +901,10 @@ void maybe_grow_message_arrays(struct database *db)/*{{{*/ ...@@ -881,10 +901,10 @@ void maybe_grow_message_arrays(struct database *db)/*{{{*/
} }
} }
/*}}}*/ /*}}}*/
static void add_msg_path(struct database *db, char *path, time_t mtime, size_t message_size)/*{{{*/ static void add_msg_path(struct database *db, char *path, time_t mtime, size_t message_size, enum message_type type)/*{{{*/
{ {
maybe_grow_message_arrays(db); maybe_grow_message_arrays(db);
db->type[db->n_msgs] = MTY_FILE; db->type[db->n_msgs] = type;
db->msgs[db->n_msgs].src.mpf.path = new_string(path); db->msgs[db->n_msgs].src.mpf.path = new_string(path);
db->msgs[db->n_msgs].src.mpf.mtime = mtime; db->msgs[db->n_msgs].src.mpf.mtime = mtime;
db->msgs[db->n_msgs].src.mpf.size = message_size; db->msgs[db->n_msgs].src.mpf.size = message_size;
...@@ -896,6 +916,11 @@ static int do_stat(struct msgpath *mp)/*{{{*/ ...@@ -896,6 +916,11 @@ static int do_stat(struct msgpath *mp)/*{{{*/
{ {
struct stat sb; struct stat sb;
int status; int status;
if (mp->type == MTY_IMAP) {
mp->src.mpf.mtime = 0;
mp->src.mpf.size = 0;
return 1;
}
status = stat(mp->src.mpf.path, &sb); status = stat(mp->src.mpf.path, &sb);
if ((status < 0) || if ((status < 0) ||
!S_ISREG(sb.st_mode)) { !S_ISREG(sb.st_mode)) {
...@@ -957,6 +982,13 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg ...@@ -957,6 +982,13 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg
} }
} }
break; break;
case MTY_IMAP:
matched_index = lookup_msgpath(sorted_paths, n_msgs, db->msgs[i].src.mpf.path, MTY_IMAP);
if (matched_index >= 0) {
file_in_db[matched_index] = 1;
file_in_new_list[i] = 1;
}
break;
case MTY_MBOX: case MTY_MBOX:
/* Nothing to do on this pass. */ /* Nothing to do on this pass. */
break; break;
...@@ -972,6 +1004,7 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg ...@@ -972,6 +1004,7 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg
/* Weed dead entries */ /* Weed dead entries */
switch (db->type[i]) { switch (db->type[i]) {
case MTY_FILE: case MTY_FILE:
case MTY_IMAP:
if (!file_in_new_list[i]) { if (!file_in_new_list[i]) {
free(db->msgs[i].src.mpf.path); free(db->msgs[i].src.mpf.path);
db->msgs[i].src.mpf.path = NULL; db->msgs[i].src.mpf.path = NULL;
...@@ -1015,7 +1048,7 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg ...@@ -1015,7 +1048,7 @@ int update_database(struct database *db, struct msgpath *sorted_paths, int n_msg
if (status) { if (status) {
/* We only add files that could be successfully stat()'d as regular /* We only add files that could be successfully stat()'d as regular
* files. */ * files. */
add_msg_path(db, sorted_paths[i].src.mpf.path, sorted_paths[i].src.mpf.mtime, sorted_paths[i].src.mpf.size); add_msg_path(db, sorted_paths[i].src.mpf.path, sorted_paths[i].src.mpf.mtime, sorted_paths[i].src.mpf.size, sorted_paths[i].type);
} else { } else {
fprintf(stderr, "Cannot add '%s' to database; stat() failed\n", sorted_paths[i].src.mpf.path); fprintf(stderr, "Cannot add '%s' to database; stat() failed\n", sorted_paths[i].src.mpf.path);
} }
...@@ -1258,6 +1291,7 @@ int cull_dead_messages(struct database *db, int do_integrity_checks)/*{{{*/ ...@@ -1258,6 +1291,7 @@ int cull_dead_messages(struct database *db, int do_integrity_checks)/*{{{*/
switch (db->type[i]) { switch (db->type[i]) {
case MTY_FILE: case MTY_FILE:
case MTY_MBOX: case MTY_MBOX:
case MTY_IMAP:
new_idx[i] = j++; new_idx[i] = j++;
break; break;
case MTY_DEAD: case MTY_DEAD:
...@@ -1282,6 +1316,7 @@ int cull_dead_messages(struct database *db, int do_integrity_checks)/*{{{*/ ...@@ -1282,6 +1316,7 @@ int cull_dead_messages(struct database *db, int do_integrity_checks)/*{{{*/
break; break;
case MTY_FILE: case MTY_FILE:
case MTY_MBOX: case MTY_MBOX:
case MTY_IMAP:
if (i > j) { if (i > j) {
db->msgs[j] = db->msgs[i]; db->msgs[j] = db->msgs[i];
db->type[j] = db->type[i]; db->type[j] = db->type[i];
......
...@@ -47,6 +47,7 @@ void free_msgpath_array(struct msgpath_array *x)/*{{{*/ ...@@ -47,6 +47,7 @@ void free_msgpath_array(struct msgpath_array *x)/*{{{*/
for (i=0; i<x->n; i++) { for (i=0; i<x->n; i++) {
switch (x->paths[i].type) { switch (x->paths[i].type) {
case MTY_FILE: case MTY_FILE:
case MTY_IMAP:
free(x->paths[i].src.mpf.path); free(x->paths[i].src.mpf.path);
break; break;
case MTY_MBOX: case MTY_MBOX:
......
...@@ -99,6 +99,10 @@ void dump_database(char *filename) ...@@ -99,6 +99,10 @@ void dump_database(char *filename)
printf("FILE %s, size=%d, tid=%d", printf("FILE %s, size=%d, tid=%d",
db->data + db->path_offsets[i], db->size_table[i], db->tid_table[i]); db->data + db->path_offsets[i], db->size_table[i], db->tid_table[i]);
break; break;
case DB_MSG_IMAP:
printf("IMAP %s, tid=%d",
db->data + db->path_offsets[i], db->tid_table[i]);
break;
case DB_MSG_MBOX: case DB_MSG_MBOX:
{ {
unsigned int mbix, msgix; unsigned int mbix, msgix;
......
...@@ -296,13 +296,14 @@ static int compare_strings(const void *a, const void *b)/*{{{*/ ...@@ -296,13 +296,14 @@ static int compare_strings(const void *a, const void *b)/*{{{*/
static int check_message_list_for_duplicates(struct msgpath_array *msgs)/*{{{*/ static int check_message_list_for_duplicates(struct msgpath_array *msgs)/*{{{*/
{ {
/* Caveat : only examines the file-per-message case */ /* Caveat : only examines the file-per-message case */
char **sorted_paths; char **sorted_paths, **sorted_imap;
int i, n, nn; int i, n, nn, imap_nn;
int result; int result;
n = msgs->n; n = msgs->n;
sorted_paths = new_array(char *, n); sorted_paths = new_array(char *, n);
for (i=0, nn=0; i<n; i++) { sorted_imap = new_array(char *, n);
for (i=0, nn=0, imap_nn=0; i<n; i++) {
switch (msgs->paths[i].type) { switch (msgs->paths[i].type) {
case MTY_MBOX: case MTY_MBOX:
break; break;
...@@ -312,9 +313,13 @@ static int check_message_list_for_duplicates(struct msgpath_array *msgs)/*{{{*/ ...@@ -312,9 +313,13 @@ static int check_message_list_for_duplicates(struct msgpath_array *msgs)/*{{{*/
case MTY_FILE: case MTY_FILE:
sorted_paths[nn++] = msgs->paths[i].src.mpf.path; sorted_paths[nn++] = msgs->paths[i].src.mpf.path;
break; break;
case MTY_IMAP:
sorted_imap[imap_nn++] = msgs->paths[i].src.mpf.path;
break;
} }
} }
qsort(sorted_paths, nn, sizeof(char *), compare_strings); qsort(sorted_paths, nn, sizeof(char *), compare_strings);
qsort(sorted_imap, imap_nn, sizeof(char *), compare_strings);
result = 0; result = 0;
for (i=1; i<nn; i++) { for (i=1; i<nn; i++) {
...@@ -323,8 +328,15 @@ static int check_message_list_for_duplicates(struct msgpath_array *msgs)/*{{{*/ ...@@ -323,8 +328,15 @@ static int check_message_list_for_duplicates(struct msgpath_array *msgs)/*{{{*/
break; break;
} }
} }
for (i=1; i<imap_nn; i++) {
if (!strcmp(sorted_imap[i-1], sorted_imap[i])) {
result = 1;
break;
}
}
free(sorted_paths); free(sorted_paths);
free(sorted_imap);
return result; return result;
} }
/*}}}*/ /*}}}*/
......
...@@ -37,7 +37,8 @@ enum message_type {/*{{{*/ ...@@ -37,7 +37,8 @@ enum message_type {/*{{{*/
MTY_DEAD, /* msg no longer exists, i.e. don't report in searches, MTY_DEAD, /* msg no longer exists, i.e. don't report in searches,
prune it on a '-p' run. */ prune it on a '-p' run. */
MTY_FILE, /* msg <-> file in 1-1 correspondence e.g. maildir, MH */ MTY_FILE, /* msg <-> file in 1-1 correspondence e.g. maildir, MH */
MTY_MBOX /* multiple msgs per file : MBOX format file */ MTY_MBOX, /* multiple msgs per file : MBOX format file */
MTY_IMAP /* Message on IMAP server; syntax: uidvalidity:uid:folder */
}; };
/*}}}*/ /*}}}*/
......
...@@ -116,6 +116,8 @@ ...@@ -116,6 +116,8 @@
#define DB_MSG_FILE 1 #define DB_MSG_FILE 1
/* mbox : multiple files per message */ /* mbox : multiple files per message */
#define DB_MSG_MBOX 2 #define DB_MSG_MBOX 2
/* message comes from IMAP server */
#define DB_MSG_IMAP 3
/*}}}*/ /*}}}*/
#define FLAG_SEEN (1<<3) #define FLAG_SEEN (1<<3)
......
...@@ -179,6 +179,7 @@ static int char_length(struct database *db)/*{{{*/ ...@@ -179,6 +179,7 @@ static int char_length(struct database *db)/*{{{*/
case MTY_MBOX: case MTY_MBOX:
break; break;
case MTY_FILE: case MTY_FILE:
case MTY_IMAP:
assert(db->msgs[i].src.mpf.path); assert(db->msgs[i].src.mpf.path);
result += (1 + strlen(db->msgs[i].src.mpf.path)); result += (1 + strlen(db->msgs[i].src.mpf.path));
break; break;
...@@ -322,6 +323,9 @@ static char *write_type_and_flag_table(struct database *db, unsigned int *uidata ...@@ -322,6 +323,9 @@ static char *write_type_and_flag_table(struct database *db, unsigned int *uidata
case MTY_DEAD: case MTY_DEAD:
cdata[i] = DB_MSG_DEAD; cdata[i] = DB_MSG_DEAD;
break; break;
case MTY_IMAP:
cdata[i] = DB_MSG_IMAP;
break;
} }
if (msgdata->seen) cdata[i] |= FLAG_SEEN; if (msgdata->seen) cdata[i] |= FLAG_SEEN;
...@@ -350,6 +354,14 @@ static char *write_messages(struct database *db, struct write_map *map, unsigned ...@@ -350,6 +354,14 @@ static char *write_messages(struct database *db, struct write_map *map, unsigned
memcpy(cdata, db->msgs[i].src.mpf.path, 1 + slen); /* include trailing null */ memcpy(cdata, db->msgs[i].src.mpf.path, 1 + slen); /* include trailing null */
cdata += (1 + slen); cdata += (1 + slen);
break; break;
case MTY_IMAP:
slen = strlen(db->msgs[i].src.mpf.path);
uidata[map->path_offset + i] = cdata - data;
uidata[map->date_offset + i] = db->msgs[i].date;
uidata[map->tid_offset + i] = db->msgs[i].tid;
memcpy(cdata, db->msgs[i].src.mpf.path, 1 + slen); /* include trailing null */
cdata += (1 + slen);
break;
case MTY_MBOX: case MTY_MBOX:
{ {
int mbno = db->msgs[i].src.mbox.file_index; int mbno = db->msgs[i].src.mbox.file_index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment