Commit 6d67f461 authored by Richard P. Curnow's avatar Richard P. Curnow

Store attachment name information in the database

parent 52561790
......@@ -182,6 +182,8 @@ void check_database_integrity(struct database *db)/*{{{*/
check_toktable_enc_integrity(db->n_msgs, db->subject);
if (verbose) fprintf(stderr, "Checking body\n");
check_toktable_enc_integrity(db->n_msgs, db->body);
if (verbose) fprintf(stderr, "Checking attachment_name\n");
check_toktable_enc_integrity(db->n_msgs, db->attachment_name);
}
/*}}}*/
struct database *new_database(void)/*{{{*/
......@@ -195,6 +197,7 @@ struct database *new_database(void)/*{{{*/
result->from = new_toktable();
result->subject = new_toktable();
result->body = new_toktable();
result->attachment_name = new_toktable();
result->msg_ids = new_toktable2();
......@@ -223,6 +226,7 @@ void free_database(struct database *db)/*{{{*/
free_toktable(db->from);
free_toktable(db->subject);
free_toktable(db->body);
free_toktable(db->attachment_name);
free_toktable2(db->msg_ids);
if (db->msgs) {
......@@ -489,6 +493,7 @@ struct database *new_database_from_file(char *db_filename, int do_integrity_chec
import_toktable(input->data, input->hash_key, result->n_msgs, &input->from, result->from);
import_toktable(input->data, input->hash_key, result->n_msgs, &input->subject, result->subject);
import_toktable(input->data, input->hash_key, result->n_msgs, &input->body, result->body);
import_toktable(input->data, input->hash_key, result->n_msgs, &input->attachment_name, result->body);
import_toktable2(input->data, input->hash_key, result->n_msgs, &input->msg_ids, result->msg_ids);
close_db(input);
......@@ -663,6 +668,10 @@ void tokenise_message(int file_index, struct database *db, struct rfc822 *msg)/*
break;
}
if (a->filename) {
add_token_in_file(file_index, db->hash_key, a->filename, db->attachment_name);
}
}
/* Deal with threading information */
......@@ -1180,6 +1189,7 @@ int cull_dead_messages(struct database *db, int do_integrity_checks)/*{{{*/
recode_toktable(db->from, new_idx);
recode_toktable(db->subject, new_idx);
recode_toktable(db->body, new_idx);
recode_toktable(db->attachment_name, new_idx);
recode_toktable2(db->msg_ids, new_idx);
/* And crunch down the filename table */
......
......@@ -122,6 +122,8 @@ void dump_database(char *filename)
printf("--------------------------------\n");
dump_toktable(db, &db->body, "Body");
printf("--------------------------------\n");
dump_toktable(db, &db->attachment_name, "Attachment names");
printf("--------------------------------\n");
close_db(db);
return;
......
......@@ -221,6 +221,7 @@ struct database {/*{{{*/
struct toktable *from;
struct toktable *subject;
struct toktable *body;
struct toktable *attachment_name;
/* Encoding chain 0 stores all msgids appearing in the following message headers:
* Message-Id, In-Reply-To, References. Used for thread reconciliation.
......
......@@ -175,6 +175,7 @@ struct read_db *open_db(char *filename)/*{{{*/
read_toktable_db(data, &result->from, UI_FROM_BASE, uidata);
read_toktable_db(data, &result->subject, UI_SUBJECT_BASE, uidata);
read_toktable_db(data, &result->body, UI_BODY_BASE, uidata);
read_toktable_db(data, &result->attachment_name, UI_ATTACHMENT_NAME_BASE, uidata);
read_toktable2_db(data, &result->msg_ids, UI_MSGID_BASE, uidata);
return result;
......@@ -197,6 +198,7 @@ void close_db(struct read_db *x)/*{{{*/
free_toktable_db(&x->from);
free_toktable_db(&x->subject);
free_toktable_db(&x->body);
free_toktable_db(&x->attachment_name);
free_toktable2_db(&x->msg_ids);
if (munmap(x->data, x->len) < 0) {
......
......@@ -27,7 +27,7 @@
#define HEADER_MAGIC0 'M'
#define HEADER_MAGIC1 'X'
#define HEADER_MAGIC2 0xA5
#define HEADER_MAGIC3 0x02
#define HEADER_MAGIC3 0x03
/*{{{ Constants for file data positions */
#define UI_ENDIAN 1
......@@ -74,7 +74,8 @@
#define UI_FROM_BASE 22
#define UI_SUBJECT_BASE 25
#define UI_BODY_BASE 28
#define UI_MSGID_BASE 31
#define UI_ATTACHMENT_NAME_BASE 31
#define UI_MSGID_BASE 34
/* Larger than the last table offset. */
#define UI_HEADER_LEN 40
......@@ -99,6 +100,9 @@
#define UI_BODY_N (UI_BODY_BASE + UI_N_OFFSET)
#define UI_BODY_TOK (UI_BODY_BASE + UI_TOK_OFFSET)
#define UI_BODY_ENC (UI_BODY_BASE + UI_ENC_OFFSET)
#define UI_ATTACHMENT_NAME_N (UI_ATTACHMENT_NAME_BASE + UI_N_OFFSET)
#define UI_ATTACHMENT_NAME_TOK (UI_ATTACHMENT_NAME_BASE + UI_TOK_OFFSET)
#define UI_ATTACHMENT_NAME_ENC (UI_ATTACHMENT_NAME_BASE + UI_ENC_OFFSET)
#define UI_MSGID_N (UI_MSGID_BASE + UI_N_OFFSET)
#define UI_MSGID_TOK (UI_MSGID_BASE + UI_TOK_OFFSET)
#define UI_MSGID_ENC0 (UI_MSGID_BASE + UI_ENC_OFFSET)
......@@ -155,6 +159,7 @@ struct read_db {/*{{{*/
struct toktable_db from;
struct toktable_db subject;
struct toktable_db body;
struct toktable_db attachment_name;
struct toktable2_db msg_ids;
};
......
......@@ -664,13 +664,21 @@ static void do_body(struct msg_src *src,
struct attachment *new_att;
const char *disposition;
new_att = new(struct attachment);
disposition = nvp_first(cd_nvp);
disposition = cd_nvp ? nvp_first(cd_nvp) : NULL;
if (disposition && !strcasecmp(disposition, "attachment")) {
new_att->filename = new_string(nvp_lookupcase(cd_nvp, "filename"));
if (!new_att->filename) {
const char *lookup;
lookup = nvp_lookupcase(cd_nvp, "filename");
if (lookup) {
new_att->filename = new_string(lookup);
} else {
/* Some messages have name=... in content-type: instead of
* filename=... in content-disposition. */
new_att->filename = new_string(nvp_lookupcase(ct_nvp, "name"));
lookup = nvp_lookup(ct_nvp, "name");
if (lookup) {
new_att->filename = new_string(lookup);
} else {
new_att->filename = NULL;
}
}
} else {
new_att->filename = NULL;
......
......@@ -78,6 +78,7 @@ struct write_map {/*{{{*/
struct write_map_toktable from;
struct write_map_toktable subject;
struct write_map_toktable body;
struct write_map_toktable attachment_name;
struct write_map_toktable2 msg_ids;
/* To get base address for character data */
......@@ -197,6 +198,7 @@ static int char_length(struct database *db)/*{{{*/
result += toktable_char_length(db->from);
result += toktable_char_length(db->subject);
result += toktable_char_length(db->body);
result += toktable_char_length(db->attachment_name);
result += toktable2_char_length(db->msg_ids);
return result;
......@@ -234,6 +236,9 @@ static void compute_mapping(struct database *db, struct write_map *map)/*{{{*/
map->body.tok_offset = total, total += db->body->n;
map->body.enc_offset = total, total += db->body->n;
map->attachment_name.tok_offset = total, total += db->attachment_name->n;
map->attachment_name.enc_offset = total, total += db->attachment_name->n;
map->msg_ids.tok_offset = total, total += db->msg_ids->n;
map->msg_ids.enc0_offset = total, total += db->msg_ids->n;
map->msg_ids.enc1_offset = total, total += db->msg_ids->n;
......@@ -290,6 +295,10 @@ static void write_header(char *data, unsigned int *uidata, struct database *db,
uidata[UI_BODY_TOK] = map->body.tok_offset;
uidata[UI_BODY_ENC] = map->body.enc_offset;
uidata[UI_ATTACHMENT_NAME_N] = db->attachment_name->n;
uidata[UI_ATTACHMENT_NAME_TOK] = map->attachment_name.tok_offset;
uidata[UI_ATTACHMENT_NAME_ENC] = map->attachment_name.enc_offset;
uidata[UI_MSGID_N] = db->msg_ids->n;
uidata[UI_MSGID_TOK] = map->msg_ids.tok_offset;
uidata[UI_MSGID_ENC0] = map->msg_ids.enc0_offset;
......@@ -579,6 +588,7 @@ void write_database(struct database *db, char *filename, int do_integrity_checks
cdata = write_toktable(db->from, &map.from, uidata, data, cdata, "From");
cdata = write_toktable(db->subject, &map.subject, uidata, data, cdata, "Subject");
cdata = write_toktable(db->body, &map.body, uidata, data, cdata, "Body");
cdata = write_toktable(db->attachment_name, &map.attachment_name, uidata, data, cdata, "Attachment Name");
cdata = write_toktable2(db->msg_ids, &map.msg_ids, uidata, data, cdata, "(Threading)");
/* Write data */
......
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