00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "define.h"
00010
00011 struct file_ll {
00012 char *dname;
00013 int32_t stored_count;
00014 int32_t item_count;
00015 int32_t skip_count;
00016 int32_t type;
00017 };
00018
00019
00020 void canonicalize_filename(char *fname);
00021 void debug_print(char *fmt, ...);
00022 void usage(char *prog_name);
00023 void version();
00024
00025
00026 pst_file pstfile;
00027
00028
00029 void create_enter_dir(struct file_ll* f, pst_item *item)
00030 {
00031 pst_convert_utf8(item, &item->file_as);
00032 f->item_count = 0;
00033 f->skip_count = 0;
00034 f->type = item->type;
00035 f->stored_count = (item->folder) ? item->folder->item_count : 0;
00036 f->dname = strdup(item->file_as.str);
00037 }
00038
00039
00040 void close_enter_dir(struct file_ll *f)
00041 {
00042 free(f->dname);
00043 }
00044
00045
00046 void process(pst_item *outeritem, pst_desc_tree *d_ptr)
00047 {
00048 struct file_ll ff;
00049 pst_item *item = NULL;
00050 char *result = NULL;
00051 size_t resultlen = 0;
00052
00053 DEBUG_ENT("process");
00054 memset(&ff, 0, sizeof(ff));
00055 create_enter_dir(&ff, outeritem);
00056
00057 while (d_ptr) {
00058 if (!d_ptr->desc) {
00059 DEBUG_WARN(("ERROR item's desc record is NULL\n"));
00060 ff.skip_count++;
00061 }
00062 else {
00063 DEBUG_INFO(("Desc Email ID %"PRIx64" [d_ptr->d_id = %"PRIx64"]\n", d_ptr->desc->i_id, d_ptr->d_id));
00064
00065 item = pst_parse_item(&pstfile, d_ptr, NULL);
00066 DEBUG_INFO(("About to process item @ %p.\n", item));
00067 if (item) {
00068 if (item->message_store) {
00069
00070 DIE(("A second message_store has been found. Sorry, this must be an error.\n"));
00071 }
00072
00073 if (item->folder && d_ptr->child) {
00074
00075 pst_convert_utf8(item, &item->file_as);
00076 printf("Folder \"%s\"\n", item->file_as.str);
00077 process(item, d_ptr->child);
00078
00079 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
00080 if (!ff.type) ff.type = item->type;
00081
00082 if (ff.type != PST_TYPE_CONTACT) {
00083 DEBUG_INFO(("I have a contact, but the folder isn't a contacts folder. Processing anyway\n"));
00084 }
00085 printf("Contact");
00086 if (item->contact->fullname.str)
00087 printf("\t%s", pst_rfc2426_escape(item->contact->fullname.str, &result, &resultlen));
00088 printf("\n");
00089
00090 } else if (item->email && ((item->type == PST_TYPE_NOTE) || (item->type == PST_TYPE_SCHEDULE) || (item->type == PST_TYPE_REPORT))) {
00091 if (!ff.type) ff.type = item->type;
00092
00093 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) {
00094 DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n"));
00095 }
00096 printf("Email");
00097 if (item->email->outlook_sender_name.str)
00098 printf("\tFrom: %s", item->email->outlook_sender_name.str);
00099 if (item->subject.str)
00100 printf("\tSubject: %s", item->subject.str);
00101 printf("\n");
00102
00103 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
00104 if (!ff.type) ff.type = item->type;
00105
00106 if (ff.type != PST_TYPE_JOURNAL) {
00107 DEBUG_INFO(("I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
00108 }
00109 if (item->subject.str)
00110 printf("Journal\t%s\n", pst_rfc2426_escape(item->subject.str, &result, &resultlen));
00111
00112 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) {
00113 char time_buffer[30];
00114 if (!ff.type) ff.type = item->type;
00115
00116 DEBUG_INFO(("Processing Appointment Entry\n"));
00117 if (ff.type != PST_TYPE_APPOINTMENT) {
00118 DEBUG_INFO(("I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
00119 }
00120 printf("Appointment");
00121 if (item->subject.str)
00122 printf("\tSUMMARY: %s", pst_rfc2426_escape(item->subject.str, &result, &resultlen));
00123 if (item->appointment->start)
00124 printf("\tSTART: %s", pst_rfc2445_datetime_format(item->appointment->start, sizeof(time_buffer), time_buffer));
00125 if (item->appointment->end)
00126 printf("\tEND: %s", pst_rfc2445_datetime_format(item->appointment->end, sizeof(time_buffer), time_buffer));
00127 printf("\tALL DAY: %s", (item->appointment->all_day==1 ? "Yes" : "No"));
00128 printf("\n");
00129
00130 } else {
00131 ff.skip_count++;
00132 DEBUG_INFO(("Unknown item type. %i. Ascii1=\"%s\"\n",
00133 item->type, item->ascii_type));
00134 }
00135 pst_freeItem(item);
00136 } else {
00137 ff.skip_count++;
00138 DEBUG_INFO(("A NULL item was seen\n"));
00139 }
00140 d_ptr = d_ptr->next;
00141 }
00142 }
00143 close_enter_dir(&ff);
00144 if (result) free(result);
00145 DEBUG_RET();
00146 }
00147
00148
00149 void usage(char *prog_name) {
00150 DEBUG_ENT("usage");
00151 version();
00152 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
00153 printf("OPTIONS:\n");
00154 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n");
00155 printf("\t-h\t- Help. This screen\n");
00156 printf("\t-V\t- Version. Display program version\n");
00157 DEBUG_RET();
00158 }
00159
00160
00161 void version() {
00162 DEBUG_ENT("version");
00163 printf("lspst / LibPST v%s\n", VERSION);
00164 #if BYTE_ORDER == BIG_ENDIAN
00165 printf("Big Endian implementation being used.\n");
00166 #elif BYTE_ORDER == LITTLE_ENDIAN
00167 printf("Little Endian implementation being used.\n");
00168 #else
00169 # error "Byte order not supported by this library"
00170 #endif
00171 #ifdef __GNUC__
00172 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
00173 #endif
00174 DEBUG_RET();
00175 }
00176
00177
00178 int main(int argc, char* const* argv) {
00179 pst_item *item = NULL;
00180 pst_desc_tree *d_ptr;
00181 char *temp = NULL;
00182 int c;
00183 char *d_log = NULL;
00184
00185 while ((c = getopt(argc, argv, "d:hV"))!= -1) {
00186 switch (c) {
00187 case 'd':
00188 d_log = optarg;
00189 break;
00190 case 'h':
00191 usage(argv[0]);
00192 exit(0);
00193 break;
00194 case 'V':
00195 version();
00196 exit(0);
00197 break;
00198 default:
00199 usage(argv[0]);
00200 exit(1);
00201 break;
00202 }
00203 }
00204
00205 #ifdef DEBUG_ALL
00206
00207 if (!d_log) d_log = "lspst.log";
00208 #endif // defined DEBUG_ALL
00209 DEBUG_INIT(d_log, NULL);
00210 DEBUG_ENT("main");
00211
00212 if (argc <= optind) {
00213 usage(argv[0]);
00214 exit(2);
00215 }
00216
00217
00218 if (pst_open(&pstfile, argv[optind])) DIE(("Error opening File\n"));
00219
00220
00221 if (pst_load_index(&pstfile)) DIE(("Index Error\n"));
00222
00223 pst_load_extended_attributes(&pstfile);
00224
00225 d_ptr = pstfile.d_head;
00226 item = pst_parse_item(&pstfile, d_ptr, NULL);
00227 if (!item || !item->message_store) {
00228 DEBUG_RET();
00229 DIE(("Could not get root record\n"));
00230 }
00231
00232
00233 if (!item->file_as.str) {
00234 if (!(temp = strrchr(argv[1], '/')))
00235 if (!(temp = strrchr(argv[1], '\\')))
00236 temp = argv[1];
00237 else
00238 temp++;
00239 else
00240 temp++;
00241 item->file_as.str = strdup(temp);
00242 item->file_as.is_utf8 = 1;
00243 }
00244
00245 d_ptr = pst_getTopOfFolders(&pstfile, item);
00246 if (!d_ptr) DIE(("Top of folders record not found. Cannot continue\n"));
00247
00248 process(item, d_ptr->child);
00249 pst_freeItem(item);
00250 pst_close(&pstfile);
00251
00252 DEBUG_RET();
00253 return 0;
00254 }
00255
00256
00257
00258
00259 void canonicalize_filename(char *fname) {
00260 DEBUG_ENT("canonicalize_filename");
00261 if (fname == NULL) {
00262 DEBUG_RET();
00263 return;
00264 }
00265 while ((fname = strpbrk(fname, "/\\:")))
00266 *fname = '_';
00267 DEBUG_RET();
00268 }
00269
00270