00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include <string>
00012 #include <vector>
00013
00014 using namespace std;
00015
00016 extern "C" {
00017 #include "define.h"
00018 #include "lzfu.h"
00019 }
00020
00021 struct file_ll {
00022 string name;
00023 int32_t stored_count;
00024 int32_t email_count;
00025 int32_t skip_count;
00026 int32_t type;
00027 file_ll() {
00028 stored_count = 0;
00029 email_count = 0;
00030 skip_count = 0;
00031 type = 0;
00032 };
00033 };
00034
00035
00036 const char* convert = "/usr/bin/convert";
00037 const char* prog_name = NULL;
00038 const char* bates_prefix = "";
00039 int bates_index = 0;
00040 const char* output_directory = ".";
00041 const char* output_file = "load.dii";
00042 char* font_file = NULL;
00043 int bates_color = 0xff0000;
00044 int email_sequence = 0;
00045 char pdf_name[PATH_MAX];
00046 FILE* dii_file = NULL;
00047 pst_file pstfile;
00048
00049
00050 bool pdf_open = false;
00051 char* pst_folder;
00052 int page_sequence;
00053 string conversion;
00054 vector<string> png_names;
00055
00056
00057 bool png_open = false;
00058 int line_height;
00059 int char_width;
00060 int col_number, col_max;
00061 int line_number, line_max;
00062 int x_position, y_position;
00063 int black, red;
00064 gdImagePtr image;
00065
00066 const int DPI = 300;
00067 const double sz = 10.0;
00068 const int margin = DPI/2;
00069 const int LINE_SIZE = 2000;
00070 const int PAGE_WIDTH = DPI*17/2;
00071 const int PAGE_HEIGHT = DPI*11;
00072
00073
00074 #define C_TIME_SIZE 500
00075
00076 static void open_png();
00077 static void close_png();
00078
00079
00080 static void version();
00081 static void version()
00082 {
00083 printf("pst2dii v%s\n", VERSION);
00084 #if BYTE_ORDER == BIG_ENDIAN
00085 printf("Big Endian implementation being used.\n");
00086 #elif BYTE_ORDER == LITTLE_ENDIAN
00087 printf("Little Endian implementation being used.\n");
00088 #else
00089 # error "Byte order not supported by this library"
00090 #endif
00091 #ifdef __GNUC__
00092 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
00093 #endif
00094 }
00095
00096
00097 static void usage();
00098 static void usage()
00099 {
00100 version();
00101 printf("Usage: %s -f ttf-font-file [OPTIONS] {PST FILENAME}\n", prog_name);
00102 printf("\t-f ttf-font-file \t- Set the font file\n");
00103 printf("OPTIONS:\n");
00104 printf("\t-B bates-prefix \t- Set the bates prefix string\n");
00105 printf("\t-O dii-output-file\t- Set the dii load file output filename\n");
00106 printf("\t-V \t- Version. Display program version\n");
00107 printf("\t-b bates-number \t- Set the starting bates sequence number\n");
00108 printf("\t-c bates-color \t- Specify the color of the bates stamps as 6 digit hex\n");
00109 printf("\t-d filename \t- Debug to file.\n");
00110 printf("\t-h \t- Help. This screen\n");
00111 printf("\t-o dirname \t- Output directory to write files to.\n");
00112 }
00113
00114
00115 static char *removeCR (char *c);
00116 static char *removeCR (char *c) {
00117
00118 char *a, *b;
00119 DEBUG_ENT("removeCR");
00120 a = b = c;
00121 while (*a != '\0') {
00122 *b = *a;
00123 if (*a != '\r')
00124 b++;
00125 a++;
00126 }
00127 *b = '\0';
00128 DEBUG_RET();
00129 return c;
00130 }
00131
00132
00133
00134
00135
00136 static char *skip_header_prologue(char *headers);
00137 static char *skip_header_prologue(char *headers) {
00138 const char *bad = "Microsoft Mail Internet Headers";
00139 if (strncmp(headers, bad, strlen(bad)) == 0) {
00140
00141 char *pc = strchr(headers, '\n');
00142 return pc + 1;
00143 }
00144 return headers;
00145 }
00146
00147
00148 static void check_filename(string &fname);
00149 static void check_filename(string &fname) {
00150 char *t = strdup(fname.c_str());
00151 DEBUG_ENT("check_filename");
00152 if (!t) {
00153 DEBUG_RET();
00154 return;
00155 }
00156 char *tt = t;
00157 bool fixed = false;
00158 while ((t = strpbrk(t, " /\\:"))) {
00159
00160 *t = '_';
00161 fixed = true;
00162 }
00163 if (fixed) fname = string(tt);
00164 free(tt);
00165 DEBUG_RET();
00166 }
00167
00168
00169 static string write_separate_attachment(string fname, pst_item_attach* current_attach, int attach_num, pst_file* pst);
00170 static string write_separate_attachment(string fname, pst_item_attach* current_attach, int attach_num, pst_file* pst)
00171 {
00172 FILE *fp = NULL;
00173 int x = 0;
00174 char *temp = NULL;
00175
00176
00177
00178 char *attach_filename = (current_attach->filename2.str) ? current_attach->filename2.str
00179 : current_attach->filename1.str;
00180 DEBUG_ENT("write_separate_attachment");
00181 check_filename(fname);
00182 const char* f_name = fname.c_str();
00183 DEBUG_INFO(("dirname=%s, pathname=%s, filename=%s\n", output_directory, f_name, attach_filename));
00184 int len = strlen(output_directory) + 1 + strlen(f_name) + 15;
00185 if (!attach_filename) {
00186
00187 temp = (char*)pst_malloc(len);
00188 sprintf(temp, "%s/%s_attach%i", output_directory, f_name, attach_num);
00189 } else {
00190
00191 temp = (char*)pst_malloc(len+strlen(attach_filename));
00192 do {
00193 if (fp) fclose(fp);
00194 if (x == 0)
00195 sprintf(temp, "%s/%s_%s", output_directory, f_name, attach_filename);
00196 else
00197 sprintf(temp, "%s/%s_%s-%i", output_directory, f_name, attach_filename, x);
00198 } while ((fp = fopen(temp, "r")) && ++x < 99999999);
00199 if (x > 99999999) {
00200 DIE(("error finding attachment name. exhausted possibilities to %s\n", temp));
00201 }
00202 }
00203 DEBUG_INFO(("Saving attachment to %s\n", temp));
00204 if (!(fp = fopen(temp, "wb"))) {
00205 DEBUG_WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
00206 } else {
00207 (void)pst_attach_to_file(pst, current_attach, fp);
00208 fclose(fp);
00209 }
00210 string rc(temp);
00211 if (temp) free(temp);
00212 DEBUG_RET();
00213 return rc;
00214 }
00215
00216
00217 static void print_pdf_short(const char *line, int len, int color);
00218 static void print_pdf_short(const char *line, int len, int color)
00219 {
00220 if (line_number >= line_max) {
00221 close_png();
00222 open_png();
00223 }
00224 int brect[8];
00225 gdFTStringExtra strex;
00226 strex.flags = gdFTEX_RESOLUTION;
00227 strex.linespacing = 1.20;
00228 strex.charmap = 0;
00229 strex.hdpi = DPI;
00230 strex.vdpi = DPI;
00231 char xline[len+1];
00232 memcpy(xline, line, len);
00233 xline[len] = '\0';
00234 char *p;
00235 char *l = xline;
00236 while ((p = strchr(l, '&'))) {
00237 *p = '\0';
00238 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex);
00239 if (err) printf("%s", err);
00240 x_position += (brect[2]-brect[6]);
00241 l = p+1;
00242 err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, (char*)"&", &strex);
00243 if (err) printf("%s", err);
00244 x_position += (brect[2]-brect[6]);
00245 }
00246 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex);
00247 if (err) printf("%s", err);
00248 x_position += (brect[2]-brect[6]);
00249 col_number += len;
00250 }
00251
00252
00253 static void new_line();
00254 static void new_line()
00255 {
00256 y_position += line_height;
00257 line_number += 1;
00258 x_position = margin;
00259 col_number = 0;
00260 }
00261
00262
00263 static void print_pdf_single(const char *line, int color);
00264 static void print_pdf_single(const char *line, int color)
00265 {
00266 while (*line == '\t') {
00267 char blanks[5];
00268 memset(blanks, ' ', 5);
00269 print_pdf_short(blanks, 4, color);
00270 line++;
00271 if (col_number >= col_max) new_line();
00272 }
00273 int n = strlen(line);
00274 while (n) {
00275 int m = col_max - col_number;
00276 m = (n > m) ? m : n;
00277 print_pdf_short(line, m, color);
00278 line += m;
00279 n -= m;
00280 if (n) new_line();
00281 }
00282 }
00283
00284
00285 static void print_pdf_only(char *line, int color);
00286 static void print_pdf_only(char *line, int color)
00287 {
00288 char *p;
00289 while ((p = strchr(line, '\n'))) {
00290 *p = '\0';
00291 print_pdf_single(line, color);
00292 *p = '\n';
00293 line = p+1;
00294 new_line();
00295 }
00296 print_pdf_single(line, color);
00297 }
00298
00299
00300 static void print_pdf(char *line);
00301 static void print_pdf(char *line)
00302 {
00303 pst_fwrite(line, 1, strlen(line), dii_file);
00304 print_pdf_only(line, black);
00305 }
00306
00307
00308 static void open_png()
00309 {
00310 if (!png_open) {
00311 png_open = true;
00312 int brect[8];
00313 image = gdImageCreate(PAGE_WIDTH, PAGE_HEIGHT);
00314 gdImageColorAllocate(image, 255, 255, 255);
00315 black = gdImageColorAllocate(image, 0, 0, 0);
00316 int r = (bates_color & 0xff0000) >> 16;
00317 int g = (bates_color & 0x00ff00) >> 8;
00318 int b = (bates_color & 0x0000ff);
00319 red = gdImageColorAllocate(image, r, g, b);
00320
00321 gdFTStringExtra strex;
00322 strex.flags = gdFTEX_RESOLUTION;
00323 strex.linespacing = 1.20;
00324 strex.charmap = 0;
00325 strex.hdpi = DPI;
00326 strex.vdpi = DPI;
00327
00328 char line[LINE_SIZE];
00329 char *err = gdImageStringFTEx(NULL, &brect[0], black, font_file, sz, 0.0, margin, margin, (char*)"LMgqQ", &strex);
00330 if (err) printf("%s", err);
00331 line_height = (brect[3]-brect[7]) * 12/10;
00332 char_width = (brect[2]-brect[6]) / 5;
00333 col_number = 0;
00334 col_max = (PAGE_WIDTH - margin*2) / char_width;
00335 line_number = 0;
00336 line_max = (PAGE_HEIGHT - margin*2) / line_height;
00337 x_position = margin;
00338 y_position = margin + line_height;
00339 snprintf(line, sizeof(line), "%s%06d\n", bates_prefix, bates_index++);
00340 print_pdf_only(line, red);
00341 print_pdf_only(pst_folder, red);
00342 }
00343 }
00344
00345
00346 static void close_png()
00347 {
00348 if (png_open) {
00349 png_open = false;
00350 char fn[PATH_MAX];
00351 snprintf(fn, sizeof(fn), "page%d.png", ++page_sequence);
00352 FILE *pngout = fopen(fn, "wb");
00353 if (pngout) {
00354 gdImagePng(image, pngout);
00355 fclose(pngout);
00356 }
00357 gdImageDestroy(image);
00358 png_names.push_back(fn);
00359 conversion += string(" ") + fn;
00360 }
00361 }
00362
00363
00364 static void open_pdf(char *line);
00365 static void open_pdf(char *line)
00366 {
00367 pst_folder = line;
00368 page_sequence = 0;
00369 conversion = string(convert);
00370 png_names.clear();
00371 open_png();
00372 snprintf(pdf_name, sizeof(pdf_name), "dii%06d", ++email_sequence);
00373 fprintf(dii_file, "\n@T %s\n", pdf_name);
00374 snprintf(pdf_name, sizeof(pdf_name), "%s/dii%06d.pdf", output_directory, email_sequence);
00375 }
00376
00377
00378 static void close_pdf();
00379 static void close_pdf()
00380 {
00381 close_png();
00382 conversion += string(" ") + pdf_name;
00383 (void)system(conversion.c_str());
00384 for (vector<string>::iterator i=png_names.begin(); i!=png_names.end(); i++) {
00385 remove((*i).c_str());
00386 }
00387 fprintf(dii_file, "@D %s\n", pdf_name);
00388 }
00389
00390
00391 static void write_simple(const char *tag, const char *value);
00392 static void write_simple(const char *tag, const char *value)
00393 {
00394 if (value) fprintf(dii_file, "@%s %s\n", tag, value);
00395 }
00396
00397
00398 static void write_simple(const char *tag, string value);
00399 static void write_simple(const char *tag, string value)
00400 {
00401 fprintf(dii_file, "@%s %s\n", tag, value.c_str());
00402 }
00403
00404
00405 static void write_simple(const char *tag, const char *value, const char *value2);
00406 static void write_simple(const char *tag, const char *value, const char *value2)
00407 {
00408 if (value) {
00409 if (value2) fprintf(dii_file, "@%s \"%s\" <%s>\n", tag, value, value2);
00410 else fprintf(dii_file, "@%s \"%s\"\n", tag, value);
00411 }
00412 }
00413
00414
00415 static string extract_header(char *headers, const char *field);
00416 static string extract_header(char *headers, const char *field)
00417 {
00418 string rc;
00419 int len = strlen(field) + 4;
00420 char f[len];
00421 snprintf(f, len, "\n%s: ", field);
00422 char *p = strstr(headers, f);
00423 if (p) {
00424 p += strlen(f);
00425 char *n = strchr(p, '\n');
00426 if (n) {
00427 *n = '\0';
00428 rc = string(p);
00429 *n = '\n';
00430 }
00431 else {
00432 rc = string(p);
00433 }
00434 }
00435 return rc;
00436 }
00437
00438
00439 static void write_normal_email(file_ll &f, pst_item* item, pst_file* pst);
00440 static void write_normal_email(file_ll &f, pst_item* item, pst_file* pst)
00441 {
00442 DEBUG_ENT("write_normal_email");
00443 char *soh = NULL;
00444 if (item->email->header.str) {
00445
00446
00447
00448 removeCR(item->email->header.str);
00449 char *temp = strstr(item->email->header.str, "\n\n");
00450 if (temp) {
00451 DEBUG_INFO(("Found body text in header\n"));
00452 temp[1] = '\0';
00453 }
00454 soh = skip_header_prologue(item->email->header.str);
00455 }
00456
00457 char folder_line[LINE_SIZE];
00458 char line[LINE_SIZE];
00459
00460 int bates = bates_index;
00461 snprintf(folder_line, sizeof(folder_line), "pst folder = %s\n", f.name.c_str());
00462 open_pdf(folder_line);
00463
00464
00465 fprintf(dii_file, "@FOLDERNAME %s\n", f.name.c_str());
00466 string myfrom = extract_header(soh, "From");
00467 string myto = extract_header(soh, "To");
00468 string mycc = extract_header(soh, "Cc");
00469 string mybcc = extract_header(soh, "Bcc");
00470 if (myfrom.empty()) write_simple("FROM", item->email->outlook_sender_name.str, item->email->sender_address.str);
00471 else write_simple("FROM", myfrom);
00472 if (myto.empty()) write_simple("TO", item->email->sentto_address.str, item->email->recip_address.str);
00473 else write_simple("TO", myto);
00474 if (mycc.empty()) write_simple("CC", item->email->cc_address.str);
00475 else write_simple("CC", mycc);
00476 if (mybcc.empty()) write_simple("BCC", item->email->bcc_address.str);
00477 else write_simple("BCC", mybcc);
00478 if (item->email->sent_date) {
00479 time_t t = pst_fileTimeToUnixTime(item->email->sent_date);
00480 char c_time[C_TIME_SIZE];
00481 strftime(c_time, C_TIME_SIZE, "%F", gmtime(&t));
00482 write_simple("DATESENT", c_time);
00483 strftime(c_time, C_TIME_SIZE, "%T+0000", gmtime(&t));
00484 write_simple("TIMESENT", c_time);
00485 }
00486 if (item->email->arrival_date) {
00487 time_t t = pst_fileTimeToUnixTime(item->email->arrival_date);
00488 char c_time[C_TIME_SIZE];
00489 strftime(c_time, C_TIME_SIZE, "%F", gmtime(&t));
00490 write_simple("DATERCVD", c_time);
00491 strftime(c_time, C_TIME_SIZE, "%T+0000", gmtime(&t));
00492 write_simple("TIMERCVD", c_time);
00493 }
00494 if (item->subject.str) {
00495 write_simple("SUBJECT", item->subject.str);
00496 }
00497 write_simple("MSGID", item->email->messageid.str);
00498 write_simple("READ", (item->flags & 1) ? "Y" : "N");
00499
00500 DEBUG_INFO(("About to print Header\n"));
00501 fprintf(dii_file, "@HEADER\n");
00502
00503 if (item && item->subject.str) {
00504 DEBUG_INFO(("item->subject = %s\n", item->subject.str));
00505 }
00506
00507 if (soh) {
00508
00509 print_pdf(soh);
00510 int len = strlen(soh);
00511 if (!len || (soh[len-1] != '\n')) {
00512 snprintf(line, sizeof(line), "\n");
00513 print_pdf(line);
00514 }
00515
00516 } else {
00517
00518 const char *temp = item->email->outlook_sender.str;
00519 if (!temp) temp = "";
00520 snprintf(line, sizeof(line), "From: \"%s\" <%s>\n", item->email->outlook_sender_name.str, temp);
00521 print_pdf(line);
00522
00523 if (item->subject.str) {
00524 snprintf(line, sizeof(line), "Subject: %s\n", item->subject.str);
00525 } else {
00526 snprintf(line, sizeof(line), "Subject: \n");
00527 }
00528 print_pdf(line);
00529
00530 snprintf(line, sizeof(line), "To: %s\n", item->email->sentto_address.str);
00531 print_pdf(line);
00532
00533 if (item->email->cc_address.str) {
00534 snprintf(line, sizeof(line), "Cc: %s\n", item->email->cc_address.str);
00535 print_pdf(line);
00536 }
00537
00538 if (item->email->sent_date) {
00539 time_t em_time = pst_fileTimeToUnixTime(item->email->sent_date);
00540 char c_time[C_TIME_SIZE];
00541 strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
00542 snprintf(line, sizeof(line), "Date: %s\n", c_time);
00543 print_pdf(line);
00544 }
00545 }
00546 snprintf(line, sizeof(line), "\n");
00547 print_pdf_only(line, black);
00548 fprintf(dii_file, "@HEADER-END\n");
00549
00550 DEBUG_INFO(("About to print Body\n"));
00551 fprintf(dii_file, "@EMAIL-BODY\n");
00552 if (item->body.str) {
00553 removeCR(item->body.str);
00554 print_pdf(item->body.str);
00555 } else if (item->email->htmlbody.str) {
00556 removeCR(item->email->htmlbody.str);
00557 print_pdf(item->email->htmlbody.str);
00558 } else if (item->email->encrypted_body.data || item->email->encrypted_htmlbody.data) {
00559 char ln[LINE_SIZE];
00560 snprintf(ln, sizeof(ln), "%s", "The body of this email is encrypted. This isn't supported yet, but the body is now an attachment\n");
00561 print_pdf(ln);
00562 }
00563 fprintf(dii_file, "@EMAIL-END\n");
00564
00565 int attach_num = 0;
00566 for (pst_item_attach* attach = item->attach; attach; attach = attach->next) {
00567 pst_convert_utf8_null(item, &attach->filename1);
00568 pst_convert_utf8_null(item, &attach->filename2);
00569 pst_convert_utf8_null(item, &attach->mimetype);
00570 DEBUG_INFO(("Attempting Attachment encoding\n"));
00571 if (attach->data.data || attach->i_id) {
00572 string an = write_separate_attachment(f.name, attach, ++attach_num, pst);
00573 fprintf(dii_file, "@EATTACH %s\n", an.c_str());
00574 }
00575 }
00576 close_pdf();
00577 fprintf(dii_file, "@BATESBEG %d\n", bates);
00578 fprintf(dii_file, "@BATESEND %d\n", bates_index-1);
00579 DEBUG_RET();
00580 }
00581
00582
00583 static void create_enter_dir(file_ll &f, file_ll *parent, pst_item *item);
00584 static void create_enter_dir(file_ll &f, file_ll *parent, pst_item *item)
00585 {
00586 pst_convert_utf8(item, &item->file_as);
00587 f.type = item->type;
00588 f.stored_count = (item->folder) ? item->folder->item_count : 0;
00589 f.name = ((parent) ? parent->name + "/" : "") + string(item->file_as.str);
00590 }
00591
00592
00593 static void close_enter_dir(file_ll &f);
00594 static void close_enter_dir(file_ll &f)
00595 {
00596 }
00597
00598
00599 static void process(pst_item *outeritem, file_ll *parent, pst_desc_tree *d_ptr);
00600 static void process(pst_item *outeritem, file_ll *parent, pst_desc_tree *d_ptr)
00601 {
00602 file_ll ff;
00603 pst_item *item = NULL;
00604 DEBUG_ENT("process");
00605 create_enter_dir(ff, parent, outeritem);
00606 for (; d_ptr; d_ptr = d_ptr->next) {
00607 if (d_ptr->desc) {
00608 item = pst_parse_item(&pstfile, d_ptr, NULL);
00609 DEBUG_INFO(("item pointer is %p\n", item));
00610 if (item) {
00611 if (item->folder && item->file_as.str && d_ptr->child ) {
00612
00613 fprintf(stderr, "entering folder %s\n", item->file_as.str);
00614 process(item, &ff, d_ptr->child);
00615 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_SCHEDULE || item->type == PST_TYPE_REPORT)) {
00616 ff.email_count++;
00617 write_normal_email(ff, item, &pstfile);
00618 }
00619 else {
00620 ff.skip_count++;
00621 }
00622 pst_freeItem(item);
00623 } else {
00624 ff.skip_count++;
00625 DEBUG_INFO(("A NULL item was seen\n"));
00626 }
00627 }
00628 }
00629 close_enter_dir(ff);
00630 DEBUG_RET();
00631 }
00632
00633
00634 int main(int argc, char* const* argv)
00635 {
00636 pst_desc_tree *d_ptr;
00637 char *fname = NULL;
00638 char c;
00639 char *d_log = NULL;
00640 prog_name = argv[0];
00641 pst_item *item = NULL;
00642
00643 while ((c = getopt(argc, argv, "B:b:c:d:f:o:O:Vh"))!= -1) {
00644 switch (c) {
00645 case 'B':
00646 bates_prefix = optarg;
00647 break;
00648 case 'b':
00649 bates_index = atoi(optarg);
00650 break;
00651 case 'c':
00652 bates_color = (int)strtol(optarg, (char**)NULL, 16);
00653 break;
00654 case 'f':
00655 font_file = optarg;
00656 break;
00657 case 'o':
00658 output_directory = optarg;
00659 break;
00660 case 'O':
00661 output_file = optarg;
00662 break;
00663 case 'd':
00664 d_log = optarg;
00665 break;
00666 case 'h':
00667 usage();
00668 exit(0);
00669 break;
00670 case 'V':
00671 version();
00672 exit(0);
00673 break;
00674 default:
00675 usage();
00676 exit(1);
00677 break;
00678 }
00679 }
00680
00681 if (!font_file) {
00682 usage();
00683 exit(1);
00684 }
00685
00686 if (argc > optind) {
00687 fname = argv[optind];
00688 } else {
00689 usage();
00690 exit(2);
00691 }
00692
00693
00694 #ifdef DEBUG_ALL
00695
00696 if (!d_log) d_log = "pst2dii.log";
00697 #endif
00698 DEBUG_INIT(d_log, NULL);
00699 DEBUG_ENT("main");
00700 RET_DERROR(pst_open(&pstfile, fname), 1, ("Error opening File\n"));
00701 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
00702
00703 pst_load_extended_attributes(&pstfile);
00704
00705 d_ptr = pstfile.d_head;
00706 item = (pst_item*)pst_parse_item(&pstfile, d_ptr, NULL);
00707 if (!item || !item->message_store) {
00708 DEBUG_RET();
00709 DIE(("Could not get root record\n"));
00710 }
00711
00712 d_ptr = pst_getTopOfFolders(&pstfile, item);
00713 if (!d_ptr) {
00714 DEBUG_RET();
00715 DIE(("Top of folders record not found. Cannot continue\n"));
00716 }
00717
00718 dii_file = fopen(output_file, "wb");
00719 if (dii_file) {
00720 process(item, NULL, d_ptr->child);
00721 pst_freeItem(item);
00722 pst_close(&pstfile);
00723 fclose(dii_file);
00724 }
00725 DEBUG_RET();
00726 return 0;
00727 }