annotate src/lspst.c @ 118:0f1492b7fe8b

patch from Fridrich Strba for building on mingw and general cleanup of autoconf files add processing for pst files of type 0x0f start adding support for properly building and installing libpst.so and the header files required to use it. remove version.h since the version number is now in config.h more const correctness issues regarding getopt()
author Carl Byington <carl@five-ten-sg.com>
date Sat, 31 Jan 2009 12:12:36 -0800
parents 7133b39975f7
children 6395ced2b8b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1 /***
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
2 * lspst.c
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3 * Part of the LibPST project
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 * Author: Joe Nahmias <joe@nahmias.net>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 * Based on readpst.c by by David Smith <dave.s@earthcorp.com>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6 *
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 */
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
9 #include "define.h"
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
10
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
11 #include <stdio.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
12 #include <stdlib.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13 #include <time.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14 #include <string.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
15 #include <ctype.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
16 #include <errno.h>
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
17 #include <unistd.h>
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
18
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
19 #include "libpst.h"
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
20 #include "common.h"
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
21 #include "timeconv.h"
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
22
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23 struct file_ll {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
24 char *dname;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
25 int32_t stored_count;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
26 int32_t email_count;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
27 int32_t skip_count;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
28 int32_t type;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
29 };
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
30
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
31
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
32 void canonicalize_filename(char *fname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
33 void debug_print(char *fmt, ...);
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
34 void usage(char *prog_name);
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
35 void version();
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
36
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
37 // global settings
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
38 pst_file pstfile;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
39
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
40
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
41 void create_enter_dir(struct file_ll* f, pst_item *item)
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
42 {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
43 f->email_count = 0;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
44 f->skip_count = 0;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
45 f->type = item->type;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
46 f->stored_count = (item->folder) ? item->folder->email_count : 0;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
47 f->dname = (char*) xmalloc(strlen(item->file_as)+1);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
48 strcpy(f->dname, item->file_as);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
49 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
50
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
51
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
52 void close_enter_dir(struct file_ll *f)
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
53 {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
54 free(f->dname);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
55 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
56
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
57
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
58 void process(pst_item *outeritem, pst_desc_ll *d_ptr)
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
59 {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
60 struct file_ll ff;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
61 pst_item *item = NULL;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
62
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
63 DEBUG_ENT("process");
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
64 memset(&ff, 0, sizeof(ff));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
65 create_enter_dir(&ff, outeritem);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
66
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
67 while (d_ptr) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
68 DEBUG_MAIN(("main: New item record, d_ptr = %p.\n", d_ptr));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
69 if (!d_ptr->desc) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
70 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
71 ff.skip_count++;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
72 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
73 else {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
74 DEBUG_MAIN(("main: Desc Email ID %x [d_ptr->id = %x]\n", d_ptr->desc->id, d_ptr->id));
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
75
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
76 item = pst_parse_item(&pstfile, d_ptr);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
77 DEBUG_MAIN(("main: About to process item @ %p.\n", item));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
78 if (item) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
79 if (item->message_store) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
80 // there should only be one message_store, and we have already done it
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
81 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
82 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
83
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
84 if (item->folder && d_ptr->child) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
85 // if this is a folder, we want to recurse into it
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
86 printf("Folder \"%s\"\n", item->file_as);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
87 process(item, d_ptr->child);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
88
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
89 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
90 // Process Contact item
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
91 if (ff.type != PST_TYPE_CONTACT) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
92 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. Processing anyway\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
93 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
94 printf("Contact");
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
95 if (item->contact->fullname)
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
96 printf("\t%s", pst_rfc2426_escape(item->contact->fullname));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
97 printf("\n");
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
98
110
7133b39975f7 patch from David Cuadrado to process emails with type PST_TYPE_OTHER
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
99 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT || item->type == PST_TYPE_OTHER)) {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
100 // Process Email item
110
7133b39975f7 patch from David Cuadrado to process emails with type PST_TYPE_OTHER
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
101 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT) && (ff.type != PST_TYPE_OTHER)) {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
102 DEBUG_MAIN(("main: I have an email, but the folder isn't an email folder. Processing anyway\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
103 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
104 printf("Email");
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
105 if (item->email->outlook_sender_name)
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
106 printf("\tFrom: %s", item->email->outlook_sender_name);
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
107 if (item->email->subject && item->email->subject->subj)
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
108 printf("\tSubject: %s", item->email->subject->subj);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
109 printf("\n");
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
110
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
111 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
112 // Process Journal item
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
113 if (ff.type != PST_TYPE_JOURNAL) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
114 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
115 }
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
116 if (item->email && item->email->subject && item->email->subject->subj)
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
117 printf("Journal\t%s\n", pst_rfc2426_escape(item->email->subject->subj));
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
118
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
119 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
120 // Process Calendar Appointment item
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
121 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
122 if (ff.type != PST_TYPE_APPOINTMENT) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
123 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
124 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
125 printf("Appointment");
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
126 if (item->email && item->email->subject)
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
127 printf("\tSUMMARY: %s", pst_rfc2426_escape(item->email->subject->subj));
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
128 if (item->appointment->start)
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
129 printf("\tSTART: %s", pst_rfc2445_datetime_format(item->appointment->start));
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
130 if (item->appointment->end)
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
131 printf("\tEND: %s", pst_rfc2445_datetime_format(item->appointment->end));
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
132 printf("\tALL DAY: %s", (item->appointment->all_day==1 ? "Yes" : "No"));
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
133 printf("\n");
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
134
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
135 } else {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
136 ff.skip_count++;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
137 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
138 item->type, item->ascii_type));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
139 }
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
140 pst_freeItem(item);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
141 } else {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
142 ff.skip_count++;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
143 DEBUG_MAIN(("main: A NULL item was seen\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
144 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
145 d_ptr = d_ptr->next;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
146 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
147 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
148 close_enter_dir(&ff);
52
034641c26ab9 code cleanup
carl
parents: 50
diff changeset
149 DEBUG_RET();
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
150 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
151
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
152
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
153 void usage(char *prog_name) {
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
154 DEBUG_ENT("usage");
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
155 version();
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
156 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
157 printf("OPTIONS:\n");
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
158 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n");
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
159 printf("\t-h\t- Help. This screen\n");
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
160 printf("\t-V\t- Version. Display program version\n");
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
161 DEBUG_RET();
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
162 }
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
163
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
164
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
165 void version() {
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
166 DEBUG_ENT("version");
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
167 printf("lspst / LibPST v%s\n", VERSION);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
168 #if BYTE_ORDER == BIG_ENDIAN
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
169 printf("Big Endian implementation being used.\n");
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
170 #elif BYTE_ORDER == LITTLE_ENDIAN
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
171 printf("Little Endian implementation being used.\n");
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
172 #else
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
173 # error "Byte order not supported by this library"
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
174 #endif
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
175 #ifdef __GNUC__
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
176 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
177 #endif
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
178 DEBUG_RET();
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
179 }
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
180
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
181
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 110
diff changeset
182 int main(int argc, char* const* argv) {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
183 pst_item *item = NULL;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
184 pst_desc_ll *d_ptr;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
185 char *temp = NULL; //temporary char pointer
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
186 int c;
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
187 char *d_log = NULL;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
188
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
189 while ((c = getopt(argc, argv, "d:hV"))!= -1) {
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
190 switch (c) {
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
191 case 'd':
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
192 d_log = optarg;
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
193 break;
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
194 case 'h':
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
195 usage(argv[0]);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
196 exit(0);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
197 break;
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
198 case 'V':
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
199 version();
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
200 exit(0);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
201 break;
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
202 default:
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
203 usage(argv[0]);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
204 exit(1);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
205 break;
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
206 }
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
207 }
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
208
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
209 #ifdef DEBUG_ALL
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
210 // force a log file
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
211 if (!d_log) d_log = "lspst.log";
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
212 #endif // defined DEBUG_ALL
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
213 DEBUG_INIT(d_log);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
214 DEBUG_REGISTER_CLOSE();
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
215 DEBUG_ENT("main");
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
216
50
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
217 if (argc <= optind) {
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
218 usage(argv[0]);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
219 exit(2);
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
220 }
fb3818370dd6 more fixes for 64 bit format
carl
parents: 48
diff changeset
221
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
222 // Open PST file
59
7d5c637aaafb General cleanup and code fixes.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
223 if (pst_open(&pstfile, argv[optind])) DIE(("Error opening File\n"));
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
224
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
225 // Load PST index
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
226 if (pst_load_index(&pstfile)) DIE(("Index Error\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
227
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
228 pst_load_extended_attributes(&pstfile);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
229
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
230 d_ptr = pstfile.d_head; // first record is main record
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
231 item = pst_parse_item(&pstfile, d_ptr);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
232 if (!item || !item->message_store) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
233 DEBUG_RET();
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
234 DIE(("main: Could not get root record\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
235 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
236
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
237 // default the file_as to the same as the main filename if it doesn't exist
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
238 if (!item->file_as) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
239 if (!(temp = strrchr(argv[1], '/')))
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
240 if (!(temp = strrchr(argv[1], '\\')))
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
241 temp = argv[1];
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
242 else
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
243 temp++; // get past the "\\"
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
244 else
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
245 temp++; // get past the "/"
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
246 item->file_as = (char*)xmalloc(strlen(temp)+1);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
247 strcpy(item->file_as, temp);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
248 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
249 fprintf(stderr, "item->file_as = '%s'.\n", item->file_as);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
250
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
251 d_ptr = pst_getTopOfFolders(&pstfile, item);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
252 if (!d_ptr) DIE(("Top of folders record not found. Cannot continue\n"));
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
253 DEBUG_MAIN(("d_ptr(TOF) = %p.\n", d_ptr));
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
254
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
255 process(item, d_ptr->child); // do the childred of TOPF
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
256 pst_freeItem(item);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
257 pst_close(&pstfile);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
258
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
259 DEBUG_RET();
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
260 return 0;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
261 }
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
262
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
263
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
264 // This function will make sure that a filename is in cannonical form. That
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
265 // is, it will replace any slashes, backslashes, or colons with underscores.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
266 void canonicalize_filename(char *fname) {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
267 DEBUG_ENT("canonicalize_filename");
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
268 if (fname == NULL) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
269 DEBUG_RET();
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
270 return;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
271 }
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: 59
diff changeset
272 while ((fname = strpbrk(fname, "/\\:")))
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
273 *fname = '_';
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
274 DEBUG_RET();
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
275 }
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
276
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
277
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
278 void debug_print(char *fmt, ...) {
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
279 // shamlessly stolen from minprintf() in K&R pg. 156
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
280 va_list ap;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
281 char *p, *sval;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
282 void *pval;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
283 int ival;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
284 double dval;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
285 FILE *fp = stderr;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
286
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
287 va_start(ap, fmt);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
288 for(p = fmt; *p; p++) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
289 if (*p != '%') {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
290 fputc(*p, fp);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
291 continue;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
292 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
293 switch (tolower(*++p)) {
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
294 case 'd': case 'i':
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
295 ival = va_arg(ap, int);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
296 fprintf(fp, "%d", ival);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
297 break;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
298 case 'f':
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
299 dval = va_arg(ap, double);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
300 fprintf(fp, "%f", dval);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
301 break;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
302 case 's':
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
303 for (sval = va_arg(ap, char *); *sval; ++sval)
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
304 fputc(*sval, fp);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
305 break;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
306 case 'p':
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
307 pval = va_arg(ap, void *);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
308 fprintf(fp, "%p", pval);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
309 break;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
310 case 'x':
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
311 ival = va_arg(ap, int);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
312 fprintf(fp, "%#010x", ival);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
313 break;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
314 default:
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
315 fputc(*p, fp);
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
316 break;
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
317 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
318 }
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 31
diff changeset
319 va_end(ap);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
320 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
321
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
322