Mercurial > libpst
comparison src/lspst.c @ 31:b88ceb81dba2
mege changes from Joe Nahmias
author | carl |
---|---|
date | Tue, 10 Jul 2007 17:17:28 -0700 |
parents | c508ee15dfca |
children | f6db1f060a95 |
comparison
equal
deleted
inserted
replaced
30:45eccad4b606 | 31:b88ceb81dba2 |
---|---|
35 int chr_count(char *str, char x); | 35 int chr_count(char *str, char x); |
36 void debug_print(char *fmt, ...); | 36 void debug_print(char *fmt, ...); |
37 char *rfc2426_escape(char *str); | 37 char *rfc2426_escape(char *str); |
38 char *rfc2445_datetime_format(FILETIME *ft); | 38 char *rfc2445_datetime_format(FILETIME *ft); |
39 // }}}1 | 39 // }}}1 |
40 #ifndef DEBUG_MAIN | 40 #ifndef LSPST_DEBUG_MAIN |
41 #define DEBUG_MAIN(x) debug_print x; | 41 #define LSPST_DEBUG_MAIN(x) debug_print x; |
42 #endif | 42 #endif |
43 // int main(int argc, char** argv) {{{1 | 43 // int main(int argc, char** argv) {{{1 |
44 int main(int argc, char** argv) { | 44 int main(int argc, char** argv) { |
45 | 45 |
46 // declarations {{{2 | 46 // declarations {{{2 |
47 pst_item *item = NULL; | 47 pst_item *item = NULL; |
48 pst_file pstfile; | 48 pst_file pstfile; |
49 pst_desc_ll *d_ptr; | 49 pst_desc_ll *d_ptr; |
50 char *temp = NULL; //temporary char pointer | 50 char *temp = NULL; //temporary char pointer |
51 int skip_child = 0; | 51 int skip_child = 0; |
52 struct file_ll *f, *head; | 52 struct file_ll *f = NULL, *head = NULL; |
53 // }}}2 | 53 // }}}2 |
54 | 54 |
55 if (argc <= 1) | 55 if (argc <= 1) |
56 DIE(("Missing PST filename.\n")); | 56 DIE(("Missing PST filename.\n")); |
57 | 57 |
90 head->next = NULL; | 90 head->next = NULL; |
91 head->name = "mbox"; | 91 head->name = "mbox"; |
92 head->dname = (char*) malloc(strlen(item->file_as)+1); | 92 head->dname = (char*) malloc(strlen(item->file_as)+1); |
93 strcpy(head->dname, item->file_as); | 93 strcpy(head->dname, item->file_as); |
94 head->type = item->type; | 94 head->type = item->type; |
95 DEBUG_MAIN(("head @ %p: name = '%s', dname = '%s', next = %p.\n", head, head->name, head->dname, head->next)); | 95 LSPST_DEBUG_MAIN(("head @ %p: name = '%s', dname = '%s', next = %p.\n", head, head->name, head->dname, head->next)); |
96 | 96 |
97 if ((d_ptr = pst_getTopOfFolders(&pstfile, item)) == NULL) { | 97 if ((d_ptr = pst_getTopOfFolders(&pstfile, item)) == NULL) { |
98 DIE(("Top of folders record not found. Cannot continue\n")); | 98 DIE(("Top of folders record not found. Cannot continue\n")); |
99 } | 99 } |
100 DEBUG_MAIN(("d_ptr(TOF) = %p.\n", d_ptr)); | 100 LSPST_DEBUG_MAIN(("d_ptr(TOF) = %p.\n", d_ptr)); |
101 | 101 |
102 if (item){ | 102 if (item){ |
103 _pst_freeItem(item); | 103 _pst_freeItem(item); |
104 item = NULL; | 104 item = NULL; |
105 } | 105 } |
106 | 106 |
107 d_ptr = d_ptr->child; // do the children of TOPF | 107 d_ptr = d_ptr->child; // do the children of TOPF |
108 DEBUG_MAIN(("d_ptr(TOF->child) = %p.\n", d_ptr)); | 108 LSPST_DEBUG_MAIN(("d_ptr(TOF->child) = %p.\n", d_ptr)); |
109 | 109 |
110 DEBUG_MAIN(("main: About to do email stuff\n")); | 110 LSPST_DEBUG_MAIN(("main: About to do email stuff\n")); |
111 while (d_ptr != NULL) { | 111 while (d_ptr != NULL) { |
112 // Process d_ptr {{{2 | 112 // Process d_ptr {{{2 |
113 DEBUG_MAIN(("main: New item record, d_ptr = %p.\n", d_ptr)); | 113 LSPST_DEBUG_MAIN(("main: New item record, d_ptr = %p.\n", d_ptr)); |
114 if (d_ptr->desc == NULL) { | 114 if (d_ptr->desc == NULL) { |
115 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n")); | 115 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n")); |
116 f->skip_count++; | 116 f->skip_count++; |
117 goto check_parent; | 117 goto check_parent; |
118 } | 118 } |
119 DEBUG_MAIN(("main: Desc Email ID %x [d_ptr->id = %x]\n", d_ptr->desc->id, d_ptr->id)); | 119 LSPST_DEBUG_MAIN(("main: Desc Email ID %x [d_ptr->id = %x]\n", d_ptr->desc->id, d_ptr->id)); |
120 | 120 |
121 item = _pst_parse_item(&pstfile, d_ptr); | 121 item = _pst_parse_item(&pstfile, d_ptr); |
122 DEBUG_MAIN(("main: About to process item @ %p.\n", item)); | 122 LSPST_DEBUG_MAIN(("main: About to process item @ %p.\n", item)); |
123 if (item != NULL) { | 123 if (item != NULL) { |
124 | 124 |
125 // there should only be one message_store, and we have already | 125 // there should only be one message_store, and we have already |
126 // done it | 126 // done it |
127 if (item->message_store != NULL) { | 127 if (item->message_store != NULL) { |
134 printf("Folder"); | 134 printf("Folder"); |
135 if (item->file_as != NULL) | 135 if (item->file_as != NULL) |
136 printf("\t%s/", item->file_as); | 136 printf("\t%s/", item->file_as); |
137 printf("\n"); | 137 printf("\n"); |
138 | 138 |
139 DEBUG_MAIN(("main: I think I may try to go into folder \"%s\"\n", item->file_as)); | 139 LSPST_DEBUG_MAIN(("main: I think I may try to go into folder \"%s\"\n", item->file_as)); |
140 f = (struct file_ll*) malloc(sizeof(struct file_ll)); | 140 f = (struct file_ll*) malloc(sizeof(struct file_ll)); |
141 memset(f, 0, sizeof(struct file_ll)); | 141 memset(f, 0, sizeof(struct file_ll)); |
142 f->next = head; | 142 f->next = head; |
143 f->email_count = 0; | 143 f->email_count = 0; |
144 f->type = item->type; | 144 f->type = item->type; |
146 head = f; | 146 head = f; |
147 f->name = "mbox"; | 147 f->name = "mbox"; |
148 f->dname = (char*) xmalloc(strlen(item->file_as)+1); | 148 f->dname = (char*) xmalloc(strlen(item->file_as)+1); |
149 strcpy(f->dname, item->file_as); | 149 strcpy(f->dname, item->file_as); |
150 | 150 |
151 DEBUG_MAIN(("main: f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as)); | 151 LSPST_DEBUG_MAIN(("main: f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as)); |
152 canonicalize_filename(f->name); | 152 canonicalize_filename(f->name); |
153 | 153 |
154 if (d_ptr->child != NULL) { | 154 if (d_ptr->child != NULL) { |
155 d_ptr = d_ptr->child; | 155 d_ptr = d_ptr->child; |
156 skip_child = 1; | 156 skip_child = 1; |
157 } else { | 157 } else { |
158 DEBUG_MAIN(("main: Folder has NO children. Creating directory, and closing again\n")); | 158 LSPST_DEBUG_MAIN(("main: Folder has NO children. Creating directory, and closing again\n")); |
159 // printf("\tNo items to process in folder \"%s\", should have been %i\n", f->dname, f->stored_count); | 159 // printf("\tNo items to process in folder \"%s\", should have been %i\n", f->dname, f->stored_count); |
160 head = f->next; | 160 head = f->next; |
161 if (f->output != NULL) | 161 if (f->output != NULL) |
162 fclose(f->output); | 162 fclose(f->output); |
163 free(f->dname); | 163 free(f->dname); |
171 goto check_parent; | 171 goto check_parent; |
172 // }}}3 | 172 // }}}3 |
173 } else if (item->contact != NULL) { | 173 } else if (item->contact != NULL) { |
174 // Process Contact item {{{3 | 174 // Process Contact item {{{3 |
175 if (f->type != PST_TYPE_CONTACT) { | 175 if (f->type != PST_TYPE_CONTACT) { |
176 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. " | 176 LSPST_DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. " |
177 "Will process anyway\n")); | 177 "Will process anyway\n")); |
178 } | 178 } |
179 if (item->type != PST_TYPE_CONTACT) { | 179 if (item->type != PST_TYPE_CONTACT) { |
180 DEBUG_MAIN(("main: I have an item that has contact info, but doesn't say that" | 180 LSPST_DEBUG_MAIN(("main: I have an item that has contact info, but doesn't say that" |
181 " it is a contact. Type is \"%s\"\n", item->ascii_type)); | 181 " it is a contact. Type is \"%s\"\n", item->ascii_type)); |
182 DEBUG_MAIN(("main: Processing anyway\n")); | 182 LSPST_DEBUG_MAIN(("main: Processing anyway\n")); |
183 } | 183 } |
184 | 184 |
185 printf("Contact"); | 185 printf("Contact"); |
186 if (item->contact->fullname != NULL) | 186 if (item->contact->fullname != NULL) |
187 printf("\t%s", rfc2426_escape(item->contact->fullname)); | 187 printf("\t%s", rfc2426_escape(item->contact->fullname)); |
198 printf("\n"); | 198 printf("\n"); |
199 // }}}3 | 199 // }}}3 |
200 } else if (item->type == PST_TYPE_JOURNAL) { | 200 } else if (item->type == PST_TYPE_JOURNAL) { |
201 // Process Journal item {{{3 | 201 // Process Journal item {{{3 |
202 if (f->type != PST_TYPE_JOURNAL) { | 202 if (f->type != PST_TYPE_JOURNAL) { |
203 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n")); | 203 LSPST_DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n")); |
204 } | 204 } |
205 | 205 |
206 printf("Journal\t%s\n", rfc2426_escape(item->email->subject->subj)); | 206 printf("Journal\t%s\n", rfc2426_escape(item->email->subject->subj)); |
207 // }}}3 | 207 // }}}3 |
208 } else if (item->type == PST_TYPE_APPOINTMENT) { | 208 } else if (item->type == PST_TYPE_APPOINTMENT) { |
209 // Process Calendar Appointment item {{{3 | 209 // Process Calendar Appointment item {{{3 |
210 // deal with Calendar appointments | 210 // deal with Calendar appointments |
211 | 211 |
212 DEBUG_MAIN(("main: Processing Appointment Entry\n")); | 212 LSPST_DEBUG_MAIN(("main: Processing Appointment Entry\n")); |
213 if (f->type != PST_TYPE_APPOINTMENT) { | 213 if (f->type != PST_TYPE_APPOINTMENT) { |
214 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n")); | 214 LSPST_DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n")); |
215 } | 215 } |
216 | 216 |
217 printf("Appointment"); | 217 printf("Appointment"); |
218 if (item->email != NULL && item->email->subject != NULL) | 218 if (item->email != NULL && item->email->subject != NULL) |
219 printf("\tSUMMARY: %s", rfc2426_escape(item->email->subject->subj)); | 219 printf("\tSUMMARY: %s", rfc2426_escape(item->email->subject->subj)); |
220 if (item->appointment != NULL && item->appointment->start != NULL) | 220 if (item->appointment != NULL) { |
221 printf("\tSTART: %s", rfc2445_datetime_format(item->appointment->start)); | 221 if (item->appointment->start != NULL) |
222 printf("\tSTART: %s", rfc2445_datetime_format(item->appointment->start)); | |
223 if (item->appointment->end != NULL) | |
224 printf("\tEND: %s", rfc2445_datetime_format(item->appointment->end)); | |
225 printf("\tALL DAY: %s", (item->appointment->all_day==1 ? "Yes" : "No")); | |
226 } | |
222 printf("\n"); | 227 printf("\n"); |
223 | 228 |
224 // }}}3 | 229 // }}}3 |
225 } else { | 230 } else { |
226 f->skip_count++; | 231 f->skip_count++; |
227 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", \ | 232 LSPST_DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", \ |
228 item->type, item->ascii_type)); | 233 item->type, item->ascii_type)); |
229 } | 234 } |
230 } else { | 235 } else { |
231 f->skip_count++; | 236 f->skip_count++; |
232 DEBUG_MAIN(("main: A NULL item was seen\n")); | 237 LSPST_DEBUG_MAIN(("main: A NULL item was seen\n")); |
233 } | 238 } |
234 | 239 |
235 check_parent: | 240 check_parent: |
236 // _pst_freeItem(item); | 241 // _pst_freeItem(item); |
237 while (!skip_child && d_ptr->next == NULL && d_ptr->parent != NULL) { | 242 while (!skip_child && d_ptr->next == NULL && d_ptr->parent != NULL) { |
238 DEBUG_MAIN(("main: Going to Parent\n")); | 243 LSPST_DEBUG_MAIN(("main: Going to Parent\n")); |
239 head = f->next; | 244 head = f->next; |
240 if (f->output != NULL) | 245 if (f->output != NULL) |
241 fclose(f->output); | 246 fclose(f->output); |
242 DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count)); | 247 LSPST_DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count)); |
243 /* | 248 /* |
244 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n", \ | 249 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n", \ |
245 f->dname, f->email_count, f->skip_count, f->stored_count); | 250 f->dname, f->email_count, f->skip_count, f->stored_count); |
246 */ | 251 */ |
247 | 252 |
248 free(f->name); | 253 free(f->name); |
249 free(f->dname); | 254 free(f->dname); |
250 free(f); | 255 free(f); |
251 f = head; | 256 f = head; |
252 if (head == NULL) { //we can't go higher. Must be at start? | 257 if (head == NULL) { //we can't go higher. Must be at start? |
253 DEBUG_MAIN(("main: We are now trying to go above the highest level. We must be finished\n")); | 258 LSPST_DEBUG_MAIN(("main: We are now trying to go above the highest level. We must be finished\n")); |
254 break; //from main while loop | 259 break; //from main while loop |
255 } | 260 } |
256 d_ptr = d_ptr->parent; | 261 d_ptr = d_ptr->parent; |
257 skip_child = 0; | 262 skip_child = 0; |
258 } | 263 } |
259 | 264 |
260 if (item != NULL) { | 265 if (item != NULL) { |
261 DEBUG_MAIN(("main: Freeing memory used by item\n")); | 266 LSPST_DEBUG_MAIN(("main: Freeing memory used by item\n")); |
262 _pst_freeItem(item); | 267 _pst_freeItem(item); |
263 item = NULL; | 268 item = NULL; |
264 } | 269 } |
265 | 270 |
266 if (!skip_child) | 271 if (!skip_child) |
267 d_ptr = d_ptr->next; | 272 d_ptr = d_ptr->next; |
268 else | 273 else |
269 skip_child = 0; | 274 skip_child = 0; |
270 | 275 |
271 if (d_ptr == NULL) { DEBUG_MAIN(("main: d_ptr is now NULL\n")); } | 276 if (d_ptr == NULL) { LSPST_DEBUG_MAIN(("main: d_ptr is now NULL\n")); } |
272 | 277 |
273 // }}}2 | 278 // }}}2 |
274 } // end while(d_ptr != NULL) | 279 } // end while(d_ptr != NULL) |
275 DEBUG_MAIN(("main: Finished.\n")); | 280 LSPST_DEBUG_MAIN(("main: Finished.\n")); |
276 | 281 |
277 // Cleanup {{{2 | 282 // Cleanup {{{2 |
278 pst_close(&pstfile); | 283 pst_close(&pstfile); |
279 while (f != NULL) { | 284 while (f != NULL) { |
280 if (f->output != NULL) | 285 if (f->output != NULL) |