Mercurial > libpst
annotate src/lspst.c @ 157:cc3c71da9fe6
bump version for fedora cvs tagging mistake
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Sat, 14 Mar 2009 17:05:05 -0700 |
parents | 581fab9f1dc7 |
children | ab384fed78c5 |
rev | line source |
---|---|
16 | 1 /*** |
2 * lspst.c | |
3 * Part of the LibPST project | |
4 * Author: Joe Nahmias <joe@nahmias.net> | |
5 * Based on readpst.c by by David Smith <dave.s@earthcorp.com> | |
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; | |
14 int32_t email_count; | |
15 int32_t skip_count; | |
16 int32_t type; | |
16 | 17 }; |
43 | 18 |
19 | |
16 | 20 void canonicalize_filename(char *fname); |
21 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
|
22 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
|
23 void version(); |
43 | 24 |
25 // global settings | |
26 pst_file pstfile; | |
27 | |
16 | 28 |
43 | 29 void create_enter_dir(struct file_ll* f, pst_item *item) |
30 { | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
31 pst_convert_utf8(item, &item->file_as); |
43 | 32 f->email_count = 0; |
33 f->skip_count = 0; | |
34 f->type = item->type; | |
35 f->stored_count = (item->folder) ? item->folder->email_count : 0; | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
36 f->dname = (char*) xmalloc(strlen(item->file_as.str)+1); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
37 strcpy(f->dname, item->file_as.str); |
43 | 38 } |
16 | 39 |
40 | |
43 | 41 void close_enter_dir(struct file_ll *f) |
42 { | |
43 free(f->dname); | |
44 } | |
16 | 45 |
46 | |
43 | 47 void process(pst_item *outeritem, pst_desc_ll *d_ptr) |
48 { | |
49 struct file_ll ff; | |
50 pst_item *item = NULL; | |
51 | |
52 DEBUG_ENT("process"); | |
53 memset(&ff, 0, sizeof(ff)); | |
54 create_enter_dir(&ff, outeritem); | |
16 | 55 |
43 | 56 while (d_ptr) { |
57 if (!d_ptr->desc) { | |
150
06aa84023b48
rename some structure fields to reflect our better understanding of the pst format
Carl Byington <carl@five-ten-sg.com>
parents:
143
diff
changeset
|
58 DEBUG_WARN(("main: ERROR item's desc record is NULL\n")); |
43 | 59 ff.skip_count++; |
60 } | |
61 else { | |
150
06aa84023b48
rename some structure fields to reflect our better understanding of the pst format
Carl Byington <carl@five-ten-sg.com>
parents:
143
diff
changeset
|
62 DEBUG_MAIN(("main: Desc Email ID %"PRIx64" [d_ptr->d_id = %"PRIx64"]\n", d_ptr->desc->id, d_ptr->d_id)); |
16 | 63 |
143
fdc58ad2c758
fix embedded rfc822 messages with attachments
Carl Byington <carl@five-ten-sg.com>
parents:
129
diff
changeset
|
64 item = pst_parse_item(&pstfile, d_ptr, NULL); |
43 | 65 DEBUG_MAIN(("main: About to process item @ %p.\n", item)); |
66 if (item) { | |
67 if (item->message_store) { | |
68 // there should only be one message_store, and we have already done it | |
69 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n")); | |
70 } | |
16 | 71 |
43 | 72 if (item->folder && d_ptr->child) { |
73 // 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
|
74 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
|
75 printf("Folder \"%s\"\n", item->file_as.str); |
43 | 76 process(item, d_ptr->child); |
16 | 77 |
43 | 78 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) { |
79 // Process Contact item | |
80 if (ff.type != PST_TYPE_CONTACT) { | |
81 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. Processing anyway\n")); | |
82 } | |
83 printf("Contact"); | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
84 if (item->contact->fullname.str) |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
85 printf("\t%s", pst_rfc2426_escape(item->contact->fullname.str)); |
43 | 86 printf("\n"); |
16 | 87 |
154
581fab9f1dc7
avoid emitting bogus empty email messages into contacts and calendar files
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
88 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) { |
43 | 89 // Process Email item |
154
581fab9f1dc7
avoid emitting bogus empty email messages into contacts and calendar files
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
90 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT)) { |
43 | 91 DEBUG_MAIN(("main: I have an email, but the folder isn't an email folder. Processing anyway\n")); |
92 } | |
93 printf("Email"); | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
94 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
|
95 printf("\tFrom: %s", 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
|
96 if (item->subject.str) |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
97 printf("\tSubject: %s", item->subject.str); |
43 | 98 printf("\n"); |
16 | 99 |
43 | 100 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) { |
101 // Process Journal item | |
102 if (ff.type != PST_TYPE_JOURNAL) { | |
103 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n")); | |
104 } | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
105 if (item->subject.str) |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
106 printf("Journal\t%s\n", pst_rfc2426_escape(item->subject.str)); |
16 | 107 |
43 | 108 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) { |
109 // Process Calendar Appointment item | |
110 DEBUG_MAIN(("main: Processing Appointment Entry\n")); | |
111 if (ff.type != PST_TYPE_APPOINTMENT) { | |
112 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n")); | |
113 } | |
114 printf("Appointment"); | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
115 if (item->subject.str) |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
116 printf("\tSUMMARY: %s", pst_rfc2426_escape(item->subject.str)); |
50 | 117 if (item->appointment->start) |
118 printf("\tSTART: %s", pst_rfc2445_datetime_format(item->appointment->start)); | |
119 if (item->appointment->end) | |
120 printf("\tEND: %s", pst_rfc2445_datetime_format(item->appointment->end)); | |
121 printf("\tALL DAY: %s", (item->appointment->all_day==1 ? "Yes" : "No")); | |
43 | 122 printf("\n"); |
16 | 123 |
43 | 124 } else { |
125 ff.skip_count++; | |
126 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", | |
127 item->type, item->ascii_type)); | |
128 } | |
46 | 129 pst_freeItem(item); |
43 | 130 } else { |
131 ff.skip_count++; | |
132 DEBUG_MAIN(("main: A NULL item was seen\n")); | |
133 } | |
134 d_ptr = d_ptr->next; | |
135 } | |
136 } | |
137 close_enter_dir(&ff); | |
52 | 138 DEBUG_RET(); |
43 | 139 } |
16 | 140 |
43 | 141 |
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
|
142 void usage(char *prog_name) { |
50 | 143 DEBUG_ENT("usage"); |
144 version(); | |
145 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name); | |
146 printf("OPTIONS:\n"); | |
147 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n"); | |
148 printf("\t-h\t- Help. This screen\n"); | |
149 printf("\t-V\t- Version. Display program version\n"); | |
150 DEBUG_RET(); | |
151 } | |
152 | |
153 | |
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
|
154 void version() { |
50 | 155 DEBUG_ENT("version"); |
156 printf("lspst / LibPST v%s\n", VERSION); | |
157 #if BYTE_ORDER == BIG_ENDIAN | |
158 printf("Big Endian implementation being used.\n"); | |
159 #elif BYTE_ORDER == LITTLE_ENDIAN | |
160 printf("Little Endian implementation being used.\n"); | |
161 #else | |
162 # error "Byte order not supported by this library" | |
163 #endif | |
164 #ifdef __GNUC__ | |
165 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__); | |
166 #endif | |
167 DEBUG_RET(); | |
168 } | |
169 | |
170 | |
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
|
171 int main(int argc, char* const* argv) { |
43 | 172 pst_item *item = NULL; |
173 pst_desc_ll *d_ptr; | |
174 char *temp = NULL; //temporary char pointer | |
50 | 175 int c; |
43 | 176 char *d_log = NULL; |
16 | 177 |
50 | 178 while ((c = getopt(argc, argv, "d:hV"))!= -1) { |
179 switch (c) { | |
180 case 'd': | |
181 d_log = optarg; | |
182 break; | |
183 case 'h': | |
184 usage(argv[0]); | |
185 exit(0); | |
186 break; | |
187 case 'V': | |
188 version(); | |
189 exit(0); | |
190 break; | |
191 default: | |
192 usage(argv[0]); | |
193 exit(1); | |
194 break; | |
195 } | |
196 } | |
43 | 197 |
48 | 198 #ifdef DEBUG_ALL |
199 // force a log file | |
200 if (!d_log) d_log = "lspst.log"; | |
201 #endif // defined DEBUG_ALL | |
43 | 202 DEBUG_INIT(d_log); |
203 DEBUG_REGISTER_CLOSE(); | |
204 DEBUG_ENT("main"); | |
205 | |
50 | 206 if (argc <= optind) { |
207 usage(argv[0]); | |
208 exit(2); | |
209 } | |
210 | |
43 | 211 // Open PST file |
59
7d5c637aaafb
General cleanup and code fixes.
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
212 if (pst_open(&pstfile, argv[optind])) DIE(("Error opening File\n")); |
16 | 213 |
43 | 214 // Load PST index |
215 if (pst_load_index(&pstfile)) DIE(("Index Error\n")); | |
216 | |
217 pst_load_extended_attributes(&pstfile); | |
16 | 218 |
43 | 219 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
|
220 item = pst_parse_item(&pstfile, d_ptr, NULL); |
43 | 221 if (!item || !item->message_store) { |
222 DEBUG_RET(); | |
223 DIE(("main: Could not get root record\n")); | |
224 } | |
16 | 225 |
43 | 226 // 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
|
227 if (!item->file_as.str) { |
43 | 228 if (!(temp = strrchr(argv[1], '/'))) |
229 if (!(temp = strrchr(argv[1], '\\'))) | |
230 temp = argv[1]; | |
231 else | |
232 temp++; // get past the "\\" | |
233 else | |
234 temp++; // get past the "/" | |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
235 item->file_as.str = (char*)xmalloc(strlen(temp)+1); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
236 strcpy(item->file_as.str, temp); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
237 item->file_as.is_utf8 = 1; |
43 | 238 } |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
150
diff
changeset
|
239 WARN(("item->file_as = '%s'.\n", item->file_as.str)); |
16 | 240 |
43 | 241 d_ptr = pst_getTopOfFolders(&pstfile, item); |
242 if (!d_ptr) DIE(("Top of folders record not found. Cannot continue\n")); | |
243 DEBUG_MAIN(("d_ptr(TOF) = %p.\n", d_ptr)); | |
16 | 244 |
43 | 245 process(item, d_ptr->child); // do the childred of TOPF |
46 | 246 pst_freeItem(item); |
43 | 247 pst_close(&pstfile); |
16 | 248 |
43 | 249 DEBUG_RET(); |
250 return 0; | |
16 | 251 } |
43 | 252 |
253 | |
254 // This function will make sure that a filename is in cannonical form. That | |
16 | 255 // is, it will replace any slashes, backslashes, or colons with underscores. |
256 void canonicalize_filename(char *fname) { | |
43 | 257 DEBUG_ENT("canonicalize_filename"); |
258 if (fname == NULL) { | |
259 DEBUG_RET(); | |
260 return; | |
261 } | |
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
|
262 while ((fname = strpbrk(fname, "/\\:"))) |
43 | 263 *fname = '_'; |
264 DEBUG_RET(); | |
16 | 265 } |
43 | 266 |
267 |