dumper.c 4.62 KB
Newer Older
1 2 3 4
/*
  mairix - message index builder and finder for maildir folders.

 **********************************************************************
5
 * Copyright (C) Richard P. Curnow  2004, 2005
Richard P. Curnow's avatar
Richard P. Curnow committed
6
 *
7 8 9
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
Richard P. Curnow's avatar
Richard P. Curnow committed
10
 *
11 12 13 14
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
Richard P. Curnow's avatar
Richard P. Curnow committed
15
 *
16 17
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
18
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Richard P. Curnow's avatar
Richard P. Curnow committed
19
 *
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
 **********************************************************************
 */

/* Database dumper */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <sys/mman.h>

36
#include "mairix.h"
37 38 39
#include "reader.h"
#include "memmac.h"

Richard P. Curnow's avatar
Richard P. Curnow committed
40
static void dump_token_chain(struct read_db *db, unsigned int n, unsigned int *tok_offsets, unsigned int *enc_offsets)
41
{
Richard P. Curnow's avatar
Richard P. Curnow committed
42
  int i, j, incr;
Richard Curnow's avatar
Richard Curnow committed
43
  int on_line;
44 45 46
  unsigned char *foo;
  printf("%d entries\n", n);
  for (i=0; i<n; i++) {
Richard P. Curnow's avatar
Richard P. Curnow committed
47 48
    printf("Word %d : <%s>\n", i, db->data + tok_offsets[i]);
    foo = (unsigned char *) db->data + enc_offsets[i];
49
    j = 0;
Richard Curnow's avatar
Richard Curnow committed
50
    on_line = 0;
51 52
    printf("  ");
    while (*foo != 0xff) {
Richard Curnow's avatar
Richard Curnow committed
53 54 55 56
      if (on_line > 15) {
        printf("\n");
        on_line = 0;
      }
57 58 59
      incr = read_increment(&foo);
      j += incr;
      printf("%d ", j);
Richard Curnow's avatar
Richard Curnow committed
60
      on_line++;
61 62 63 64 65
    }
    printf("\n");
  }
}

Richard P. Curnow's avatar
Richard P. Curnow committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
static void dump_toktable(struct read_db *db, struct toktable_db *tbl, const char *title)
{
  printf("Contents of <%s> table\n", title);
  dump_token_chain( db, tbl->n, tbl->tok_offsets, tbl->enc_offsets);
}

static void dump_toktable2(struct read_db *db, struct toktable2_db *tbl, const char *title)
{
  unsigned int n;
  n = tbl->n;
  printf("Contents of <%s> table\n", title);
  printf("Chain 0\n");
  dump_token_chain( db, n, tbl->tok_offsets, tbl->enc0_offsets);
  printf("Chain 1\n");
  dump_token_chain( db, n, tbl->tok_offsets, tbl->enc1_offsets);
}

83 84 85 86
void dump_database(char *filename)
{
  struct read_db *db;
  int i;
Richard P. Curnow's avatar
Richard P. Curnow committed
87

88 89 90 91 92 93
  db = open_db(filename);

  printf("Dump of %s\n", filename);
  printf("%d messages\n", db->n_msgs);
  for (i=0; i<db->n_msgs; i++) {
    printf("%6d: ", i);
94
    switch (rd_msg_type(db, i)) {
95 96 97 98
      case DB_MSG_DEAD:
        printf("DEAD");
        break;
      case DB_MSG_FILE:
Richard P. Curnow's avatar
Richard P. Curnow committed
99
        printf("FILE %s, size=%d, tid=%d",
100 101
               db->data + db->path_offsets[i], db->size_table[i], db->tid_table[i]);
        break;
102 103 104 105
      case DB_MSG_IMAP:
        printf("IMAP %s, tid=%d",
               db->data + db->path_offsets[i], db->tid_table[i]);
        break;
106 107
      case DB_MSG_MBOX:
        {
108
          unsigned int mbix, msgix;
109 110 111 112 113 114 115
          decode_mbox_indices(db->path_offsets[i], &mbix, &msgix);

          printf("MBOX %d, msg %d, offset=%d, size=%d, tid=%d",
                 mbix, msgix, db->mtime_table[i], db->size_table[i], db->tid_table[i]);
        }
        break;
    }
116 117 118
    if (db->msg_type_and_flags[i] & FLAG_SEEN) printf(" seen");
    if (db->msg_type_and_flags[i] & FLAG_REPLIED) printf(" replied");
    if (db->msg_type_and_flags[i] & FLAG_FLAGGED) printf(" flagged");
119 120 121 122 123 124 125
    printf("\n");
  }
  printf("\n");
  if (db->n_mboxen > 0) {
    printf("\nMBOX INFORMATION\n");
    printf("%d mboxen\n", db->n_mboxen);
    for (i=0; i<db->n_mboxen; i++) {
Richard Curnow's avatar
Richard Curnow committed
126 127 128 129 130
      if (db->mbox_paths_table[i]) {
        printf("%4d: %d msgs in %s\n", i, db->mbox_entries_table[i], db->data + db->mbox_paths_table[i]);
      } else {
        printf("%4d: dead\n", i);
      }
131 132 133 134
    }
    printf("\n");
  }

135
  printf("Hash key %08x\n\n", db->hash_key);
136 137 138
  printf("--------------------------------\n");
  dump_toktable(db, &db->to, "To");
  printf("--------------------------------\n");
139
  dump_toktable(db, &db->cc, "Cc");
140 141 142 143 144 145 146
  printf("--------------------------------\n");
  dump_toktable(db, &db->from, "From");
  printf("--------------------------------\n");
  dump_toktable(db, &db->subject, "Subject");
  printf("--------------------------------\n");
  dump_toktable(db, &db->body, "Body");
  printf("--------------------------------\n");
147 148
  dump_toktable(db, &db->attachment_name, "Attachment names");
  printf("--------------------------------\n");
Richard P. Curnow's avatar
Richard P. Curnow committed
149 150
  dump_toktable2(db, &db->msg_ids, "Message Ids");
  printf("--------------------------------\n");
151 152 153 154 155

  close_db(db);
  return;
}