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