annotate src/pst2dii.cpp.in @ 79:56fa05fd5271

Patch from Robert Simpson for encryption type 2. Fix the order of testing item types to avoid claiming there are multiple message stores.
author Carl Byington <carl@five-ten-sg.com>
date Fri, 13 Jun 2008 20:47:01 -0700
parents 3cb02cb1e6cd
children 7133b39975f7
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 */
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
10 #include <gd.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
11 #include <stdio.h>
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 <iostream>
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 #include <unistd.h>
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 #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
15 #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
16
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 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
18
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 extern "C" {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 #include "define.h"
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 #include "libstrfunc.h"
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 #include "libpst.h"
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 #include "common.h"
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 #include "timeconv.h"
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 #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
26 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 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
37 skip_count = 0;
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
38 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
39 };
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 };
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 // 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 int email_sequence = 0; // current pdf sequence number
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 char pdf_name[PATH_MAX]; // current pdf file name
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 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
54 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
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 // 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
57 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
58 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
59 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
60 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
61 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
62
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 // 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
64 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
65 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
66 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
67 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
68 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
69 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
70 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
71 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
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 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
74 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
75 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
76 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
77 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
78 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
79
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80 // 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
81 #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
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 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
84 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
85
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 static int version();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 static int version()
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 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
91 #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
92 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
93 #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
94 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
95 #else
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 # 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
97 #endif
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
98 #ifdef __GNUC__
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 #endif
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101 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
102 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
105 static int usage();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
106 static int usage()
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 version();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 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
111 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
112 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
113 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
114 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
115 printf("\t-c bates-color \t- Specify the color of the bates stamps as 6 digit hex\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116 printf("\t-d filename \t- Debug to file. This is a binary log. Use readpstlog to print it.\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117 printf("\t-f ttf-font-file \t- Set the font file\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 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
119 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
120 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
121 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122
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 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
125 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
126 // 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
127 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
128 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
129 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
130 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
131 *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
132 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
133 b++;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134 a++;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
135 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 *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
137 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
138 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
139 }
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
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142 // 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
143 // 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
144 // 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
145 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
146 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
147 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
148 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
149 // 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
150 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
151 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
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 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
154 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
155
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
156
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 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
158 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
159 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
160 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
161 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
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 return;
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 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
166 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
167 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
168 // 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
169 *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
170 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
171 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
172 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
173 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
174 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
175 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
176
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
177
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178 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
179 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
180 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
181 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
182 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
183 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
184
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
185 // 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
186 // use the 8.3 filename (filename1)
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
187 char *attach_filename = (current_attach->filename2) ? current_attach->filename2
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
188 : current_attach->filename1;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
189 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
190 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
191 const char* f_name = 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
192 DEBUG_EMAIL(("dirname=%s, pathname=%s, filename=%s\n", 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 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
194 if (!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
195 // generate our own (dummy) filename for the attachement
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
196 temp = (char*)xmalloc(len);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
197 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
198 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
199 // have an attachment name, make sure it's unique
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200 temp = (char*)xmalloc(len+strlen(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
201 do {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
202 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
203 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
204 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
205 else
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 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
207 } 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
208 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
209 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
210 }
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 DEBUG_EMAIL(("Saving attachment 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
213 if (!(fp = fopen(temp, "wb"))) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
214 WARN(("write_separate_attachment: Cannot open attachment save file \"%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
215 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216 if (current_attach->data)
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
217 pst_fwrite(current_attach->data, 1, current_attach->size, 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
218 else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
219 (void)pst_attach_to_file(pst, current_attach, fp);
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 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
222 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
223 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
224 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
225 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
226 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
227 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
228
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
229
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
230 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
231 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
232 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
233 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
234 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
235 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
236 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237 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
238 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
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250 *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
251 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
252 if (err) printf(err);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
253 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
254 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
255 err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, (char*)"&amp;", &strex);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
256 if (err) printf(err);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
257 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
258 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
259 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
260 if (err) printf(err);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
261 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
262 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
263 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
264
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
265
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
266 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
267 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
268 {
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 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
270 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
271 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
272 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
273 }
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
274
90aa7814ad1f Initial version of pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents: 64
diff changeset
275
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
276 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
277 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
278 {
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
279 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
280 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
281 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
282 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
283 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
284 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
285 }
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
286 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
287 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
288 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
289 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
290 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
291 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
292 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
293 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
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
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
297
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
298 static void print_pdf_only(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
299 static void print_pdf_only(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
300 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
301 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
302 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
303 *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
304 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
305 *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
306 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
307 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
308 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
309 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
310 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
311
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
312
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
313 static void print_pdf(const char *line);
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
314 static void print_pdf(const 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
315 {
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
316 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
317 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
318 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
319
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
320
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
321 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
322 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 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
331 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
332 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
333
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
334 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
335 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
336 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
337 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
338 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
339 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
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 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
342 char *err = gdImageStringFTEx(NULL, &brect[0], black, font_file, sz, 0.0, margin, margin, (char*)"LMgqQ", &strex);
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
343 if (err) printf(err);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
344 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
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
356 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
357
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
358
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
359 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
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 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
362 png_open = false;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
363 char fn[PATH_MAX];
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
364 snprintf(fn, sizeof(fn), "page%d.png", ++page_sequence);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
365 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
366 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
367 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
368 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
369 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
370 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
371 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
372 conversion += string(" ") + fn;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
373 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
374 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
375
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
376
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
377 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
378 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
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 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
381 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
382 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
383 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
384 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
385 snprintf(pdf_name, sizeof(pdf_name), "dii%06d", ++email_sequence);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
386 fprintf(dii_file, "\n@T %s\n", pdf_name);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
387 snprintf(pdf_name, sizeof(pdf_name), "%s/dii%06d.pdf", output_directory, email_sequence);
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
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
390
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
391 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
392 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
393 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
394 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
395 conversion += string(" ") + pdf_name;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
396 system(conversion.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
397 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
398 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
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 fprintf(dii_file, "@D %s\n", pdf_name);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
401 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
402
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
403
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
404 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
405 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
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 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
408 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
409
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
410
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
411 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
412 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
413 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
414 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
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 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
419 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
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 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
422 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
423 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
424 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
425 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
426
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
427
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
428 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
429 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
430 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438 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
439 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
440 *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
441 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
442 *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
443 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
444 else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
445 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
446 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
447 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
448 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
449 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
450
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
451
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
452 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
453 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
454 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
455 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
456 char *soh = NULL; // real start of headers.
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
457 if (item->email->header) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
458 // 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
459 // 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
460 // when we see a \n\n or \r\n\r\n
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
461 removeCR(item->email->header);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
462 char *temp = strstr(item->email->header, "\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
463 if (temp) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
464 DEBUG_EMAIL(("Found body text in 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
465 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
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 soh = skip_header_prologue(item->email->header);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
468 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
469
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
470 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
471 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
472 // 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
473 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
474 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
475 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
476
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
477 // 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
478 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
479 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
480 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
481 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
482 string mybcc = extract_header(soh, "Bcc");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
483 if (myfrom.empty()) write_simple("FROM", item->email->outlook_sender_name, item->email->sender_address);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
484 else write_simple("FROM", myfrom);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
485 if (myto.empty()) write_simple("TO", item->email->sentto_address, item->email->recip_address);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
486 else write_simple("TO", myto);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
487 if (mycc.empty()) write_simple("CC", item->email->cc_address);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
488 else write_simple("CC", mycc);
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 (mybcc.empty()) write_simple("BCC", item->email->bcc_address);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
490 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
491 if (item->email->sent_date) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
492 time_t t = fileTimeToUnixTime(item->email->sent_date, NULL);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
493 char c_time[C_TIME_SIZE];
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
494 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
495 write_simple("DATESENT", c_time);
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
496 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
497 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
498 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
499 if (item->email->arrival_date) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
500 time_t t = fileTimeToUnixTime(item->email->arrival_date, NULL);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
501 char c_time[C_TIME_SIZE];
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
502 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
503 write_simple("DATERCVD", c_time);
64
2c6040b6e8f8 packaging for Fedora (#434727)
Carl Byington <carl@five-ten-sg.com>
parents: 63
diff changeset
504 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
505 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
506 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
507 if (item->email->subject) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
508 write_simple("SUBJECT", item->email->subject->subj);
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 write_simple("MSGID", item->email->messageid);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
511 if (item->email->flag) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
512 write_simple("READ", (item->email->flag & 1) ? "Y" : "N");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
513 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
514
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
515 DEBUG_EMAIL(("About to print 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
516 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
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 if (item && item->email && item->email->subject && item->email->subject->subj) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
519 DEBUG_EMAIL(("item->email->subject->subj = %s\n", item->email->subject->subj));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
520 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
521
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 (soh) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
523 // 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
524 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
525 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
526 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
527 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
528 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
529 }
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 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
532 //make up our own headers
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
533 const char *temp = item->email->outlook_sender;
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 if (!temp) temp = "";
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
535 snprintf(line, sizeof(line), "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
536 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
537
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
538 if (item->email->subject) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
539 snprintf(line, sizeof(line), "Subject: %s\n", item->email->subject->subj);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
540 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
541 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
542 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
543 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
544
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), "To: %s\n", item->email->sentto_address);
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 if (item->email->cc_address) {
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), "Cc: %s\n", item->email->cc_address);
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(line);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
551 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
552
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
553 if (item->email->sent_date) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
554 time_t em_time = fileTimeToUnixTime(item->email->sent_date, 0);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
555 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
556 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
557 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
558 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
559 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
560 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
561 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
562 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
563 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
564
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
565 DEBUG_EMAIL(("About to print Body\n"));
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-BODY\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 if (item->email->body) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
568 removeCR(item->email->body);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
569 print_pdf(item->email->body);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
570 } else if (item->email->htmlbody) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
571 removeCR(item->email->htmlbody);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
572 print_pdf(item->email->htmlbody);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
573 } else if (item->email->encrypted_body || item->email->encrypted_htmlbody) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
574 print_pdf("The body of this email is encrypted. This isn't supported yet, but the body is now an attachment\n");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
575 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
576 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
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 int attach_num = 0;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
579 for (pst_item_attach* current_attach = item->attach; current_attach; current_attach = current_attach->next) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
580 DEBUG_EMAIL(("Attempting Attachment encoding\n"));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
581 if (!current_attach->data) {
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_EMAIL(("Data of attachment is NULL!. Size is supposed to be %i\n", current_attach->size));
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 string an = write_separate_attachment(f.name, current_attach, ++attach_num, pst);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
585 fprintf(dii_file, "@EATTACH %s\n", an.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
586 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
587 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
588 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
589 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
590 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
591 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
592
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 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
595 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
596 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
597 f.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
598 f.skip_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
599 f.type = item->type;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
600 f.stored_count = (item->folder) ? item->folder->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
601 f.name = ((parent) ? parent->name + "/" : "") + string(item->file_as);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
602 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
603
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 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
606 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
607 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
608 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
609
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
610
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
611 static void process(pst_item *outeritem, file_ll *parent, pst_desc_ll *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
612 static void process(pst_item *outeritem, file_ll *parent, pst_desc_ll *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
613 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
614 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
615 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
616 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
617 create_enter_dir(ff, parent, outeritem);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
618 while (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
619 if (d_ptr->desc) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
620 item = pst_parse_item(&pstfile, 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
621 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
622 if (item) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
623 if (item->folder && d_ptr->child ) {
69
63c02a242ca9 minor code cleanup
Carl Byington <carl@five-ten-sg.com>
parents: 67
diff changeset
624 //if this is a non-empty folder, we want to recurse into it
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 fprintf(stderr, "entering folder %s\n", item->file_as);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
626 process(item, &ff, d_ptr->child);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
627 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
628 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
629 DEBUG_MAIN(("main: Processing Email\n"));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
630 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT)) {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
631 DEBUG_MAIN(("main: I have an email, but the folder isn't an email folder. Processing anyway\n"));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
632 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
633 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
634 }
63
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
635 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
636 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
637 ff.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
638 DEBUG_MAIN(("main: A NULL item was seen\n"));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
639 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
640 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
641 d_ptr = d_ptr->next;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
642 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
643 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
644 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
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
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
647
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
648 int main(int argc, char **argv)
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
649 {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
650 pst_desc_ll *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
651 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
652 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
653 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
654 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
655 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
656
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
657 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
658 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
659 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
660 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
661 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
662 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
663 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
664 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
665 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
666 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
667 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
668 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
669 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
670 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
671 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
672 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
673 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
674 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
675 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
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 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
678 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
679 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
680 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
681 usage();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
682 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
683 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
684 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
685 version();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
686 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
687 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
688 default:
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
689 usage();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
690 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
691 break;
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
692 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
693 }
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 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
696 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
697 } else {
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
698 usage();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
699 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
700 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
701
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
702
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
703 #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
704 // 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
705 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
706 #endif
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
707 DEBUG_INIT(d_log);
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
708 DEBUG_REGISTER_CLOSE();
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
709 DEBUG_ENT("main");
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
710 RET_DERROR(pst_open(&pstfile, fname), 1, ("Error opening File\n"));
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
711 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
712
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
713 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
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 = pstfile.d_head; // first record is main record
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
716 item = (pst_item*)pst_parse_item(&pstfile, 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 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
718 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
719 DIE(("main: Could not get root record\n"));
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
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
722 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
723 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
724 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
725 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
726 }
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 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
729 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
730 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
731 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
732 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
733 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
734 }
cfd6175f9334 Start work on pst2dii to convert to Summation dii load file format.
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
735 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
736 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
737 }