Mercurial > libpst
comparison src/readpst.c @ 230:42b38d65f7e4
patches from Justin Greer
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 10 Sep 2009 13:01:08 -0700 |
parents | 4a659f3138b7 |
children | fe64279df92b |
comparison
equal
deleted
inserted
replaced
229:e7f363452178 | 230:42b38d65f7e4 |
---|---|
101 | 101 |
102 // output mode for deleted items | 102 // output mode for deleted items |
103 #define DMODE_EXCLUDE 0 | 103 #define DMODE_EXCLUDE 0 |
104 #define DMODE_INCLUDE 1 | 104 #define DMODE_INCLUDE 1 |
105 | 105 |
106 // Output type mode flags | |
107 #define OTMODE_EMAIL 1 | |
108 #define OTMODE_APPOINTMENT 2 | |
109 #define OTMODE_JOURNAL 4 | |
110 #define OTMODE_CONTACT 8 | |
111 | |
106 // output settings for RTF bodies | 112 // output settings for RTF bodies |
107 // filename for the attachment | 113 // filename for the attachment |
108 #define RTF_ATTACH_NAME "rtf-body.rtf" | 114 #define RTF_ATTACH_NAME "rtf-body.rtf" |
109 // mime type for the attachment | 115 // mime type for the attachment |
110 #define RTF_ATTACH_TYPE "application/rtf" | 116 #define RTF_ATTACH_TYPE "application/rtf" |
113 int mode = MODE_NORMAL; | 119 int mode = MODE_NORMAL; |
114 int mode_MH = 0; // a submode of MODE_SEPARATE | 120 int mode_MH = 0; // a submode of MODE_SEPARATE |
115 int output_mode = OUTPUT_NORMAL; | 121 int output_mode = OUTPUT_NORMAL; |
116 int contact_mode = CMODE_VCARD; | 122 int contact_mode = CMODE_VCARD; |
117 int deleted_mode = DMODE_EXCLUDE; | 123 int deleted_mode = DMODE_EXCLUDE; |
124 int output_type_mode = 0xff; // Default to all. | |
118 int contact_mode_specified = 0; | 125 int contact_mode_specified = 0; |
119 int overwrite = 0; | 126 int overwrite = 0; |
120 int save_rtf_body = 1; | 127 int save_rtf_body = 1; |
121 pst_file pstfile; | 128 pst_file pstfile; |
122 regex_t meta_charset_pattern; | 129 regex_t meta_charset_pattern; |
270 DEBUG_INFO(("Processing Contact\n")); | 277 DEBUG_INFO(("Processing Contact\n")); |
271 if (ff.type != PST_TYPE_CONTACT) { | 278 if (ff.type != PST_TYPE_CONTACT) { |
272 ff.skip_count++; | 279 ff.skip_count++; |
273 DEBUG_INFO(("I have a contact, but the folder type %"PRIi32" isn't a contacts folder. Skipping it\n", ff.type)); | 280 DEBUG_INFO(("I have a contact, but the folder type %"PRIi32" isn't a contacts folder. Skipping it\n", ff.type)); |
274 } | 281 } |
282 else if (!(output_type_mode & OTMODE_CONTACT)) { | |
283 ff.skip_count++; | |
284 DEBUG_INFO(("skipping contact: not in output type list\n")); | |
285 } | |
275 else { | 286 else { |
276 ff.item_count++; | 287 ff.item_count++; |
277 if (mode == MODE_SEPARATE) mk_separate_file(&ff); | 288 if (mode == MODE_SEPARATE) mk_separate_file(&ff); |
278 if (contact_mode == CMODE_VCARD) { | 289 if (contact_mode == CMODE_VCARD) { |
279 pst_convert_utf8_null(item, &item->comment); | 290 pst_convert_utf8_null(item, &item->comment); |
291 DEBUG_INFO(("Processing Email\n")); | 302 DEBUG_INFO(("Processing Email\n")); |
292 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) { | 303 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) { |
293 ff.skip_count++; | 304 ff.skip_count++; |
294 DEBUG_INFO(("I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type)); | 305 DEBUG_INFO(("I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type)); |
295 } | 306 } |
307 else if (!(output_type_mode & OTMODE_EMAIL)) { | |
308 ff.skip_count++; | |
309 DEBUG_INFO(("skipping email: not in output type list\n")); | |
310 } | |
296 else { | 311 else { |
297 char *extra_mime_headers = NULL; | 312 char *extra_mime_headers = NULL; |
298 ff.item_count++; | 313 ff.item_count++; |
299 if (mode == MODE_SEPARATE) mk_separate_file(&ff); | 314 if (mode == MODE_SEPARATE) mk_separate_file(&ff); |
300 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); | 315 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); |
305 DEBUG_INFO(("Processing Journal Entry\n")); | 320 DEBUG_INFO(("Processing Journal Entry\n")); |
306 if (ff.type != PST_TYPE_JOURNAL) { | 321 if (ff.type != PST_TYPE_JOURNAL) { |
307 ff.skip_count++; | 322 ff.skip_count++; |
308 DEBUG_INFO(("I have a journal entry, but the folder type %"PRIi32" isn't a journal folder. Skipping it\n", ff.type)); | 323 DEBUG_INFO(("I have a journal entry, but the folder type %"PRIi32" isn't a journal folder. Skipping it\n", ff.type)); |
309 } | 324 } |
325 else if (!(output_type_mode & OTMODE_JOURNAL)) { | |
326 ff.skip_count++; | |
327 DEBUG_INFO(("skipping journal entry: not in output type list\n")); | |
328 } | |
310 else { | 329 else { |
311 ff.item_count++; | 330 ff.item_count++; |
312 if (mode == MODE_SEPARATE) mk_separate_file(&ff); | 331 if (mode == MODE_SEPARATE) mk_separate_file(&ff); |
313 write_journal(ff.output, item); | 332 write_journal(ff.output, item); |
314 fprintf(ff.output, "\n"); | 333 fprintf(ff.output, "\n"); |
318 if (!ff.type) ff.type = item->type; | 337 if (!ff.type) ff.type = item->type; |
319 DEBUG_INFO(("Processing Appointment Entry\n")); | 338 DEBUG_INFO(("Processing Appointment Entry\n")); |
320 if (ff.type != PST_TYPE_APPOINTMENT) { | 339 if (ff.type != PST_TYPE_APPOINTMENT) { |
321 ff.skip_count++; | 340 ff.skip_count++; |
322 DEBUG_INFO(("I have an appointment, but the folder type %"PRIi32" isn't an appointment folder. Skipping it\n", ff.type)); | 341 DEBUG_INFO(("I have an appointment, but the folder type %"PRIi32" isn't an appointment folder. Skipping it\n", ff.type)); |
342 } | |
343 else if (!(output_type_mode & OTMODE_APPOINTMENT)) { | |
344 ff.skip_count++; | |
345 DEBUG_INFO(("skipping appointment: not in output type list\n")); | |
323 } | 346 } |
324 else { | 347 else { |
325 ff.item_count++; | 348 ff.item_count++; |
326 if (mode == MODE_SEPARATE) mk_separate_file(&ff); | 349 if (mode == MODE_SEPARATE) mk_separate_file(&ff); |
327 write_appointment(ff.output, item, 0); | 350 write_appointment(ff.output, item, 0); |
362 printf("cannot compile regex pattern to find content charset in html bodies\n"); | 385 printf("cannot compile regex pattern to find content charset in html bodies\n"); |
363 exit(3); | 386 exit(3); |
364 } | 387 } |
365 | 388 |
366 // command-line option handling | 389 // command-line option handling |
367 while ((c = getopt(argc, argv, "bc:Dd:hj:kMo:qrSVw"))!= -1) { | 390 while ((c = getopt(argc, argv, "bc:Dd:hj:kMo:qrSt:Vw"))!= -1) { |
368 switch (c) { | 391 switch (c) { |
369 case 'b': | 392 case 'b': |
370 save_rtf_body = 0; | 393 save_rtf_body = 0; |
371 break; | 394 break; |
372 case 'c': | 395 case 'c': |
418 mode_MH = 0; | 441 mode_MH = 0; |
419 break; | 442 break; |
420 case 'V': | 443 case 'V': |
421 version(); | 444 version(); |
422 exit(0); | 445 exit(0); |
446 break; | |
447 case 't': | |
448 // email, appointment, contact, other | |
449 if (!optarg) { | |
450 usage(); | |
451 exit(0); | |
452 } | |
453 temp = optarg; | |
454 output_type_mode = 0; | |
455 while (*temp > 0) { | |
456 switch (temp[0]) { | |
457 case 'e': | |
458 output_type_mode |= OTMODE_EMAIL; | |
459 break; | |
460 case 'a': | |
461 output_type_mode |= OTMODE_APPOINTMENT; | |
462 break; | |
463 case 'j': | |
464 output_type_mode |= OTMODE_JOURNAL; | |
465 break; | |
466 case 'c': | |
467 output_type_mode |= OTMODE_CONTACT; | |
468 break; | |
469 default: | |
470 usage(); | |
471 exit(0); | |
472 break; | |
473 } | |
474 temp++; | |
475 } | |
423 break; | 476 break; |
424 case 'w': | 477 case 'w': |
425 overwrite = 1; | 478 overwrite = 1; |
426 break; | 479 break; |
427 default: | 480 default: |
577 printf("\t-D\t- Include deleted items in output\n"); | 630 printf("\t-D\t- Include deleted items in output\n"); |
578 printf("\t-M\t- MH. Write emails in the MH format\n"); | 631 printf("\t-M\t- MH. Write emails in the MH format\n"); |
579 printf("\t-S\t- Separate. Write emails in the separate format\n"); | 632 printf("\t-S\t- Separate. Write emails in the separate format\n"); |
580 printf("\t-b\t- Don't save RTF-Body attachments\n"); | 633 printf("\t-b\t- Don't save RTF-Body attachments\n"); |
581 printf("\t-c[v|l]\t- Set the Contact output mode. -cv = VCard, -cl = EMail list\n"); | 634 printf("\t-c[v|l]\t- Set the Contact output mode. -cv = VCard, -cl = EMail list\n"); |
635 printf("\t-t[eajc]\t- Set the output type list. e = email, a = attachment, j = journal, c = contact\n"); | |
582 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readpstlog to print it\n"); | 636 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readpstlog to print it\n"); |
583 printf("\t-h\t- Help. This screen\n"); | 637 printf("\t-h\t- Help. This screen\n"); |
584 printf("\t-j <integer>\t- Number of parallel jobs to run\n"); | 638 printf("\t-j <integer>\t- Number of parallel jobs to run\n"); |
585 printf("\t-k\t- KMail. Output in kmail format\n"); | 639 printf("\t-k\t- KMail. Output in kmail format\n"); |
586 printf("\t-o <dirname>\t- Output directory to write files to. CWD is changed *after* opening pst file\n"); | 640 printf("\t-o <dirname>\t- Output directory to write files to. CWD is changed *after* opening pst file\n"); |
1342 fprintf(f_output, "From \"%s\" %s\n", sender, c_time); | 1396 fprintf(f_output, "From \"%s\" %s\n", sender, c_time); |
1343 } | 1397 } |
1344 | 1398 |
1345 // print the supplied email headers | 1399 // print the supplied email headers |
1346 if (headers) { | 1400 if (headers) { |
1347 int len; | 1401 int len = strlen(headers); |
1348 fprintf(f_output, "%s", headers); | 1402 if (len > 0) { |
1349 // make sure the headers end with a \n | 1403 fprintf(f_output, "%s", headers); |
1350 len = strlen(headers); | 1404 // make sure the headers end with a \n |
1351 if (!len || (headers[len-1] != '\n')) fprintf(f_output, "\n"); | 1405 if (headers[len-1] != '\n') fprintf(f_output, "\n"); |
1406 } | |
1352 } | 1407 } |
1353 | 1408 |
1354 // create required header fields that are not already written | 1409 // create required header fields that are not already written |
1355 | 1410 |
1356 if (!has_from) { | 1411 if (!has_from) { |