annotate src/pst2dii.cpp.in @ 359:a3e674fade6c

From Jeffrey Morlan: pst_parse_block misreads Table Contexts (aka "type 2") with a multi-block Row Matrix ("ind2"). Rows are never split between blocks - every block except the last has padding at the end which should be ignored. I've only seen this affect the recipients table, but presumably it could affect attachments too. This was causing out-of-bounds memory ranges to be returned from pst_getBlockOffset and later access; patch fixes both the table reading issue and adds a missing bounds check to pst_getBlockOffset (so as not to risk a segfault if the PST is corrupted).
author Carl Byington <carl@five-ten-sg.com>
date Wed, 06 Jul 2016 10:20:12 -0700
parents cb67b335afcc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 /*
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 Copyright (c) 2008 Carl Byington - 510 Software Group, released under
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 the GPL version 2 or any later version at your choice available at
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 http://www.fsf.org/licenses/gpl.txt
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 Based on readpst.c by David Smith
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 */
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 #include <iostream>
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 #include <string>
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 #include <vector>
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 using namespace std;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 extern "C" {
123
ab2a11e72250 more cleanup of #include files.
Carl Byington <carl@five-ten-sg.com>
parents: 120
diff changeset
17 #include "define.h"
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 #include "lzfu.h"
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 struct file_ll {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 string name;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 int32_t stored_count;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 int32_t email_count;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 int32_t skip_count;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 int32_t type;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 file_ll() {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 stored_count = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 email_count = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 skip_count = 0;
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
31 type = 0;
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 };
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 };
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 // global settings
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
36 const char* convert = "@CONVERT@"; // fully qualified path of the convert program from image magick
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
37 const char* prog_name = NULL; // our arg0 name
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
38 const char* bates_prefix = ""; // string to prefix bates numbers
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
39 int bates_index = 0; // current bates sequence
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
40 const char* output_directory = ".";
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
41 const char* output_file = "load.dii";
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 char* font_file = NULL;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 int bates_color = 0xff0000; // color of bates header stamp
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 int email_sequence = 0; // current pdf sequence number
325
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
45 char* pdf_name = NULL; // current pdf file name
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 FILE* dii_file = NULL; // the output dii load file
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
47 pst_file pstfile; // the input pst file
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 // pdf writer globals
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 bool pdf_open = false; // is pdf writer started
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 char* pst_folder; // current folder name
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 int page_sequence; // current page number
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 string conversion; // conversion command
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 vector<string> png_names;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56 // png writer globals
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 bool png_open = false; // is current page open
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 int line_height; // in pixels
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 int char_width; // in pixels
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 int col_number, col_max; // in characters
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61 int line_number, line_max; // lines per page
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
62 int x_position, y_position; // in pixels
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 int black, red; // text colors
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 gdImagePtr image; // current gd image
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
65
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66 const int DPI = 300;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 const double sz = 10.0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 const int margin = DPI/2;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69 const int LINE_SIZE = 2000;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70 const int PAGE_WIDTH = DPI*17/2;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 const int PAGE_HEIGHT = DPI*11;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73 // max size of the c_time char*. It will store the date of the email
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74 #define C_TIME_SIZE 500
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76 static void open_png();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 static void close_png();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
79
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
80 static void version();
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
81 static void version()
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83 printf("pst2dii v%s\n", VERSION);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84 #if BYTE_ORDER == BIG_ENDIAN
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85 printf("Big Endian implementation being used.\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86 #elif BYTE_ORDER == LITTLE_ENDIAN
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 printf("Little Endian implementation being used.\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 #else
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89 # error "Byte order not supported by this library"
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 #endif
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
94 static void usage();
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
95 static void usage()
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97 version();
214
7fcff97ca5a9 document pst2dii font file arg not optional, patch from bharder to fix documentation for pst_getTopOfFolders
Carl Byington <carl@five-ten-sg.com>
parents: 213
diff changeset
98 printf("Usage: %s -f ttf-font-file [OPTIONS] {PST FILENAME}\n", prog_name);
7fcff97ca5a9 document pst2dii font file arg not optional, patch from bharder to fix documentation for pst_getTopOfFolders
Carl Byington <carl@five-ten-sg.com>
parents: 213
diff changeset
99 printf("\t-f ttf-font-file \t- Set the font file\n");
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 printf("OPTIONS:\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101 printf("\t-B bates-prefix \t- Set the bates prefix string\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
102 printf("\t-O dii-output-file\t- Set the dii load file output filename\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103 printf("\t-V \t- Version. Display program version\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104 printf("\t-b bates-number \t- Set the starting bates sequence number\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
105 printf("\t-c bates-color \t- Specify the color of the bates stamps as 6 digit hex\n");
238
410b6422d65b fix --help usage; readpstlog is gone
Carl Byington <carl@five-ten-sg.com>
parents: 214
diff changeset
106 printf("\t-d filename \t- Debug to file.\n");
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107 printf("\t-h \t- Help. This screen\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 printf("\t-o dirname \t- Output directory to write files to.\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
112 static char *removeCR (char *c);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
113 static char *removeCR (char *c) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
114 // converts /r/n to /n
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
115 char *a, *b;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116 DEBUG_ENT("removeCR");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117 a = b = c;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 while (*a != '\0') {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119 *b = *a;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 if (*a != '\r')
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
121 b++;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122 a++;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 *b = '\0';
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 DEBUG_RET();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126 return c;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
127 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130 // The sole purpose of this function is to bypass the pseudo-header prologue
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
131 // that Microsoft Outlook inserts at the beginning of the internet email
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
132 // headers for emails stored in their "Personal Folders" files.
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 static char *skip_header_prologue(char *headers);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134 static char *skip_header_prologue(char *headers) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
135 const char *bad = "Microsoft Mail Internet Headers";
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 if (strncmp(headers, bad, strlen(bad)) == 0) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137 // Found the offensive header prologue
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138 char *pc = strchr(headers, '\n');
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139 return pc + 1;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141 return headers;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
144
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
145 static void check_filename(string &fname);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
146 static void check_filename(string &fname) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
147 char *t = strdup(fname.c_str());
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148 DEBUG_ENT("check_filename");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
149 if (!t) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
150 DEBUG_RET();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
151 return;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
152 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
153 char *tt = t;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
154 bool fixed = false;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
155 while ((t = strpbrk(t, " /\\:"))) {
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
156 // while there are characters in the second string that we don't want
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 *t = '_'; //replace them with an underscore
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
158 fixed = true;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
159 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
160 if (fixed) fname = string(tt);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
161 free(tt);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
162 DEBUG_RET();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
164
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
165
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
166 static string write_separate_attachment(string fname, pst_item_attach* current_attach, int attach_num, pst_file* pst);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
167 static string write_separate_attachment(string fname, pst_item_attach* current_attach, int attach_num, pst_file* pst)
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
168 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
169 FILE *fp = NULL;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
170 int x = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
171 char *temp = NULL;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
172
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
173 // If there is a long filename (filename2) use that, otherwise
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
174 // use the 8.3 filename (filename1)
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
175 char *attach_filename = (current_attach->filename2.str) ? current_attach->filename2.str
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
176 : current_attach->filename1.str;
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
177 DEBUG_ENT("write_separate_attachment");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178 check_filename(fname);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
179 const char* f_name = fname.c_str();
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
180 DEBUG_INFO(("dirname=%s, pathname=%s, filename=%s\n", output_directory, f_name, attach_filename));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
181 int len = strlen(output_directory) + 1 + strlen(f_name) + 15;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
182 if (!attach_filename) {
307
db6db9a26a19 filter private provides from rpm
Carl Byington <carl@five-ten-sg.com>
parents: 298
diff changeset
183 // generate our own (dummy) filename for the attachment
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 170
diff changeset
184 temp = (char*)pst_malloc(len);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
185 sprintf(temp, "%s/%s_attach%i", output_directory, f_name, attach_num);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
186 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
187 // have an attachment name, make sure it's unique
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 170
diff changeset
188 temp = (char*)pst_malloc(len+strlen(attach_filename));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
189 do {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
190 if (fp) fclose(fp);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
191 if (x == 0)
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
192 sprintf(temp, "%s/%s_%s", output_directory, f_name, attach_filename);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
193 else
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
194 sprintf(temp, "%s/%s_%s-%i", output_directory, f_name, attach_filename, x);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
195 } while ((fp = fopen(temp, "r")) && ++x < 99999999);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
196 if (x > 99999999) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
197 DIE(("error finding attachment name. exhausted possibilities to %s\n", temp));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
198 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
199 }
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
200 DEBUG_INFO(("Saving attachment to %s\n", temp));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
201 if (!(fp = fopen(temp, "wb"))) {
213
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
202 DEBUG_WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
203 } else {
195
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents: 186
diff changeset
204 (void)pst_attach_to_file(pst, current_attach, fp);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205 fclose(fp);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 string rc(temp);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
208 if (temp) free(temp);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
209 DEBUG_RET();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
210 return rc;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
211 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
212
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
213
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
214 static void print_pdf_short(const char *line, int len, int color);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
215 static void print_pdf_short(const char *line, int len, int color)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
217 if (line_number >= line_max) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
218 close_png();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
219 open_png();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
221 int brect[8];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
222 gdFTStringExtra strex;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
223 strex.flags = gdFTEX_RESOLUTION;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
224 strex.linespacing = 1.20;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
225 strex.charmap = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
226 strex.hdpi = DPI;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
227 strex.vdpi = DPI;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
228 char xline[len+1];
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
229 memcpy(xline, line, len);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
230 xline[len] = '\0';
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
231 char *p;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
232 char *l = xline;
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
233 while ((p = strchr(l, '&'))) {
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
234 *p = '\0';
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
235 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex);
170
0e1e048716e4 fix bug where we failed to pickup the last extended attribute.
Carl Byington <carl@five-ten-sg.com>
parents: 167
diff changeset
236 if (err) printf("%s", err);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237 x_position += (brect[2]-brect[6]);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
238 l = p+1;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
239 err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, (char*)"&amp;", &strex);
170
0e1e048716e4 fix bug where we failed to pickup the last extended attribute.
Carl Byington <carl@five-ten-sg.com>
parents: 167
diff changeset
240 if (err) printf("%s", err);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
241 x_position += (brect[2]-brect[6]);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
242 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
243 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex);
170
0e1e048716e4 fix bug where we failed to pickup the last extended attribute.
Carl Byington <carl@five-ten-sg.com>
parents: 167
diff changeset
244 if (err) printf("%s", err);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
245 x_position += (brect[2]-brect[6]);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
246 col_number += len;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
247 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
248
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
249
67
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
250 static void new_line();
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
251 static void new_line()
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
252 {
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
253 y_position += line_height;
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
254 line_number += 1;
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
255 x_position = margin;
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
256 col_number = 0;
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
257 }
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
258
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
259
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
260 static void print_pdf_single(const char *line, int color);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
261 static void print_pdf_single(const char *line, int color)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
262 {
67
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
263 while (*line == '\t') {
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
264 char blanks[5];
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
265 memset(blanks, ' ', 5);
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
266 print_pdf_short(blanks, 4, color);
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
267 line++;
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
268 if (col_number >= col_max) new_line();
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
269 }
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
270 int n = strlen(line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
271 while (n) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
272 int m = col_max - col_number; // number of chars that will fit on this line
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
273 m = (n > m) ? m : n;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
274 print_pdf_short(line, m, color);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
275 line += m;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
276 n -= m;
67
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
277 if (n) new_line();
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
278 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
279 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
280
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
281
136
16770fc77139 fix for const correctness on Fedora 11
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
282 static void print_pdf_only(char *line, int color);
16770fc77139 fix for const correctness on Fedora 11
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
283 static void print_pdf_only(char *line, int color)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
284 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
285 char *p;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
286 while ((p = strchr(line, '\n'))) {
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
287 *p = '\0';
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
288 print_pdf_single(line, color);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
289 *p = '\n';
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
290 line = p+1;
67
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
291 new_line();
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
292 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
293 print_pdf_single(line, color);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
294 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
295
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
296
136
16770fc77139 fix for const correctness on Fedora 11
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
297 static void print_pdf(char *line);
16770fc77139 fix for const correctness on Fedora 11
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
298 static void print_pdf(char *line)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
299 {
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
300 pst_fwrite(line, 1, strlen(line), dii_file);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
301 print_pdf_only(line, black);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
302 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
303
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
304
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
305 static void open_png()
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
306 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
307 if (!png_open) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
308 png_open = true;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
309 int brect[8];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
310 image = gdImageCreate(PAGE_WIDTH, PAGE_HEIGHT);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
311 gdImageColorAllocate(image, 255, 255, 255); // background color first one allocated
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
312 black = gdImageColorAllocate(image, 0, 0, 0);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
313 int r = (bates_color & 0xff0000) >> 16;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
314 int g = (bates_color & 0x00ff00) >> 8;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
315 int b = (bates_color & 0x0000ff);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
316 red = gdImageColorAllocate(image, r, g, b);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
317
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
318 gdFTStringExtra strex;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
319 strex.flags = gdFTEX_RESOLUTION;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
320 strex.linespacing = 1.20;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
321 strex.charmap = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
322 strex.hdpi = DPI;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
323 strex.vdpi = DPI;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
324
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
325 char line[LINE_SIZE];
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
326 char *err = gdImageStringFTEx(NULL, &brect[0], black, font_file, sz, 0.0, margin, margin, (char*)"LMgqQ", &strex);
170
0e1e048716e4 fix bug where we failed to pickup the last extended attribute.
Carl Byington <carl@five-ten-sg.com>
parents: 167
diff changeset
327 if (err) printf("%s", err);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
328 line_height = (brect[3]-brect[7]) * 12/10;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
329 char_width = (brect[2]-brect[6]) / 5;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
330 col_number = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
331 col_max = (PAGE_WIDTH - margin*2) / char_width;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
332 line_number = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
333 line_max = (PAGE_HEIGHT - margin*2) / line_height;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
334 x_position = margin;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
335 y_position = margin + line_height;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
336 snprintf(line, sizeof(line), "%s%06d\n", bates_prefix, bates_index++);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
337 print_pdf_only(line, red);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
338 print_pdf_only(pst_folder, red);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
339 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
340 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
341
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
342
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
343 static void close_png()
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
344 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
345 if (png_open) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
346 png_open = false;
325
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
347 int len = 4 + 11 + 4 +1;
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
348 char *fn = (char*)pst_malloc(len);
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
349 snprintf(fn, len, "page%d.png", ++page_sequence);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
350 FILE *pngout = fopen(fn, "wb");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
351 if (pngout) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
352 gdImagePng(image, pngout);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
353 fclose(pngout);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
354 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
355 gdImageDestroy(image); // free memory
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
356 png_names.push_back(fn);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
357 conversion += string(" ") + fn;
325
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
358 free(fn);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
359 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
360 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
361
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
362
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
363 static void open_pdf(char *line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
364 static void open_pdf(char *line)
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
365 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
366 pst_folder = line;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
367 page_sequence = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
368 conversion = string(convert);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
369 png_names.clear();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
370 open_png();
325
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
371 /* Note; allocating the largest string length to pdf_name */
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
372 int len = strlen(output_directory) + 4 + 6 + 4 + 1;
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
373 pdf_name = (char*)pst_malloc(len);
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
374 snprintf(pdf_name, 3 + 6 + 1, "dii%06d", ++email_sequence);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
375 fprintf(dii_file, "\n@T %s\n", pdf_name);
325
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
376 snprintf(pdf_name, len, "%s/dii%06d.pdf", output_directory, email_sequence);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
377 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
378
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
379
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
380 static void close_pdf();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
381 static void close_pdf()
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
382 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
383 close_png();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
384 conversion += string(" ") + pdf_name;
146
0695de3b5a98 fix for 64bit on Fedora 11
Carl Byington <carl@five-ten-sg.com>
parents: 143
diff changeset
385 (void)system(conversion.c_str());
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
386 for (vector<string>::iterator i=png_names.begin(); i!=png_names.end(); i++) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
387 remove((*i).c_str());
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
388 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
389 fprintf(dii_file, "@D %s\n", pdf_name);
325
cb67b335afcc patches from debian
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
390 free(pdf_name);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
391 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
392
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
393
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
394 static void write_simple(const char *tag, const char *value);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
395 static void write_simple(const char *tag, const char *value)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
396 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
397 if (value) fprintf(dii_file, "@%s %s\n", tag, value);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
398 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
399
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
400
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
401 static void write_simple(const char *tag, string value);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
402 static void write_simple(const char *tag, string value)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
403 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
404 fprintf(dii_file, "@%s %s\n", tag, value.c_str());
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
405 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
406
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
407
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
408 static void write_simple(const char *tag, const char *value, const char *value2);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
409 static void write_simple(const char *tag, const char *value, const char *value2)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
410 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
411 if (value) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
412 if (value2) fprintf(dii_file, "@%s \"%s\" <%s>\n", tag, value, value2);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
413 else fprintf(dii_file, "@%s \"%s\"\n", tag, value);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
414 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
415 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
416
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
417
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
418 static string extract_header(char *headers, const char *field);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 69
diff changeset
419 static string extract_header(char *headers, const char *field)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
420 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
421 string rc;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
422 int len = strlen(field) + 4;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
423 char f[len];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
424 snprintf(f, len, "\n%s: ", field);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
425 char *p = strstr(headers, f);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
426 if (p) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
427 p += strlen(f);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
428 char *n = strchr(p, '\n');
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
429 if (n) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
430 *n = '\0';
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
431 rc = string(p);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
432 *n = '\n';
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
433 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
434 else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
435 rc = string(p);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
436 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
437 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
438 return rc;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
439 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
440
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
441
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
442 static void write_normal_email(file_ll &f, pst_item* item, pst_file* pst);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
443 static void write_normal_email(file_ll &f, pst_item* item, pst_file* pst)
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
444 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
445 DEBUG_ENT("write_normal_email");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
446 char *soh = NULL; // real start of headers.
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
447 if (item->email->header.str) {
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
448 // some of the headers we get from the file are not properly defined.
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
449 // they can contain some email stuff too. We will cut off the header
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
450 // when we see a \n\n or \r\n\r\n
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
451 removeCR(item->email->header.str);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
452 char *temp = strstr(item->email->header.str, "\n\n");
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
453 if (temp) {
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
454 DEBUG_INFO(("Found body text in header\n"));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
455 temp[1] = '\0'; // stop after first \n
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
456 }
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
457 soh = skip_header_prologue(item->email->header.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
458 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
459
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
460 char folder_line[LINE_SIZE];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
461 char line[LINE_SIZE];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
462 // reset pdf writer to new file
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
463 int bates = bates_index; // save starting index
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
464 snprintf(folder_line, sizeof(folder_line), "pst folder = %s\n", f.name.c_str());
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
465 open_pdf(folder_line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
466
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
467 // start printing this email
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
468 fprintf(dii_file, "@FOLDERNAME %s\n", f.name.c_str());
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
469 string myfrom = extract_header(soh, "From");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
470 string myto = extract_header(soh, "To");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
471 string mycc = extract_header(soh, "Cc");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
472 string mybcc = extract_header(soh, "Bcc");
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
473 if (myfrom.empty()) write_simple("FROM", item->email->outlook_sender_name.str, item->email->sender_address.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
474 else write_simple("FROM", myfrom);
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
475 if (myto.empty()) write_simple("TO", item->email->sentto_address.str, item->email->recip_address.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
476 else write_simple("TO", myto);
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
477 if (mycc.empty()) write_simple("CC", item->email->cc_address.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
478 else write_simple("CC", mycc);
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
479 if (mybcc.empty()) write_simple("BCC", item->email->bcc_address.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
480 else write_simple("BCC", mybcc);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
481 if (item->email->sent_date) {
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
482 time_t t = pst_fileTimeToUnixTime(item->email->sent_date);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
483 char c_time[C_TIME_SIZE];
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
484 strftime(c_time, C_TIME_SIZE, "%F", gmtime(&t));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
485 write_simple("DATESENT", c_time);
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
486 strftime(c_time, C_TIME_SIZE, "%T+0000", gmtime(&t));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
487 write_simple("TIMESENT", c_time);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
488 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
489 if (item->email->arrival_date) {
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
490 time_t t = pst_fileTimeToUnixTime(item->email->arrival_date);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
491 char c_time[C_TIME_SIZE];
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
492 strftime(c_time, C_TIME_SIZE, "%F", gmtime(&t));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
493 write_simple("DATERCVD", c_time);
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
494 strftime(c_time, C_TIME_SIZE, "%T+0000", gmtime(&t));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
495 write_simple("TIMERCVD", c_time);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
496 }
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
497 if (item->subject.str) {
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
498 write_simple("SUBJECT", item->subject.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
499 }
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
500 write_simple("MSGID", item->email->messageid.str);
154
581fab9f1dc7 avoid emitting bogus empty email messages into contacts and calendar files
Carl Byington <carl@five-ten-sg.com>
parents: 151
diff changeset
501 write_simple("READ", (item->flags & 1) ? "Y" : "N");
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
502
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
503 DEBUG_INFO(("About to print Header\n"));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
504 fprintf(dii_file, "@HEADER\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
505
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
506 if (item && item->subject.str) {
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
507 DEBUG_INFO(("item->subject = %s\n", item->subject.str));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
508 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
509
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
510 if (soh) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
511 // Now, write out the header...
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
512 print_pdf(soh);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
513 int len = strlen(soh);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
514 if (!len || (soh[len-1] != '\n')) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
515 snprintf(line, sizeof(line), "\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
516 print_pdf(line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
517 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
518
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
519 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
520 //make up our own headers
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
521 const char *temp = item->email->outlook_sender.str;
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
522 if (!temp) temp = "";
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
523 snprintf(line, sizeof(line), "From: \"%s\" <%s>\n", item->email->outlook_sender_name.str, temp);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
524 print_pdf(line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
525
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
526 if (item->subject.str) {
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
527 snprintf(line, sizeof(line), "Subject: %s\n", item->subject.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
528 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
529 snprintf(line, sizeof(line), "Subject: \n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
530 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
531 print_pdf(line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
532
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
533 snprintf(line, sizeof(line), "To: %s\n", item->email->sentto_address.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
534 print_pdf(line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
535
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
536 if (item->email->cc_address.str) {
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
537 snprintf(line, sizeof(line), "Cc: %s\n", item->email->cc_address.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
538 print_pdf(line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
539 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
540
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
541 if (item->email->sent_date) {
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
542 time_t em_time = pst_fileTimeToUnixTime(item->email->sent_date);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
543 char c_time[C_TIME_SIZE];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
544 strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
545 snprintf(line, sizeof(line), "Date: %s\n", c_time);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
546 print_pdf(line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
547 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
548 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
549 snprintf(line, sizeof(line), "\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
550 print_pdf_only(line, black);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
551 fprintf(dii_file, "@HEADER-END\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
552
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
553 DEBUG_INFO(("About to print Body\n"));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
554 fprintf(dii_file, "@EMAIL-BODY\n");
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
555 if (item->body.str) {
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
556 removeCR(item->body.str);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
557 print_pdf(item->body.str);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
558 } else if (item->email->htmlbody.str) {
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
559 removeCR(item->email->htmlbody.str);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
560 print_pdf(item->email->htmlbody.str);
167
40e9de445038 improve consistency checking when fetching items from the pst file.
Carl Byington <carl@five-ten-sg.com>
parents: 162
diff changeset
561 } else if (item->email->encrypted_body.data || item->email->encrypted_htmlbody.data) {
146
0695de3b5a98 fix for 64bit on Fedora 11
Carl Byington <carl@five-ten-sg.com>
parents: 143
diff changeset
562 char ln[LINE_SIZE];
0695de3b5a98 fix for 64bit on Fedora 11
Carl Byington <carl@five-ten-sg.com>
parents: 143
diff changeset
563 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");
0695de3b5a98 fix for 64bit on Fedora 11
Carl Byington <carl@five-ten-sg.com>
parents: 143
diff changeset
564 print_pdf(ln);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
565 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
566 fprintf(dii_file, "@EMAIL-END\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
567
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
568 int attach_num = 0;
213
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
569 for (pst_item_attach* attach = item->attach; attach; attach = attach->next) {
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
570 pst_convert_utf8_null(item, &attach->filename1);
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
571 pst_convert_utf8_null(item, &attach->filename2);
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
572 pst_convert_utf8_null(item, &attach->mimetype);
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
573 DEBUG_INFO(("Attempting Attachment encoding\n"));
213
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
574 if (attach->data.data || attach->i_id) {
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
575 string an = write_separate_attachment(f.name, attach, ++attach_num, pst);
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
576 fprintf(dii_file, "@EATTACH %s\n", an.c_str());
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
577 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
578 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
579 close_pdf();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
580 fprintf(dii_file, "@BATESBEG %d\n", bates);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
581 fprintf(dii_file, "@BATESEND %d\n", bates_index-1);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
582 DEBUG_RET();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
583 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
584
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
585
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
586 static void create_enter_dir(file_ll &f, file_ll *parent, pst_item *item);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
587 static void create_enter_dir(file_ll &f, file_ll *parent, pst_item *item)
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
588 {
213
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
589 pst_convert_utf8(item, &item->file_as);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
590 f.type = item->type;
167
40e9de445038 improve consistency checking when fetching items from the pst file.
Carl Byington <carl@five-ten-sg.com>
parents: 162
diff changeset
591 f.stored_count = (item->folder) ? item->folder->item_count : 0;
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 146
diff changeset
592 f.name = ((parent) ? parent->name + "/" : "") + string(item->file_as.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
593 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
594
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
595
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
596 static void close_enter_dir(file_ll &f);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
597 static void close_enter_dir(file_ll &f)
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
598 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
599 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
600
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
601
186
0a4f7ecd7452 more cleanup of external names in the shared library
Carl Byington <carl@five-ten-sg.com>
parents: 182
diff changeset
602 static void process(pst_item *outeritem, file_ll *parent, pst_desc_tree *d_ptr);
0a4f7ecd7452 more cleanup of external names in the shared library
Carl Byington <carl@five-ten-sg.com>
parents: 182
diff changeset
603 static void process(pst_item *outeritem, file_ll *parent, pst_desc_tree *d_ptr)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
604 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
605 file_ll ff;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
606 pst_item *item = NULL;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
607 DEBUG_ENT("process");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
608 create_enter_dir(ff, parent, outeritem);
213
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
609 for (; d_ptr; d_ptr = d_ptr->next) {
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
610 if (d_ptr->desc) {
143
fdc58ad2c758 fix embedded rfc822 messages with attachments
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
611 item = pst_parse_item(&pstfile, d_ptr, NULL);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
612 DEBUG_INFO(("item pointer is %p\n", item));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
613 if (item) {
213
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
614 if (item->folder && item->file_as.str && d_ptr->child ) {
69
63c02a242ca9 minor code cleanup
Carl Byington <carl@five-ten-sg.com>
parents: 67
diff changeset
615 //if this is a non-empty folder, we want to recurse into it
162
6cb85306e28a fix fedora 11 type mismatch warning (actually an error in this case)
Carl Byington <carl@five-ten-sg.com>
parents: 154
diff changeset
616 fprintf(stderr, "entering folder %s\n", item->file_as.str);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
617 process(item, &ff, d_ptr->child);
213
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
618 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_SCHEDULE || item->type == PST_TYPE_REPORT)) {
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
619 ff.email_count++;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
620 write_normal_email(ff, item, &pstfile);
79
56fa05fd5271 Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
621 }
213
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
622 else {
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
623 ff.skip_count++; // other mapi objects
4a659f3138b7 fix pst2dii for shared library changes
Carl Byington <carl@five-ten-sg.com>
parents: 202
diff changeset
624 }
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
625 pst_freeItem(item);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
626 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
627 ff.skip_count++;
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
628 DEBUG_INFO(("A NULL item was seen\n"));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
629 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
630 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
631 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
632 close_enter_dir(ff);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
633 DEBUG_RET();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
634 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
635
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
636
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
637 int main(int argc, char* const* argv)
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
638 {
186
0a4f7ecd7452 more cleanup of external names in the shared library
Carl Byington <carl@five-ten-sg.com>
parents: 182
diff changeset
639 pst_desc_tree *d_ptr;
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
640 char *fname = NULL;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
641 char c;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
642 char *d_log = NULL;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
643 prog_name = argv[0];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
644 pst_item *item = NULL;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
645
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
646 while ((c = getopt(argc, argv, "B:b:c:d:f:o:O:Vh"))!= -1) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
647 switch (c) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
648 case 'B':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
649 bates_prefix = optarg;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
650 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
651 case 'b':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
652 bates_index = atoi(optarg);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
653 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
654 case 'c':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
655 bates_color = (int)strtol(optarg, (char**)NULL, 16);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
656 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
657 case 'f':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
658 font_file = optarg;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
659 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
660 case 'o':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
661 output_directory = optarg;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
662 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
663 case 'O':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
664 output_file = optarg;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
665 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
666 case 'd':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
667 d_log = optarg;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
668 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
669 case 'h':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
670 usage();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
671 exit(0);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
672 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
673 case 'V':
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
674 version();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
675 exit(0);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
676 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
677 default:
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
678 usage();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
679 exit(1);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
680 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
681 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
682 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
683
214
7fcff97ca5a9 document pst2dii font file arg not optional, patch from bharder to fix documentation for pst_getTopOfFolders
Carl Byington <carl@five-ten-sg.com>
parents: 213
diff changeset
684 if (!font_file) {
7fcff97ca5a9 document pst2dii font file arg not optional, patch from bharder to fix documentation for pst_getTopOfFolders
Carl Byington <carl@five-ten-sg.com>
parents: 213
diff changeset
685 usage();
7fcff97ca5a9 document pst2dii font file arg not optional, patch from bharder to fix documentation for pst_getTopOfFolders
Carl Byington <carl@five-ten-sg.com>
parents: 213
diff changeset
686 exit(1);
7fcff97ca5a9 document pst2dii font file arg not optional, patch from bharder to fix documentation for pst_getTopOfFolders
Carl Byington <carl@five-ten-sg.com>
parents: 213
diff changeset
687 }
7fcff97ca5a9 document pst2dii font file arg not optional, patch from bharder to fix documentation for pst_getTopOfFolders
Carl Byington <carl@five-ten-sg.com>
parents: 213
diff changeset
688
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
689 if (argc > optind) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
690 fname = argv[optind];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
691 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
692 usage();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
693 exit(2);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
694 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
695
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
696
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
697 #ifdef DEBUG_ALL
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
698 // force a log file
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
699 if (!d_log) d_log = "pst2dii.log";
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
700 #endif
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
701 DEBUG_INIT(d_log, NULL);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
702 DEBUG_ENT("main");
298
201464dd356e add default character set for items where the pst file does not specify a character set
Carl Byington <carl@five-ten-sg.com>
parents: 285
diff changeset
703 RET_DERROR(pst_open(&pstfile, fname, NULL), 1, ("Error opening File\n"));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
704 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
705
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
706 pst_load_extended_attributes(&pstfile);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
707
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
708 d_ptr = pstfile.d_head; // first record is main record
143
fdc58ad2c758 fix embedded rfc822 messages with attachments
Carl Byington <carl@five-ten-sg.com>
parents: 136
diff changeset
709 item = (pst_item*)pst_parse_item(&pstfile, d_ptr, NULL);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
710 if (!item || !item->message_store) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
711 DEBUG_RET();
202
2f38c4ce606f remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents: 195
diff changeset
712 DIE(("Could not get root record\n"));
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
713 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
714
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
715 d_ptr = pst_getTopOfFolders(&pstfile, item);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
716 if (!d_ptr) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
717 DEBUG_RET();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
718 DIE(("Top of folders record not found. Cannot continue\n"));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
719 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
720
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
721 dii_file = fopen(output_file, "wb");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
722 if (dii_file) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
723 process(item, NULL, d_ptr->child); // do the children of TOPF
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
724 pst_freeItem(item);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
725 pst_close(&pstfile);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
726 fclose(dii_file);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
727 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
728 DEBUG_RET();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
729 return 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
730 }