comparison src/readpst.c @ 39:2ad7ef0a3c4f stable-0-5-10

more valgrind fixes
author carl
date Mon, 20 Aug 2007 20:43:17 -0700
parents f5c024aa1dc5
children 183ae993b9ad
comparison
equal deleted inserted replaced
38:f5c024aa1dc5 39:2ad7ef0a3c4f
58 FILE * output; 58 FILE * output;
59 int32_t stored_count; 59 int32_t stored_count;
60 int32_t email_count; 60 int32_t email_count;
61 int32_t skip_count; 61 int32_t skip_count;
62 int32_t type; 62 int32_t type;
63 struct file_ll *next;
64 }; 63 };
65 64
65 void process(pst_item *outeritem, pst_desc_ll *d_ptr);
66 void write_email_body(FILE *f, char *body); 66 void write_email_body(FILE *f, char *body);
67 char* removeCR (char *c); 67 char* removeCR (char *c);
68 int32_t usage(); 68 int32_t usage();
69 int32_t version(); 69 int32_t version();
70 char* mk_kmail_dir(char*); 70 char* mk_kmail_dir(char*);
71 int32_t close_kmail_dir(); 71 int32_t close_kmail_dir();
72 char* mk_recurse_dir(char*); 72 char* mk_recurse_dir(char*);
73 int32_t close_recurse_dir(); 73 int32_t close_recurse_dir();
74 char* mk_seperate_dir(char *dir, int overwrite); 74 char* mk_seperate_dir(char *dir);
75 int32_t close_seperate_dir(); 75 int32_t close_seperate_dir();
76 int32_t mk_seperate_file(struct file_ll *f); 76 int32_t mk_seperate_file(struct file_ll *f);
77 char* my_stristr(char *haystack, char *needle); 77 char* my_stristr(char *haystack, char *needle);
78 char* check_filename(char *fname); 78 char* check_filename(char *fname);
79 char* rfc2426_escape(char *str); 79 char* rfc2426_escape(char *str);
85 void write_inline_attachment(FILE* f_output, pst_item_attach* current_attach, char boundary[], pst_file* pst); 85 void write_inline_attachment(FILE* f_output, pst_item_attach* current_attach, char boundary[], pst_file* pst);
86 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf); 86 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf);
87 void write_vcard(FILE* f_output, pst_item_contact* contact, char comment[]); 87 void write_vcard(FILE* f_output, pst_item_contact* contact, char comment[]);
88 void write_appointment(FILE* f_output, pst_item_appointment* appointment, 88 void write_appointment(FILE* f_output, pst_item_appointment* appointment,
89 pst_item_email* email, FILETIME* create_date, FILETIME* modify_date); 89 pst_item_email* email, FILETIME* create_date, FILETIME* modify_date);
90 void create_enter_dir(struct file_ll* f, char file_as[], int mode, int overwrite); 90 void create_enter_dir(struct file_ll* f, pst_item *item);
91 void close_enter_dir(struct file_ll *f);
91 92
92 char* prog_name; 93 char* prog_name;
93 char* output_dir = "."; 94 char* output_dir = ".";
94 char* kmail_chdir = NULL; 95 char* kmail_chdir = NULL;
95 // Normal mode just creates mbox format files in the current directory. Each file is named 96 // Normal mode just creates mbox format files in the current directory. Each file is named
123 // filename for the attachment 124 // filename for the attachment
124 #define RTF_ATTACH_NAME "rtf-body.rtf" 125 #define RTF_ATTACH_NAME "rtf-body.rtf"
125 // mime type for the attachment 126 // mime type for the attachment
126 #define RTF_ATTACH_TYPE "application/rtf" 127 #define RTF_ATTACH_TYPE "application/rtf"
127 128
129 // global settings
130 int mode = MODE_NORMAL;
131 int mode_MH = 0;
132 int output_mode = OUTPUT_NORMAL;
133 int contact_mode = CMODE_VCARD;
134 int overwrite = 0;
135 int save_rtf_body = 1;
136 pst_file pstfile;
137
138
139
140 void process(pst_item *outeritem, pst_desc_ll *d_ptr)
141 {
142 struct file_ll ff;
143 pst_item *item = NULL;
144
145 DEBUG_ENT("process");
146 memset(&ff, 0, sizeof(ff));
147 create_enter_dir(&ff, outeritem);
148
149 while (d_ptr) {
150 DEBUG_MAIN(("main: New item record\n"));
151 if (!d_ptr->desc) {
152 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n"));
153 ff.skip_count++;
154 }
155 else {
156 DEBUG_MAIN(("main: Desc Email ID %#x [d_ptr->id = %#x]\n", d_ptr->desc->id, d_ptr->id));
157
158 item = _pst_parse_item(&pstfile, d_ptr);
159 DEBUG_MAIN(("main: About to process item\n"));
160 if (item && item->email && item->email->subject && item->email->subject->subj) {
161 DEBUG_EMAIL(("item->email->subject = %p\n", item->email->subject));
162 DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
163 }
164 if (item) {
165 if (item->message_store) {
166 // there should only be one message_store, and we have already done it
167 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
168 }
169
170 if (item->folder && d_ptr->child && strcasecmp(item->file_as, "Deleted Items")) {
171 //if this is a non-empty folder other than deleted items, we want to recurse into it
172 if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as);
173 process(item, d_ptr->child);
174
175 } else if (item->contact) {
176 // deal with a contact
177 // write them to the file, one per line in this format
178 // Desc Name <email@address>\n
179 if (mode == MODE_SEPERATE) mk_seperate_file(&ff);
180 ff.email_count++;
181 DEBUG_MAIN(("main: Processing Contact\n"));
182 if (ff.type != PST_TYPE_CONTACT) {
183 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. "
184 "Will process anyway\n"));
185 }
186 if (item->type != PST_TYPE_CONTACT) {
187 DEBUG_MAIN(("main: I have an item that has contact info, but doesn't say that"
188 " it is a contact. Type is \"%s\"\n", item->ascii_type));
189 DEBUG_MAIN(("main: Processing anyway\n"));
190 }
191 if (!item->contact) { // this is an incorrect situation. Inform user
192 DEBUG_MAIN(("main: ERROR. This contact has not been fully parsed. one of the pre-requisties is NULL\n"));
193 } else {
194 if (contact_mode == CMODE_VCARD)
195 write_vcard(ff.output, item->contact, item->comment);
196 else
197 fprintf(ff.output, "%s <%s>\n", item->contact->fullname, item->contact->address1);
198 }
199
200 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
201 if (mode == MODE_SEPERATE) mk_seperate_file(&ff);
202 ff.email_count++;
203 DEBUG_MAIN(("main: seen an email\n"));
204 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body);
205
206 } else if (item->type == PST_TYPE_JOURNAL) {
207 // deal with journal items
208 if (mode == MODE_SEPERATE) mk_seperate_file(&ff);
209 ff.email_count++;
210
211 DEBUG_MAIN(("main: Processing Journal Entry\n"));
212 if (ff.type != PST_TYPE_JOURNAL) {
213 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
214 }
215
216 /* if (item->type != PST_TYPE_JOURNAL) {
217 DEBUG_MAIN(("main: I have an item with journal info, but it's type is \"%s\" \n. Processing...\n",
218 item->ascii_type));
219 }*/
220 fprintf(ff.output, "BEGIN:VJOURNAL\n");
221 if (item->email->subject)
222 fprintf(ff.output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
223 if (item->email->body)
224 fprintf(ff.output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
225 if (item->journal->start)
226 fprintf(ff.output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start));
227 fprintf(ff.output, "END:VJOURNAL\n\n");
228
229 } else if (item->type == PST_TYPE_APPOINTMENT) {
230 // deal with Calendar appointments
231 if (mode == MODE_SEPERATE) mk_seperate_file(&ff);
232 ff.email_count++;
233 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
234 if (ff.type != PST_TYPE_APPOINTMENT) {
235 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
236 }
237 write_appointment(ff.output, item->appointment, item->email, item->create_date, item->modify_date);
238
239 } else {
240 ff.skip_count++;
241 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
242 item->type, item->ascii_type));
243 }
244 _pst_freeItem(item);
245 } else {
246 ff.skip_count++;
247 DEBUG_MAIN(("main: A NULL item was seen\n"));
248 }
249 d_ptr = d_ptr->next;
250 }
251 }
252 close_enter_dir(&ff);
253 DEBUG_RET();
254 }
255
256
128 257
129 int main(int argc, char** argv) { 258 int main(int argc, char** argv) {
130 pst_item *item = NULL; 259 pst_item *item = NULL;
131 pst_file pstfile;
132 pst_desc_ll *d_ptr; 260 pst_desc_ll *d_ptr;
133 char * fname = NULL; 261 char * fname = NULL;
134 char *d_log=NULL; 262 char *d_log=NULL;
135 int c,x; 263 int c,x;
136 int mode = MODE_NORMAL;
137 int mode_MH = 0;
138 int output_mode = OUTPUT_NORMAL;
139 int contact_mode = CMODE_VCARD;
140 int overwrite = 0;
141 char *enc = NULL; // base64 encoded attachment
142 char *boundary = NULL, *b1, *b2; // the boundary marker between multipart sections
143 char *temp = NULL; //temporary char pointer 264 char *temp = NULL; //temporary char pointer
144 char *attach_filename = NULL;
145 int skip_child = 0;
146 struct file_ll *f, *head;
147 int save_rtf_body = 1;
148 prog_name = argv[0]; 265 prog_name = argv[0];
149 266
150 // command-line option handling 267 // command-line option handling
151 while ((c = getopt(argc, argv, "bd:hko:qrMSVwc:"))!= -1) { 268 while ((c = getopt(argc, argv, "bd:hko:qrMSVwc:"))!= -1) {
152 switch (c) { 269 switch (c) {
201 exit(1); 318 exit(1);
202 break; 319 break;
203 } 320 }
204 } 321 }
205 322
206 #ifdef DEBUG_ALL
207 // force a log file
208 if (!d_log) d_log = "readpst.log";
209 #endif // defined DEBUG_ALL
210 DEBUG_INIT(d_log);
211 DEBUG_REGISTER_CLOSE();
212 DEBUG_ENT("main");
213
214 if (argc > optind) { 323 if (argc > optind) {
215 fname = argv[optind]; 324 fname = argv[optind];
216 } else { 325 } else {
217 usage(); 326 usage();
218 exit(2); 327 exit(2);
219 } 328 }
220 329
330 #ifdef DEBUG_ALL
331 // force a log file
332 if (!d_log) d_log = "readpst.log";
333 #endif // defined DEBUG_ALL
334 DEBUG_INIT(d_log);
335 DEBUG_REGISTER_CLOSE();
336 DEBUG_ENT("main");
337
221 if (output_mode != OUTPUT_QUIET) printf("Opening PST file and indexes...\n"); 338 if (output_mode != OUTPUT_QUIET) printf("Opening PST file and indexes...\n");
222 339
223 DEBUG_MAIN(("main: Opening PST file '%s'\n", fname));
224 RET_DERROR(pst_open(&pstfile, fname, "r"), 1, ("Error opening File\n")); 340 RET_DERROR(pst_open(&pstfile, fname, "r"), 1, ("Error opening File\n"));
225 DEBUG_MAIN(("main: Loading Indexes\n"));
226 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n")); 341 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
227 DEBUG_MAIN(("processing file items\n"));
228 342
229 pst_load_extended_attributes(&pstfile); 343 pst_load_extended_attributes(&pstfile);
230 344
231 if (chdir(output_dir)) { 345 if (chdir(output_dir)) {
232 x = errno; 346 x = errno;
233 pst_close(&pstfile); 347 pst_close(&pstfile);
348 DEBUG_RET();
234 DIE(("main: Cannot change to output dir %s: %s\n", output_dir, strerror(x))); 349 DIE(("main: Cannot change to output dir %s: %s\n", output_dir, strerror(x)));
235 } 350 }
236 351
237 if (output_mode != OUTPUT_QUIET) printf("About to start processing first record...\n"); 352 if (output_mode != OUTPUT_QUIET) printf("About to start processing first record...\n");
238 353
239 d_ptr = pstfile.d_head; // first record is main record 354 d_ptr = pstfile.d_head; // first record is main record
240 if (!(item = _pst_parse_item(&pstfile, d_ptr)) || !item->message_store) { 355 item = (pst_item*)_pst_parse_item(&pstfile, d_ptr);
356 if (!item || !item->message_store) {
357 DEBUG_RET();
241 DIE(("main: Could not get root record\n")); 358 DIE(("main: Could not get root record\n"));
242 } 359 }
243 360
244 // default the file_as to the same as the main filename if it doesn't exist 361 // default the file_as to the same as the main filename if it doesn't exist
245 if (!item->file_as) { 362 if (!item->file_as) {
254 strcpy(item->file_as, temp); 371 strcpy(item->file_as, temp);
255 DEBUG_MAIN(("file_as was blank, so am using %s\n", item->file_as)); 372 DEBUG_MAIN(("file_as was blank, so am using %s\n", item->file_as));
256 } 373 }
257 DEBUG_MAIN(("main: Root Folder Name: %s\n", item->file_as)); 374 DEBUG_MAIN(("main: Root Folder Name: %s\n", item->file_as));
258 375
259 376 d_ptr = pst_getTopOfFolders(&pstfile, item);
260 f = (struct file_ll*) malloc(sizeof(struct file_ll)); 377 if (!d_ptr) {
261 memset(f, 0, sizeof(struct file_ll)); 378 DEBUG_RET();
262 f->email_count = 0;
263 f->skip_count = 0;
264 f->next = NULL;
265 head = f;
266 create_enter_dir(f, item->file_as, mode, overwrite);
267 f->type = item->type;
268
269 if (!(d_ptr = pst_getTopOfFolders(&pstfile, item))) {
270 DIE(("Top of folders record not found. Cannot continue\n")); 379 DIE(("Top of folders record not found. Cannot continue\n"));
271 } 380 }
272 381
273 if (item){ 382 process(item, d_ptr->child); // do the children of TOPF
274 _pst_freeItem(item); 383 _pst_freeItem(item);
275 item = NULL;
276 }
277
278 d_ptr = d_ptr->child; // do the children of TOPF
279
280 if (output_mode != OUTPUT_QUIET) printf("Processing items...\n");
281
282 DEBUG_MAIN(("main: About to do email stuff\n"));
283 while (d_ptr) {
284 DEBUG_MAIN(("main: New item record\n"));
285 if (!d_ptr->desc) {
286 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n"));
287 f->skip_count++;
288 goto check_parent;
289 }
290 DEBUG_MAIN(("main: Desc Email ID %#x [d_ptr->id = %#x]\n", d_ptr->desc->id, d_ptr->id));
291
292 item = _pst_parse_item(&pstfile, d_ptr);
293 DEBUG_MAIN(("main: About to process item\n"));
294 if (item && item->email && item->email->subject && item->email->subject->subj) {
295 DEBUG_EMAIL(("item->email->subject = %p\n", item->email->subject));
296 DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
297 }
298 if (item) {
299 if (item->message_store) {
300 // there should only be one message_store, and we have already done it
301 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
302 }
303
304 if (item->folder) {
305 // if this is a folder, we want to recurse into it
306 if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as);
307 // f->email_count++;
308 DEBUG_MAIN(("main: I think I may try to go into folder \"%s\"\n", item->file_as));
309 f = (struct file_ll*) malloc(sizeof(struct file_ll));
310 memset(f, 0, sizeof(struct file_ll));
311
312 f->next = head;
313 f->email_count = 0;
314 f->type = item->type;
315 f->stored_count = item->folder->email_count;
316 head = f;
317
318 temp = item->file_as;
319 temp = check_filename(temp);
320 create_enter_dir(f, item->file_as, mode, overwrite);
321 if (d_ptr->child) {
322 d_ptr = d_ptr->child;
323 skip_child = 1;
324 } else {
325 DEBUG_MAIN(("main: Folder has NO children. Creating directory, and closing again\n"));
326 if (output_mode != OUTPUT_QUIET) printf("\tNo items to process in folder \"%s\", should have been %i\n", f->dname, f->stored_count);
327 head = f->next;
328 if (f->output)
329 fclose(f->output);
330 if (mode == MODE_KMAIL)
331 close_kmail_dir();
332 else if (mode == MODE_RECURSE)
333 close_recurse_dir();
334 else if (mode == MODE_SEPERATE)
335 close_seperate_dir();
336 free(f->dname);
337 free(f->name);
338 free(f);
339
340 f = head;
341 }
342 _pst_freeItem(item);
343 item = NULL;
344 goto check_parent;
345 } else if (item->contact) {
346 // deal with a contact
347 // write them to the file, one per line in this format
348 // Desc Name <email@address>\n
349 if (mode == MODE_SEPERATE) {
350 mk_seperate_file(f);
351 }
352 f->email_count++;
353
354 DEBUG_MAIN(("main: Processing Contact\n"));
355 if (f->type != PST_TYPE_CONTACT) {
356 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. "
357 "Will process anyway\n"));
358 }
359 if (item->type != PST_TYPE_CONTACT) {
360 DEBUG_MAIN(("main: I have an item that has contact info, but doesn't say that"
361 " it is a contact. Type is \"%s\"\n", item->ascii_type));
362 DEBUG_MAIN(("main: Processing anyway\n"));
363 }
364 if (!item->contact) { // this is an incorrect situation. Inform user
365 DEBUG_MAIN(("main: ERROR. This contact has not been fully parsed. one of the pre-requisties is NULL\n"));
366 } else {
367 if (contact_mode == CMODE_VCARD)
368 write_vcard(f->output, item->contact, item->comment);
369 else
370 fprintf(f->output, "%s <%s>\n", item->contact->fullname, item->contact->address1);
371 }
372 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
373 if (mode == MODE_SEPERATE) {
374 mk_seperate_file(f);
375 }
376
377 f->email_count++;
378
379 DEBUG_MAIN(("main: seen an email\n"));
380 write_normal_email(f->output, f->name, item, mode, mode_MH, &pstfile, save_rtf_body);
381 } else if (item->type == PST_TYPE_JOURNAL) {
382 // deal with journal items
383 if (mode == MODE_SEPERATE) {
384 mk_seperate_file(f);
385 }
386 f->email_count++;
387
388 DEBUG_MAIN(("main: Processing Journal Entry\n"));
389 if (f->type != PST_TYPE_JOURNAL) {
390 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
391 }
392
393 /* if (item->type != PST_TYPE_JOURNAL) {
394 DEBUG_MAIN(("main: I have an item with journal info, but it's type is \"%s\" \n. Processing...\n",
395 item->ascii_type));
396 }*/
397 fprintf(f->output, "BEGIN:VJOURNAL\n");
398 if (item->email->subject)
399 fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
400 if (item->email->body)
401 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
402 if (item->journal->start)
403 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start));
404 fprintf(f->output, "END:VJOURNAL\n\n");
405 } else if (item->type == PST_TYPE_APPOINTMENT) {
406 // deal with Calendar appointments
407 if (mode == MODE_SEPERATE) {
408 mk_seperate_file(f);
409 }
410 f->email_count++;
411
412 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
413 if (f->type != PST_TYPE_APPOINTMENT) {
414 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
415 }
416 write_appointment(f->output, item->appointment, item->email, item->create_date, item->modify_date);
417 } else {
418 f->skip_count++;
419 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
420 item->type, item->ascii_type));
421 }
422 } else {
423 f->skip_count++;
424 DEBUG_MAIN(("main: A NULL item was seen\n"));
425 }
426
427 DEBUG_MAIN(("main: Going to next d_ptr\n"));
428
429 check_parent:
430 // _pst_freeItem(item);
431 while (!skip_child && !d_ptr->next && d_ptr->parent) {
432 DEBUG_MAIN(("main: Going to Parent\n"));
433 head = f->next;
434 if (f->output) fclose(f->output);
435 DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count));
436 if (output_mode != OUTPUT_QUIET)
437 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n",
438 f->dname, f->email_count, f->skip_count, f->stored_count);
439 if (mode == MODE_KMAIL)
440 close_kmail_dir();
441 else if (mode == MODE_RECURSE)
442 close_recurse_dir();
443 else if (mode == MODE_SEPERATE)
444 close_seperate_dir();
445 free(f->name);
446 free(f->dname);
447 free(f);
448 f = head;
449 if (!head) { //we can't go higher. Must be at start?
450 DEBUG_MAIN(("main: We are now trying to go above the highest level. We must be finished\n"));
451 break; //from main while loop
452 }
453 d_ptr = d_ptr->parent;
454 skip_child = 0;
455 }
456
457 if (item) {
458 DEBUG_MAIN(("main: Freeing memory used by item\n"));
459 _pst_freeItem(item);
460 item = NULL;
461 }
462
463 if (!skip_child)
464 d_ptr = d_ptr->next;
465 else
466 skip_child = 0;
467
468 if (!d_ptr) {
469 DEBUG_MAIN(("main: d_ptr is now NULL\n"));
470 }
471 }
472 if (output_mode != OUTPUT_QUIET) printf("Finished.\n");
473 DEBUG_MAIN(("main: Finished.\n"));
474
475 pst_close(&pstfile); 384 pst_close(&pstfile);
476 // fclose(pstfile.fp); 385
477 while (f) { 386 DEBUG_RET();
478 if (f->output) fclose(f->output);
479 free(f->name);
480 free(f->dname);
481
482 if (mode == MODE_KMAIL)
483 close_kmail_dir();
484 else if (mode == MODE_RECURSE)
485 close_recurse_dir();
486 else if (mode == MODE_SEPERATE)
487 // DO SOMETHING HERE
488 ;
489 head = f->next;
490 free (f);
491 f = head;
492 }
493
494 DEBUG_RET();
495
496 return 0; 387 return 0;
497 } 388 }
498 389
499 390
500 void write_email_body(FILE *f, char *body) { 391 void write_email_body(FILE *f, char *body) {
665 DEBUG_RET(); 556 DEBUG_RET();
666 return 0; 557 return 0;
667 } 558 }
668 559
669 560
670 char *mk_seperate_dir(char *dir, int overwrite) { 561 char *mk_seperate_dir(char *dir) {
671 DEBUG_ENT("mk_seperate_dir"); 562 DEBUG_ENT("mk_seperate_dir");
672 #if !defined(WIN32) && !defined(__CYGWIN__) 563 #if !defined(WIN32) && !defined(__CYGWIN__)
673 DIR * sdir = NULL; 564 DIR * sdir = NULL;
674 struct dirent *dirent = NULL; 565 struct dirent *dirent = NULL;
675 struct stat *filestat = xmalloc(sizeof(struct stat)); 566 struct stat *filestat = xmalloc(sizeof(struct stat));
676 #endif 567 #endif
677 568
678 char *dir_name = NULL; 569 char *dir_name = NULL;
679 int x = 0, y = 0; 570 int x = 0, y = 0;
680 /*#if defined(WIN32) || defined(__CYGWIN__)
681 DIE(("mk_seperate_dir: Win32 applications cannot use this function yet.\n"));
682 #endif*/
683 571
684 dir_name = xmalloc(strlen(dir)+10); 572 dir_name = xmalloc(strlen(dir)+10);
685 573
686 do { 574 do {
687 if (y == 0) 575 if (y == 0)
724 } 612 }
725 } 613 }
726 #endif 614 #endif
727 } 615 }
728 616
729 // overwrite will never change during this function, it is just there so that
730 // if overwrite is set, we only go through this loop once.
731
732 // we don't return a filename here cause it isn't necessary. 617 // we don't return a filename here cause it isn't necessary.
733 DEBUG_RET(); 618 DEBUG_RET();
734 return NULL; 619 return NULL;
735 } 620 }
736 621
753 DEBUG_MAIN(("opening next file to save email\n")); 638 DEBUG_MAIN(("opening next file to save email\n"));
754 if (f->email_count > 999999999) { // bigger than nine 9's 639 if (f->email_count > 999999999) { // bigger than nine 9's
755 DIE(("mk_seperate_file: The number of emails in this folder has become too high to handle")); 640 DIE(("mk_seperate_file: The number of emails in this folder has become too high to handle"));
756 } 641 }
757 sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->email_count + name_offset); 642 sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->email_count + name_offset);
758 if (f->output) 643 if (f->output) fclose(f->output);
759 fclose(f->output);
760 f->output = NULL; 644 f->output = NULL;
761 f->name = check_filename(f->name); 645 f->name = check_filename(f->name);
762 if (!(f->output = fopen(f->name, "w"))) { 646 if (!(f->output = fopen(f->name, "w"))) {
763 DIE(("mk_seperate_file: Cannot open file to save email \"%s\"\n", f->name)); 647 DIE(("mk_seperate_file: Cannot open file to save email \"%s\"\n", f->name));
764 } 648 }
870 return r; 754 return r;
871 } 755 }
872 756
873 757
874 char *rfc2425_datetime_format(FILETIME *ft) { 758 char *rfc2425_datetime_format(FILETIME *ft) {
875 static char * buffer = NULL; 759 static char* buffer = NULL;
876 struct tm *stm = NULL; 760 struct tm *stm = NULL;
877 DEBUG_ENT("rfc2425_datetime_format"); 761 DEBUG_ENT("rfc2425_datetime_format");
878 if (!buffer) 762 if (!buffer) buffer = malloc(30); // should be enough for the date as defined below
879 buffer = malloc(30); // should be enough for the date as defined below
880
881 stm = fileTimeToStructTM(ft); 763 stm = fileTimeToStructTM(ft);
882 //Year[4]-Month[2]-Day[2] Hour[2]:Min[2]:Sec[2]
883 if (strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm)==0) { 764 if (strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm)==0) {
884 DEBUG_INFO(("Problem occured formatting date\n")); 765 DEBUG_INFO(("Problem occured formatting date\n"));
885 } 766 }
886 DEBUG_RET(); 767 DEBUG_RET();
887 return buffer; 768 return buffer;
890 771
891 char *rfc2445_datetime_format(FILETIME *ft) { 772 char *rfc2445_datetime_format(FILETIME *ft) {
892 static char* buffer = NULL; 773 static char* buffer = NULL;
893 struct tm *stm = NULL; 774 struct tm *stm = NULL;
894 DEBUG_ENT("rfc2445_datetime_format"); 775 DEBUG_ENT("rfc2445_datetime_format");
895 if (!buffer) 776 if (!buffer) buffer = malloc(30); // should be enough for the date as defined below
896 buffer = malloc(30); // should be enough
897 stm = fileTimeToStructTM(ft); 777 stm = fileTimeToStructTM(ft);
898 if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) { 778 if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) {
899 DEBUG_INFO(("Problem occured formatting date\n")); 779 DEBUG_INFO(("Problem occured formatting date\n"));
900 } 780 }
901 DEBUG_RET(); 781 DEBUG_RET();
1275 write_email_body(f_output, "The body of this email is encrypted. This isn't supported yet, but the body is now an attachment\n"); 1155 write_email_body(f_output, "The body of this email is encrypted. This isn't supported yet, but the body is now an attachment\n");
1276 } 1156 }
1277 1157
1278 // attachments 1158 // attachments
1279 attach_num = 0; 1159 attach_num = 0;
1280 for (current_attach = item->attach; 1160 for (current_attach = item->attach; current_attach; current_attach = current_attach->next) {
1281 current_attach;
1282 current_attach = current_attach->next) {
1283 DEBUG_EMAIL(("Attempting Attachment encoding\n")); 1161 DEBUG_EMAIL(("Attempting Attachment encoding\n"));
1284 if (!current_attach->data) { 1162 if (!current_attach->data) {
1285 DEBUG_EMAIL(("Data of attachment is NULL!. Size is supposed to be %i\n", current_attach->size)); 1163 DEBUG_EMAIL(("Data of attachment is NULL!. Size is supposed to be %i\n", current_attach->size));
1286 } 1164 }
1287 if (mode == MODE_SEPERATE && !mode_MH) 1165 if (mode == MODE_SEPERATE && !mode_MH)
1299 } 1177 }
1300 1178
1301 1179
1302 void write_vcard(FILE* f_output, pst_item_contact* contact, char comment[]) 1180 void write_vcard(FILE* f_output, pst_item_contact* contact, char comment[])
1303 { 1181 {
1182 // We can only call rfc escape once per printf, since the second call
1183 // may free the buffer returned by the first call.
1184 // I had tried to place those into a single printf - Carl.
1185
1304 DEBUG_ENT("write_vcard"); 1186 DEBUG_ENT("write_vcard");
1305 // the specification I am following is (hopefully) RFC2426 vCard Mime Directory Profile 1187 // the specification I am following is (hopefully) RFC2426 vCard Mime Directory Profile
1306 fprintf(f_output, "BEGIN:VCARD\n"); 1188 fprintf(f_output, "BEGIN:VCARD\n");
1307 fprintf(f_output, "FN:%s\n", rfc2426_escape(contact->fullname)); 1189 fprintf(f_output, "FN:%s\n", rfc2426_escape(contact->fullname));
1308 fprintf(f_output, "N:%s;%s;%s;%s;%s\n", 1190
1309 (!contact->surname) ? "" : rfc2426_escape(contact->surname), 1191 //fprintf(f_output, "N:%s;%s;%s;%s;%s\n",
1310 (!contact->first_name) ? "" : rfc2426_escape(contact->first_name), 1192 fprintf(f_output, "N:%s;", (!contact->surname) ? "" : rfc2426_escape(contact->surname));
1311 (!contact->middle_name) ? "" : rfc2426_escape(contact->middle_name), 1193 fprintf(f_output, "%s;", (!contact->first_name) ? "" : rfc2426_escape(contact->first_name));
1312 (!contact->display_name_prefix) ? "" : rfc2426_escape(contact->display_name_prefix), 1194 fprintf(f_output, "%s;", (!contact->middle_name) ? "" : rfc2426_escape(contact->middle_name));
1313 (!contact->suffix) ? "" : rfc2426_escape(contact->suffix)); 1195 fprintf(f_output, "%s;", (!contact->display_name_prefix) ? "" : rfc2426_escape(contact->display_name_prefix));
1196 fprintf(f_output, "%s\n", (!contact->suffix) ? "" : rfc2426_escape(contact->suffix));
1197
1314 if (contact->nickname) 1198 if (contact->nickname)
1315 fprintf(f_output, "NICKNAME:%s\n", rfc2426_escape(contact->nickname)); 1199 fprintf(f_output, "NICKNAME:%s\n", rfc2426_escape(contact->nickname));
1316 if (contact->address1) 1200 if (contact->address1)
1317 fprintf(f_output, "EMAIL:%s\n", rfc2426_escape(contact->address1)); 1201 fprintf(f_output, "EMAIL:%s\n", rfc2426_escape(contact->address1));
1318 if (contact->address2) 1202 if (contact->address2)
1319 fprintf(f_output, "EMAIL:%s\n", rfc2426_escape(contact->address2)); 1203 fprintf(f_output, "EMAIL:%s\n", rfc2426_escape(contact->address2));
1320 if (contact->address3) 1204 if (contact->address3)
1321 fprintf(f_output, "EMAIL:%s\n", rfc2426_escape(contact->address3)); 1205 fprintf(f_output, "EMAIL:%s\n", rfc2426_escape(contact->address3));
1322 if (contact->birthday) 1206 if (contact->birthday)
1323 fprintf(f_output, "BDAY:%s\n", rfc2425_datetime_format(contact->birthday)); 1207 fprintf(f_output, "BDAY:%s\n", rfc2425_datetime_format(contact->birthday));
1208
1324 if (contact->home_address) { 1209 if (contact->home_address) {
1325 fprintf(f_output, "ADR;TYPE=home:%s;%s;%s;%s;%s;%s;%s\n", 1210 //fprintf(f_output, "ADR;TYPE=home:%s;%s;%s;%s;%s;%s;%s\n",
1326 (!contact->home_po_box) ? "" : rfc2426_escape(contact->home_po_box), 1211 fprintf(f_output, "ADR;TYPE=home:%s;", (!contact->home_po_box) ? "" : rfc2426_escape(contact->home_po_box));
1327 "", // extended Address 1212 fprintf(f_output, "%s;", ""); // extended Address
1328 (!contact->home_street) ? "" : rfc2426_escape(contact->home_street), 1213 fprintf(f_output, "%s;", (!contact->home_street) ? "" : rfc2426_escape(contact->home_street));
1329 (!contact->home_city) ? "" : rfc2426_escape(contact->home_city), 1214 fprintf(f_output, "%s;", (!contact->home_city) ? "" : rfc2426_escape(contact->home_city));
1330 (!contact->home_state) ? "" : rfc2426_escape(contact->home_state), 1215 fprintf(f_output, "%s;", (!contact->home_state) ? "" : rfc2426_escape(contact->home_state));
1331 (!contact->home_postal_code) ? "" : rfc2426_escape(contact->home_postal_code), 1216 fprintf(f_output, "%s;", (!contact->home_postal_code) ? "" : rfc2426_escape(contact->home_postal_code));
1332 (!contact->home_country) ? "" : rfc2426_escape(contact->home_country)); 1217 fprintf(f_output, "%s\n", (!contact->home_country) ? "" : rfc2426_escape(contact->home_country));
1333 fprintf(f_output, "LABEL;TYPE=home:%s\n", rfc2426_escape(contact->home_address)); 1218 fprintf(f_output, "LABEL;TYPE=home:%s\n", rfc2426_escape(contact->home_address));
1334 } 1219 }
1220
1335 if (contact->business_address) { 1221 if (contact->business_address) {
1336 // these should be equivalent, but valgrind complains about the single large fprintf 1222 //fprintf(f_output, "ADR;TYPE=work:%s;%s;%s;%s;%s;%s;%s\n",
1337 // 1223 fprintf(f_output, "ADR;TYPE=work:%s;", (!contact->business_po_box) ? "" : rfc2426_escape(contact->business_po_box));
1338 char *ab = (!contact->business_po_box ) ? "" : rfc2426_escape(contact->business_po_box ); 1224 fprintf(f_output, "%s;", ""); // extended Address
1339 char *ac = (!contact->business_street ) ? "" : rfc2426_escape(contact->business_street ); 1225 fprintf(f_output, "%s;", (!contact->business_street) ? "" : rfc2426_escape(contact->business_street));
1340 char *ad = (!contact->business_city ) ? "" : rfc2426_escape(contact->business_city ); 1226 fprintf(f_output, "%s;", (!contact->business_city) ? "" : rfc2426_escape(contact->business_city));
1341 char *ae = (!contact->business_state ) ? "" : rfc2426_escape(contact->business_state ); 1227 fprintf(f_output, "%s;", (!contact->business_state) ? "" : rfc2426_escape(contact->business_state));
1342 char *af = (!contact->business_postal_code) ? "" : rfc2426_escape(contact->business_postal_code); 1228 fprintf(f_output, "%s;", (!contact->business_postal_code) ? "" : rfc2426_escape(contact->business_postal_code));
1343 char *ag = (!contact->business_country ) ? "" : rfc2426_escape(contact->business_country ); 1229 fprintf(f_output, "%s\n", (!contact->business_country) ? "" : rfc2426_escape(contact->business_country));
1344 fprintf(f_output, "ADR;TYPE=work:%s;%s;%s;%s;%s;%s;%s\n", ab, "", ac, ad, ae, af, ag);
1345 //fprintf(f_output, "ADR;TYPE=work:%s;%s;%s;%s;%s;%s;%s\n",
1346 // (!contact->business_po_box) ? "" : rfc2426_escape(contact->business_po_box),
1347 // "", // extended Address
1348 // (!contact->business_street) ? "" : rfc2426_escape(contact->business_street),
1349 // (!contact->business_city) ? "" : rfc2426_escape(contact->business_city),
1350 // (!contact->business_state) ? "" : rfc2426_escape(contact->business_state),
1351 // (!contact->business_postal_code) ? "" : rfc2426_escape(contact->business_postal_code),
1352 // (!contact->business_country) ? "" : rfc2426_escape(contact->business_country));
1353 fprintf(f_output, "LABEL;TYPE=work:%s\n", rfc2426_escape(contact->business_address)); 1230 fprintf(f_output, "LABEL;TYPE=work:%s\n", rfc2426_escape(contact->business_address));
1354 } 1231 }
1232
1355 if (contact->other_address) { 1233 if (contact->other_address) {
1356 fprintf(f_output, "ADR;TYPE=postal:%s;%s;%s;%s;%s;%s;%s\n", 1234 //fprintf(f_output, "ADR;TYPE=postal:%s;%s;%s;%s;%s;%s;%s\n",
1357 (!contact->other_po_box) ? "" : rfc2426_escape(contact->other_po_box), 1235 fprintf(f_output, "ADR;TYPE=postal:%s;",(!contact->other_po_box) ? "" : rfc2426_escape(contact->other_po_box));
1358 "", // extended Address 1236 fprintf(f_output, "%s;", ""); // extended Address
1359 (!contact->other_street) ? "" : rfc2426_escape(contact->other_street), 1237 fprintf(f_output, "%s;", (!contact->other_street) ? "" : rfc2426_escape(contact->other_street));
1360 (!contact->other_city) ? "" : rfc2426_escape(contact->other_city), 1238 fprintf(f_output, "%s;", (!contact->other_city) ? "" : rfc2426_escape(contact->other_city));
1361 (!contact->other_state) ? "" : rfc2426_escape(contact->other_state), 1239 fprintf(f_output, "%s;", (!contact->other_state) ? "" : rfc2426_escape(contact->other_state));
1362 (!contact->other_postal_code) ? "" : rfc2426_escape(contact->other_postal_code), 1240 fprintf(f_output, "%s;", (!contact->other_postal_code) ? "" : rfc2426_escape(contact->other_postal_code));
1363 (!contact->other_country) ? "" : rfc2426_escape(contact->other_country)); 1241 fprintf(f_output, "%s\n", (!contact->other_country) ? "" : rfc2426_escape(contact->other_country));
1364 fprintf(f_output, "LABEL;TYPE=postal:%s\n", rfc2426_escape(contact->other_address)); 1242 fprintf(f_output, "LABEL;TYPE=postal:%s\n", rfc2426_escape(contact->other_address));
1365 } 1243 }
1366 if (contact->business_fax) 1244
1367 fprintf(f_output, "TEL;TYPE=work,fax:%s\n", 1245 if (contact->business_fax) fprintf(f_output, "TEL;TYPE=work,fax:%s\n", rfc2426_escape(contact->business_fax));
1368 rfc2426_escape(contact->business_fax)); 1246 if (contact->business_phone) fprintf(f_output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(contact->business_phone));
1369 if (contact->business_phone) 1247 if (contact->business_phone2) fprintf(f_output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(contact->business_phone2));
1370 fprintf(f_output, "TEL;TYPE=work,voice:%s\n", 1248 if (contact->car_phone) fprintf(f_output, "TEL;TYPE=car,voice:%s\n", rfc2426_escape(contact->car_phone));
1371 rfc2426_escape(contact->business_phone)); 1249 if (contact->home_fax) fprintf(f_output, "TEL;TYPE=home,fax:%s\n", rfc2426_escape(contact->home_fax));
1372 if (contact->business_phone2) 1250 if (contact->home_phone) fprintf(f_output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(contact->home_phone));
1373 fprintf(f_output, "TEL;TYPE=work,voice:%s\n", 1251 if (contact->home_phone2) fprintf(f_output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(contact->home_phone2));
1374 rfc2426_escape(contact->business_phone2)); 1252 if (contact->isdn_phone) fprintf(f_output, "TEL;TYPE=isdn:%s\n", rfc2426_escape(contact->isdn_phone));
1375 if (contact->car_phone) 1253 if (contact->mobile_phone) fprintf(f_output, "TEL;TYPE=cell,voice:%s\n", rfc2426_escape(contact->mobile_phone));
1376 fprintf(f_output, "TEL;TYPE=car,voice:%s\n", 1254 if (contact->other_phone) fprintf(f_output, "TEL;TYPE=msg:%s\n", rfc2426_escape(contact->other_phone));
1377 rfc2426_escape(contact->car_phone)); 1255 if (contact->pager_phone) fprintf(f_output, "TEL;TYPE=pager:%s\n", rfc2426_escape(contact->pager_phone));
1378 if (contact->home_fax) 1256 if (contact->primary_fax) fprintf(f_output, "TEL;TYPE=fax,pref:%s\n", rfc2426_escape(contact->primary_fax));
1379 fprintf(f_output, "TEL;TYPE=home,fax:%s\n", 1257 if (contact->primary_phone) fprintf(f_output, "TEL;TYPE=phone,pref:%s\n", rfc2426_escape(contact->primary_phone));
1380 rfc2426_escape(contact->home_fax)); 1258 if (contact->radio_phone) fprintf(f_output, "TEL;TYPE=pcs:%s\n", rfc2426_escape(contact->radio_phone));
1381 if (contact->home_phone) 1259 if (contact->telex) fprintf(f_output, "TEL;TYPE=bbs:%s\n", rfc2426_escape(contact->telex));
1382 fprintf(f_output, "TEL;TYPE=home,voice:%s\n", 1260 if (contact->job_title) fprintf(f_output, "TITLE:%s\n", rfc2426_escape(contact->job_title));
1383 rfc2426_escape(contact->home_phone)); 1261 if (contact->profession) fprintf(f_output, "ROLE:%s\n", rfc2426_escape(contact->profession));
1384 if (contact->home_phone2) 1262 if (contact->assistant_name || contact->assistant_phone) {
1385 fprintf(f_output, "TEL;TYPE=home,voice:%s\n",
1386 rfc2426_escape(contact->home_phone2));
1387 if (contact->isdn_phone)
1388 fprintf(f_output, "TEL;TYPE=isdn:%s\n",
1389 rfc2426_escape(contact->isdn_phone));
1390 if (contact->mobile_phone)
1391 fprintf(f_output, "TEL;TYPE=cell,voice:%s\n",
1392 rfc2426_escape(contact->mobile_phone));
1393 if (contact->other_phone)
1394 fprintf(f_output, "TEL;TYPE=msg:%s\n",
1395 rfc2426_escape(contact->other_phone));
1396 if (contact->pager_phone)
1397 fprintf(f_output, "TEL;TYPE=pager:%s\n",
1398 rfc2426_escape(contact->pager_phone));
1399 if (contact->primary_fax)
1400 fprintf(f_output, "TEL;TYPE=fax,pref:%s\n",
1401 rfc2426_escape(contact->primary_fax));
1402 if (contact->primary_phone)
1403 fprintf(f_output, "TEL;TYPE=phone,pref:%s\n",
1404 rfc2426_escape(contact->primary_phone));
1405 if (contact->radio_phone)
1406 fprintf(f_output, "TEL;TYPE=pcs:%s\n",
1407 rfc2426_escape(contact->radio_phone));
1408 if (contact->telex)
1409 fprintf(f_output, "TEL;TYPE=bbs:%s\n",
1410 rfc2426_escape(contact->telex));
1411 if (contact->job_title)
1412 fprintf(f_output, "TITLE:%s\n",
1413 rfc2426_escape(contact->job_title));
1414 if (contact->profession)
1415 fprintf(f_output, "ROLE:%s\n",
1416 rfc2426_escape(contact->profession));
1417 if (contact->assistant_name
1418 || contact->assistant_phone) {
1419 fprintf(f_output, "AGENT:BEGIN:VCARD\n"); 1263 fprintf(f_output, "AGENT:BEGIN:VCARD\n");
1420 if (contact->assistant_name) 1264 if (contact->assistant_name) fprintf(f_output, "FN:%s\n", rfc2426_escape(contact->assistant_name));
1421 fprintf(f_output, "FN:%s\n", 1265 if (contact->assistant_phone) fprintf(f_output, "TEL:%s\n", rfc2426_escape(contact->assistant_phone));
1422 rfc2426_escape(contact->assistant_name)); 1266 }
1423 if (contact->assistant_phone) 1267 if (contact->company_name) fprintf(f_output, "ORG:%s\n", rfc2426_escape(contact->company_name));
1424 fprintf(f_output, "TEL:%s\n", 1268 if (comment) fprintf(f_output, "NOTE:%s\n", rfc2426_escape(comment));
1425 rfc2426_escape(contact->assistant_phone));
1426 }
1427 if (contact->company_name)
1428 fprintf(f_output, "ORG:%s\n",
1429 rfc2426_escape(contact->company_name));
1430 if (comment)
1431 fprintf(f_output, "NOTE:%s\n", rfc2426_escape(comment));
1432 1269
1433 fprintf(f_output, "VERSION: 3.0\n"); 1270 fprintf(f_output, "VERSION: 3.0\n");
1434 fprintf(f_output, "END:VCARD\n\n"); 1271 fprintf(f_output, "END:VCARD\n\n");
1435 DEBUG_RET(); 1272 DEBUG_RET();
1436 } 1273 }
1512 } 1349 }
1513 fprintf(f_output, "END:VEVENT\n\n"); 1350 fprintf(f_output, "END:VEVENT\n\n");
1514 } 1351 }
1515 1352
1516 1353
1517 void create_enter_dir(struct file_ll* f, char file_as[], int mode, int overwrite) 1354 void create_enter_dir(struct file_ll* f, pst_item *item)
1518 { 1355 {
1356 f->email_count = 0;
1357 f->skip_count = 0;
1358 f->type = item->type;
1359 f->stored_count = (item->folder) ? item->folder->email_count : 0;
1360
1519 DEBUG_ENT("create_enter_dir"); 1361 DEBUG_ENT("create_enter_dir");
1520 if (mode == MODE_KMAIL) 1362 if (mode == MODE_KMAIL)
1521 f->name = mk_kmail_dir(file_as); //create directory and form filename 1363 f->name = mk_kmail_dir(item->file_as); //create directory and form filename
1522 else if (mode == MODE_RECURSE) 1364 else if (mode == MODE_RECURSE)
1523 f->name = mk_recurse_dir(file_as); 1365 f->name = mk_recurse_dir(item->file_as);
1524 else if (mode == MODE_SEPERATE) { 1366 else if (mode == MODE_SEPERATE) {
1525 // do similar stuff to recurse here. 1367 // do similar stuff to recurse here.
1526 mk_seperate_dir(file_as, overwrite); 1368 mk_seperate_dir(item->file_as);
1527 f->name = (char*) xmalloc(10); 1369 f->name = (char*) xmalloc(10);
1528 memset(f->name, 0, 10); 1370 memset(f->name, 0, 10);
1529 // sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->email_count); 1371 // sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->email_count);
1530 } else { 1372 } else {
1531 f->name = (char*) xmalloc(strlen(file_as)+strlen(OUTPUT_TEMPLATE)+1); 1373 f->name = (char*) xmalloc(strlen(item->file_as)+strlen(OUTPUT_TEMPLATE)+1);
1532 sprintf(f->name, OUTPUT_TEMPLATE, file_as); 1374 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as);
1533 } 1375 }
1534 1376
1535 f->dname = (char*) xmalloc(strlen(file_as)+1); 1377 f->dname = (char*) xmalloc(strlen(item->file_as)+1);
1536 strcpy(f->dname, file_as); 1378 strcpy(f->dname, item->file_as);
1537 1379
1538 if (overwrite != 1) { 1380 if (overwrite != 1) {
1539 int x = 0; 1381 int x = 0;
1540 char *temp = (char*) xmalloc (strlen(f->name)+10); //enough room for 10 digits 1382 char *temp = (char*) xmalloc (strlen(f->name)+10); //enough room for 10 digits
1541 1383
1558 } else { 1400 } else {
1559 free(temp); 1401 free(temp);
1560 } 1402 }
1561 } 1403 }
1562 1404
1563 DEBUG_MAIN(("f->name = %s\nitem->folder_name = %s\n", f->name, file_as)); 1405 DEBUG_MAIN(("f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as));
1564 if (mode != MODE_SEPERATE) { 1406 if (mode != MODE_SEPERATE) {
1565 f->name = check_filename(f->name); 1407 f->name = check_filename(f->name);
1566 if (!(f->output = fopen(f->name, "w"))) { 1408 if (!(f->output = fopen(f->name, "w"))) {
1567 DIE(("create_enter_dir: Could not open file \"%s\" for write\n", f->name)); 1409 DIE(("create_enter_dir: Could not open file \"%s\" for write\n", f->name));
1568 } 1410 }
1569 } 1411 }
1570 DEBUG_RET(); 1412 DEBUG_RET();
1571 } 1413 }
1572 1414
1415
1416 void close_enter_dir(struct file_ll *f)
1417 {
1418 DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count));
1419 if (output_mode != OUTPUT_QUIET)
1420 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n",
1421 f->dname, f->email_count, f->skip_count, f->stored_count);
1422 if (f->output) fclose(f->output);
1423 free(f->name);
1424 free(f->dname);
1425
1426 if (mode == MODE_KMAIL)
1427 close_kmail_dir();
1428 else if (mode == MODE_RECURSE)
1429 close_recurse_dir();
1430 else if (mode == MODE_SEPERATE)
1431 close_seperate_dir();
1432 }
1433