diff src/readpst.c @ 316:c4537664ff50

merge .msg generation code
author Carl Byington <carl@five-ten-sg.com>
date Mon, 24 Dec 2012 17:51:12 -0800
parents 5338d93889aa 0f19cd173eab
children 2474d01043cd
line wrap: on
line diff
--- a/src/readpst.c	Mon Dec 24 16:26:39 2012 -0800
+++ b/src/readpst.c	Mon Dec 24 17:51:12 2012 -0800
@@ -7,6 +7,7 @@
 
 #include "define.h"
 #include "lzfu.h"
+#include "msg.h"
 
 #define OUTPUT_TEMPLATE "%s"
 #define OUTPUT_KMAIL_DIR_TEMPLATE ".%s.directory"
@@ -39,7 +40,7 @@
 int       close_recurse_dir();
 char*     mk_separate_dir(char *dir);
 int       close_separate_dir();
-void      mk_separate_file(struct file_ll *f, char *extension);
+void      mk_separate_file(struct file_ll *f, char *extension, int openit);
 void      close_separate_file(struct file_ll *f);
 char*     my_stristr(char *haystack, char *needle);
 void      check_filename(char *fname);
@@ -122,6 +123,7 @@
 int         mode         = MODE_NORMAL;
 int         mode_MH      = 0;   // a submode of MODE_SEPARATE
 int         mode_EX      = 0;   // a submode of MODE_SEPARATE
+int         mode_MSG     = 0;   // a submode of MODE_SEPARATE
 int         mode_thunder = 0;   // a submode of MODE_RECURSE
 int         output_mode  = OUTPUT_NORMAL;
 int         contact_mode = CMODE_VCARD;
@@ -306,7 +308,7 @@
                 }
                 else {
                     ff.item_count++;
-                    if (mode == MODE_SEPARATE) mk_separate_file(&ff, (mode_EX) ? ".vcf" : "");
+                    if (mode == MODE_SEPARATE) mk_separate_file(&ff, (mode_EX) ? ".vcf" : "", 1);
                     if (contact_mode == CMODE_VCARD) {
                         pst_convert_utf8_null(item, &item->comment);
                         write_vcard(ff.output, item, item->contact, item->comment.str);
@@ -342,9 +344,13 @@
                         if (child == 0) {
                             // we are the child process, or the original parent if no children were available
                             pid_t me = getpid();
-                            mk_separate_file(&ff, (mode_EX) ? ".eml" : "");
+                            mk_separate_file(&ff, (mode_EX) ? ".eml" : "", 1);
                             write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers);
                             close_separate_file(&ff);
+                            if (mode_MSG) {
+                                mk_separate_file(&ff, ".msg", 0);
+                                write_msg_email(ff.name, item, &pstfile);
+                            }
 #ifdef HAVE_FORK
 #ifdef HAVE_SEMAPHORE_H
                             if (me != parent) {
@@ -380,7 +386,7 @@
                 }
                 else {
                     ff.item_count++;
-                    if (mode == MODE_SEPARATE) mk_separate_file(&ff, (mode_EX) ? ".ics" : "");
+                    if (mode == MODE_SEPARATE) mk_separate_file(&ff, (mode_EX) ? ".ics" : "", 1);
                     write_journal(ff.output, item);
                     fprintf(ff.output, "\n");
                     if (mode == MODE_SEPARATE) close_separate_file(&ff);
@@ -401,7 +407,7 @@
                 }
                 else {
                     ff.item_count++;
-                    if (mode == MODE_SEPARATE) mk_separate_file(&ff, (mode_EX) ? ".ics" : "");
+                    if (mode == MODE_SEPARATE) mk_separate_file(&ff, (mode_EX) ? ".ics" : "", 1);
                     write_schedule_part_data(ff.output, item, NULL, NULL);
                     fprintf(ff.output, "\n");
                     if (mode == MODE_SEPARATE) close_separate_file(&ff);
@@ -444,7 +450,7 @@
     }
 
     // command-line option handling
-    while ((c = getopt(argc, argv, "bC:c:Dd:ehj:kMo:qrSt:uVw"))!= -1) {
+    while ((c = getopt(argc, argv, "bC:c:Dd:emhj:kMo:qrSt:uVw"))!= -1) {
         switch (c) {
         case 'b':
             save_rtf_body = 0;
@@ -491,13 +497,22 @@
             break;
         case 'M':
             mode = MODE_SEPARATE;
-            mode_MH = 1;
-            mode_EX = 0;
+            mode_MH  = 1;
+            mode_EX  = 0;
+            mode_MSG = 0;
             break;
         case 'e':
             mode = MODE_SEPARATE;
-            mode_MH = 1;
-            mode_EX = 1;
+            mode_MH  = 1;
+            mode_EX  = 1;
+            mode_MSG = 0;
+            file_name_len = 14;
+            break;
+        case 'm':
+            mode = MODE_SEPARATE;
+            mode_MH  = 1;
+            mode_EX  = 1;
+            mode_MSG = 1;
             file_name_len = 14;
             break;
         case 'o':
@@ -512,8 +527,9 @@
             break;
         case 'S':
             mode = MODE_SEPARATE;
-            mode_MH = 0;
-            mode_EX = 0;
+            mode_MH  = 0;
+            mode_EX  = 0;
+            mode_MSG = 0;
             break;
         case 't':
             // email, appointment, contact, other
@@ -719,6 +735,7 @@
     printf("\t-h\t- Help. This screen\n");
     printf("\t-j <integer>\t- Number of parallel jobs to run\n");
     printf("\t-k\t- KMail. Output in kmail format\n");
+    printf("\t-m\t- As with -e, but write .msg files also\n");
     printf("\t-o <dirname>\t- Output directory to write files to. CWD is changed *after* opening pst file\n");
     printf("\t-q\t- Quiet. Only print error messages\n");
     printf("\t-r\t- Recursive. Output in a recursive format\n");
@@ -726,7 +743,7 @@
     printf("\t-u\t- Thunderbird mode. Write two extra .size and .type files\n");
     printf("\t-w\t- Overwrite any output mbox files\n");
     printf("\n");
-    printf("Only one of -k -M -r -S should be specified\n");
+    printf("Only one of -M -S -e -k -m -r should be specified\n");
     DEBUG_RET();
 }
 
@@ -924,7 +941,7 @@
 }
 
 
-void mk_separate_file(struct file_ll *f, char *extension) {
+void mk_separate_file(struct file_ll *f, char *extension, int openit) {
     DEBUG_ENT("mk_separate_file");
     DEBUG_INFO(("opening next file to save email\n"));
     if (f->item_count > 999999999) { // bigger than nine 9's
@@ -932,8 +949,10 @@
     }
     sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->item_count, extension);
     check_filename(f->name);
-    if (!(f->output = fopen(f->name, "w"))) {
-        DIE(("mk_separate_file: Cannot open file to save email \"%s\"\n", f->name));
+    if (openit) {
+        if (!(f->output = fopen(f->name, "w"))) {
+            DIE(("mk_separate_file: Cannot open file to save email \"%s\"\n", f->name));
+        }
     }
     DEBUG_RET();
 }