Mercurial > libpst
annotate src/lspst.c @ 409:1c458f13d1d3 stable-0-6-76
fix template issue to build with gcc 11
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Sat, 27 Mar 2021 17:06:30 -0700 |
parents | 5c0ce43c7532 |
children |
rev | line source |
---|---|
16 | 1 /*** |
2 * lspst.c | |
3 * Part of the LibPST project | |
4 * Author: Joe Nahmias <joe@nahmias.net> | |
390
5c0ce43c7532
Fix a number of spelling mistakes
Paul Wise <pabs3@bonedaddy.net>
parents:
378
diff
changeset
|
5 * Based on readpst.c by David Smith <dave.s@earthcorp.com> |
16 | 6 * |
7 */ | |
8 | |
122
bdb38b434c0a
more changes from Fridrich Strba to avoid installing our config.h
Carl Byington <carl@five-ten-sg.com>
parents:
120
diff
changeset
|
9 #include "define.h" |
bdb38b434c0a
more changes from Fridrich Strba to avoid installing our config.h
Carl Byington <carl@five-ten-sg.com>
parents:
120
diff
changeset
|
10 |
16 | 11 struct file_ll { |
43 | 12 char *dname; |
13 int32_t stored_count; | |
167
40e9de445038
improve consistency checking when fetching items from the pst file.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
14 int32_t item_count; |
43 | 15 int32_t skip_count; |
16 int32_t type; | |
16 | 17 }; |
43 | 18 |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
19 struct options { |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
20 int long_format; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
21 char *date_format; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
22 }; |
43 | 23 |
16 | 24 void canonicalize_filename(char *fname); |
25 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
|
26 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
|
27 void version(); |
43 | 28 |
29 // global settings | |
30 pst_file pstfile; | |
31 | |
16 | 32 |
43 | 33 void create_enter_dir(struct file_ll* f, pst_item *item) |
34 { | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
35 pst_convert_utf8(item, &item->file_as); |
167
40e9de445038
improve consistency checking when fetching items from the pst file.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
36 f->item_count = 0; |
43 | 37 f->skip_count = 0; |
38 f->type = item->type; | |
167
40e9de445038
improve consistency checking when fetching items from the pst file.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
39 f->stored_count = (item->folder) ? item->folder->item_count : 0; |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
167
diff
changeset
|
40 f->dname = strdup(item->file_as.str); |
43 | 41 } |
16 | 42 |
43 | |
43 | 44 void close_enter_dir(struct file_ll *f) |
45 { | |
46 free(f->dname); | |
47 } | |
16 | 48 |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
49 void process(pst_item *outeritem, pst_desc_tree *d_ptr, struct options o) |
43 | 50 { |
51 struct file_ll ff; | |
52 pst_item *item = NULL; | |
211
94bde95d7e18
the shared library interface should now be thread safe
Carl Byington <carl@five-ten-sg.com>
parents:
202
diff
changeset
|
53 char *result = NULL; |
94bde95d7e18
the shared library interface should now be thread safe
Carl Byington <carl@five-ten-sg.com>
parents:
202
diff
changeset
|
54 size_t resultlen = 0; |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
55 size_t dateresultlen; |
43 | 56 |
57 DEBUG_ENT("process"); | |
58 memset(&ff, 0, sizeof(ff)); | |
59 create_enter_dir(&ff, outeritem); | |
16 | 60 |
43 | 61 while (d_ptr) { |
62 if (!d_ptr->desc) { | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
63 DEBUG_WARN(("ERROR item's desc record is NULL\n")); |
43 | 64 ff.skip_count++; |
65 } | |
66 else { | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
67 DEBUG_INFO(("Desc Email ID %"PRIx64" [d_ptr->d_id = %"PRIx64"]\n", d_ptr->desc->i_id, d_ptr->d_id)); |
16 | 68 |
143
fdc58ad2c758
fix embedded rfc822 messages with attachments
Carl Byington <carl@five-ten-sg.com>
parents:
129
diff
changeset
|
69 item = pst_parse_item(&pstfile, d_ptr, NULL); |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
70 DEBUG_INFO(("About to process item @ %p.\n", item)); |
43 | 71 if (item) { |
72 if (item->message_store) { | |
73 // there should only be one message_store, and we have already done it | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
74 DIE(("A second message_store has been found. Sorry, this must be an error.\n")); |
43 | 75 } |
16 | 76 |
43 | 77 if (item->folder && d_ptr->child) { |
78 // if this is a folder, we want to recurse into it | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
79 pst_convert_utf8(item, &item->file_as); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
80 printf("Folder \"%s\"\n", item->file_as.str); |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
81 process(item, d_ptr->child, o); |
16 | 82 |
43 | 83 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) { |
198
7c60d6d1c681
decode more recurrence mapi elements
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
84 if (!ff.type) ff.type = item->type; |
43 | 85 // Process Contact item |
86 if (ff.type != PST_TYPE_CONTACT) { | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
87 DEBUG_INFO(("I have a contact, but the folder isn't a contacts folder. Processing anyway\n")); |
43 | 88 } |
89 printf("Contact"); | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
90 if (item->contact->fullname.str) |
211
94bde95d7e18
the shared library interface should now be thread safe
Carl Byington <carl@five-ten-sg.com>
parents:
202
diff
changeset
|
91 printf("\t%s", pst_rfc2426_escape(item->contact->fullname.str, &result, &resultlen)); |
43 | 92 printf("\n"); |
16 | 93 |
198
7c60d6d1c681
decode more recurrence mapi elements
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
94 } else if (item->email && ((item->type == PST_TYPE_NOTE) || (item->type == PST_TYPE_SCHEDULE) || (item->type == PST_TYPE_REPORT))) { |
7c60d6d1c681
decode more recurrence mapi elements
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
95 if (!ff.type) ff.type = item->type; |
43 | 96 // Process Email item |
198
7c60d6d1c681
decode more recurrence mapi elements
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
97 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) { |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
98 DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n")); |
43 | 99 } |
100 printf("Email"); | |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
101 if (o.long_format == 1) { |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
102 if (item->email->arrival_date) { |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
103 char time_buffer[MAXDATEFMTLEN]; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
104 dateresultlen = pst_fileTimeToString(item->email->arrival_date, o.date_format, time_buffer); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
105 if (dateresultlen < 1) |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
106 DIE(("Date format error in -f option.\n")); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
107 printf("\tDate: %s", time_buffer); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
108 } |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
109 else |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
110 printf("\t"); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
111 } |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
112 if (item->email->outlook_sender_name.str) |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
113 printf("\tFrom: %s", item->email->outlook_sender_name.str); |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
114 else |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
115 printf("\t"); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
116 if (o.long_format == 1) { |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
117 if (item->email->outlook_recipient_name.str) |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
118 printf("\tTo: %s", item->email->outlook_recipient_name.str); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
119 else |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
120 printf("\t"); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
121 if (item->email->cc_address.str) |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
122 printf("\tCC: %s", item->email->cc_address.str); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
123 else |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
124 printf("\t"); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
125 if (item->email->bcc_address.str) |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
126 printf("\tBCC: %s", item->email->bcc_address.str); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
127 else |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
128 printf("\t"); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
129 } |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
130 if (item->subject.str) |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
131 printf("\tSubject: %s", item->subject.str); |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
132 else |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
133 printf("\t"); |
43 | 134 printf("\n"); |
16 | 135 |
43 | 136 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) { |
198
7c60d6d1c681
decode more recurrence mapi elements
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
137 if (!ff.type) ff.type = item->type; |
43 | 138 // Process Journal item |
139 if (ff.type != PST_TYPE_JOURNAL) { | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
140 DEBUG_INFO(("I have a journal entry, but folder isn't specified as a journal type. Processing...\n")); |
43 | 141 } |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
142 if (item->subject.str) |
211
94bde95d7e18
the shared library interface should now be thread safe
Carl Byington <carl@five-ten-sg.com>
parents:
202
diff
changeset
|
143 printf("Journal\t%s\n", pst_rfc2426_escape(item->subject.str, &result, &resultlen)); |
16 | 144 |
43 | 145 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) { |
199
e3a46f66332b
more changes in recurrence decoding
Carl Byington <carl@five-ten-sg.com>
parents:
198
diff
changeset
|
146 char time_buffer[30]; |
198
7c60d6d1c681
decode more recurrence mapi elements
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
147 if (!ff.type) ff.type = item->type; |
43 | 148 // Process Calendar Appointment item |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
149 DEBUG_INFO(("Processing Appointment Entry\n")); |
43 | 150 if (ff.type != PST_TYPE_APPOINTMENT) { |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
151 DEBUG_INFO(("I have an appointment, but folder isn't specified as an appointment type. Processing...\n")); |
43 | 152 } |
153 printf("Appointment"); | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
154 if (item->subject.str) |
211
94bde95d7e18
the shared library interface should now be thread safe
Carl Byington <carl@five-ten-sg.com>
parents:
202
diff
changeset
|
155 printf("\tSUMMARY: %s", pst_rfc2426_escape(item->subject.str, &result, &resultlen)); |
50 | 156 if (item->appointment->start) |
199
e3a46f66332b
more changes in recurrence decoding
Carl Byington <carl@five-ten-sg.com>
parents:
198
diff
changeset
|
157 printf("\tSTART: %s", pst_rfc2445_datetime_format(item->appointment->start, sizeof(time_buffer), time_buffer)); |
50 | 158 if (item->appointment->end) |
199
e3a46f66332b
more changes in recurrence decoding
Carl Byington <carl@five-ten-sg.com>
parents:
198
diff
changeset
|
159 printf("\tEND: %s", pst_rfc2445_datetime_format(item->appointment->end, sizeof(time_buffer), time_buffer)); |
50 | 160 printf("\tALL DAY: %s", (item->appointment->all_day==1 ? "Yes" : "No")); |
43 | 161 printf("\n"); |
16 | 162 |
43 | 163 } else { |
164 ff.skip_count++; | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
165 DEBUG_INFO(("Unknown item type. %i. Ascii1=\"%s\"\n", |
43 | 166 item->type, item->ascii_type)); |
167 } | |
46 | 168 pst_freeItem(item); |
43 | 169 } else { |
170 ff.skip_count++; | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
171 DEBUG_INFO(("A NULL item was seen\n")); |
43 | 172 } |
173 } | |
355 | 174 d_ptr = d_ptr->next; |
43 | 175 } |
176 close_enter_dir(&ff); | |
211
94bde95d7e18
the shared library interface should now be thread safe
Carl Byington <carl@five-ten-sg.com>
parents:
202
diff
changeset
|
177 if (result) free(result); |
52 | 178 DEBUG_RET(); |
43 | 179 } |
16 | 180 |
43 | 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 void usage(char *prog_name) { |
50 | 183 DEBUG_ENT("usage"); |
184 version(); | |
185 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name); | |
186 printf("OPTIONS:\n"); | |
187 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n"); | |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
188 printf("\t-l\t- Print the date, CC and BCC fields of emails too (by default only the From and Subject)\n"); |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
189 printf("\t-f <date_format> \t- Select the date format in ctime format (by default \"%%F %%T\")\n"); |
50 | 190 printf("\t-h\t- Help. This screen\n"); |
191 printf("\t-V\t- Version. Display program version\n"); | |
192 DEBUG_RET(); | |
193 } | |
194 | |
195 | |
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
|
196 void version() { |
50 | 197 DEBUG_ENT("version"); |
198 printf("lspst / LibPST v%s\n", VERSION); | |
199 #if BYTE_ORDER == BIG_ENDIAN | |
200 printf("Big Endian implementation being used.\n"); | |
201 #elif BYTE_ORDER == LITTLE_ENDIAN | |
202 printf("Little Endian implementation being used.\n"); | |
203 #else | |
204 # error "Byte order not supported by this library" | |
205 #endif | |
206 DEBUG_RET(); | |
207 } | |
208 | |
209 | |
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
|
210 int main(int argc, char* const* argv) { |
43 | 211 pst_item *item = NULL; |
186
0a4f7ecd7452
more cleanup of external names in the shared library
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
212 pst_desc_tree *d_ptr; |
43 | 213 char *temp = NULL; //temporary char pointer |
50 | 214 int c; |
43 | 215 char *d_log = NULL; |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
216 struct options o; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
217 o.long_format = 0; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
218 char *defaultfmtdate = "%F %T"; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
219 o.date_format = defaultfmtdate; |
16 | 220 |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
221 while ((c = getopt(argc, argv, "d:f:lhV"))!= -1) { |
50 | 222 switch (c) { |
223 case 'd': | |
224 d_log = optarg; | |
225 break; | |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
226 case 'f': |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
227 o.date_format = optarg; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
228 break; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
229 case 'l': |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
230 o.long_format = 1; |
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
231 break; |
50 | 232 case 'h': |
233 usage(argv[0]); | |
234 exit(0); | |
235 break; | |
236 case 'V': | |
237 version(); | |
238 exit(0); | |
239 break; | |
240 default: | |
241 usage(argv[0]); | |
242 exit(1); | |
243 break; | |
244 } | |
245 } | |
43 | 246 |
48 | 247 #ifdef DEBUG_ALL |
248 // force a log file | |
249 if (!d_log) d_log = "lspst.log"; | |
250 #endif // defined DEBUG_ALL | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
251 DEBUG_INIT(d_log, NULL); |
43 | 252 DEBUG_ENT("main"); |
253 | |
50 | 254 if (argc <= optind) { |
255 usage(argv[0]); | |
256 exit(2); | |
257 } | |
258 | |
43 | 259 // Open PST file |
298
201464dd356e
add default character set for items where the pst file does not specify a character set
Carl Byington <carl@five-ten-sg.com>
parents:
285
diff
changeset
|
260 if (pst_open(&pstfile, argv[optind], NULL)) DIE(("Error opening File\n")); |
16 | 261 |
43 | 262 // Load PST index |
263 if (pst_load_index(&pstfile)) DIE(("Index Error\n")); | |
264 | |
265 pst_load_extended_attributes(&pstfile); | |
16 | 266 |
43 | 267 d_ptr = pstfile.d_head; // first record is main record |
143
fdc58ad2c758
fix embedded rfc822 messages with attachments
Carl Byington <carl@five-ten-sg.com>
parents:
129
diff
changeset
|
268 item = pst_parse_item(&pstfile, d_ptr, NULL); |
43 | 269 if (!item || !item->message_store) { |
270 DEBUG_RET(); | |
202
2f38c4ce606f
remove readpstlog, switch to plain ascii debug log files
Carl Byington <carl@five-ten-sg.com>
parents:
199
diff
changeset
|
271 DIE(("Could not get root record\n")); |
43 | 272 } |
16 | 273 |
43 | 274 // default the file_as to the same as the main filename if it doesn't exist |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
275 if (!item->file_as.str) { |
43 | 276 if (!(temp = strrchr(argv[1], '/'))) |
277 if (!(temp = strrchr(argv[1], '\\'))) | |
278 temp = argv[1]; | |
279 else | |
280 temp++; // get past the "\\" | |
281 else | |
282 temp++; // get past the "/" | |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
167
diff
changeset
|
283 item->file_as.str = strdup(temp); |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
284 item->file_as.is_utf8 = 1; |
43 | 285 } |
16 | 286 |
43 | 287 d_ptr = pst_getTopOfFolders(&pstfile, item); |
288 if (!d_ptr) DIE(("Top of folders record not found. Cannot continue\n")); | |
16 | 289 |
378
ad7b880ad3d1
Alfredo Esteban - add -l and -f options to lspst
Carl Byington <carl@five-ten-sg.com>
parents:
355
diff
changeset
|
290 process(item, d_ptr->child, o); // do the childred of TOPF |
46 | 291 pst_freeItem(item); |
43 | 292 pst_close(&pstfile); |
16 | 293 |
43 | 294 DEBUG_RET(); |
295 return 0; | |
16 | 296 } |
43 | 297 |
298 | |
390
5c0ce43c7532
Fix a number of spelling mistakes
Paul Wise <pabs3@bonedaddy.net>
parents:
378
diff
changeset
|
299 // This function will make sure that a filename is in canonical form. That |
16 | 300 // is, it will replace any slashes, backslashes, or colons with underscores. |
301 void canonicalize_filename(char *fname) { | |
43 | 302 DEBUG_ENT("canonicalize_filename"); |
303 if (fname == NULL) { | |
304 DEBUG_RET(); | |
305 return; | |
306 } | |
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
|
307 while ((fname = strpbrk(fname, "/\\:"))) |
43 | 308 *fname = '_'; |
309 DEBUG_RET(); | |
16 | 310 } |
43 | 311 |
312 |