Julien Kerihuel wrote, On 08/29/08 14:35:

I'll add some code this week-end to exchange2mbox to fetch
PR_TRANSPORT_MESSAGE_HEADERS and store them in the mbox file if the
message has the property.

Well, here's a patch for adding that functionality, if it'll help. It's not perfect. Among other things, it still needs to deal with instances where the transport headers contain a "Content-type" line. Should probably scan for that and use the boundary value from it instead of the default boundary.

I apologize for my rusty C. Spend most of my time in Perl these days. I kept thinking how much nicer it would be if I had Perl regex's instead of strstr() and strchr(). Ah well, use what's available and make it work. C does tend to be faster for many things.

--
Noah Romer <[EMAIL PROTECTED]>
GPG Key Fingerprint: 944E C2F8 EBEC BCC7 EEA9  9381 1B21 0098 CC8D 45BA
Index: utils/exchange2mbox.c
===================================================================
--- utils/exchange2mbox.c       (revision 708)
+++ utils/exchange2mbox.c       (working copy)
@@ -32,6 +32,8 @@
 #include <param.h>
 #include <magic.h>
 
+#include <string.h>
+
 #include "openchange-tools.h"
 
 /* Ugly and lazy but working ... */
@@ -333,6 +335,7 @@
        const char                      *bcc = NULL;
        const char                      *subject = NULL;
        const char                      *msgid;
+       const char                      *msgheaders = NULL;
        DATA_BLOB                       body;
        const char                      *attach_filename;
        const uint32_t                  *attach_size;
@@ -369,6 +372,8 @@
        subject = (const char *) octool_get_propval(aRow, 
PR_CONVERSATION_TOPIC);
        msgid = (const char *) octool_get_propval(aRow, PR_INTERNET_MESSAGE_ID);
 
+       msgheaders = (const char *) octool_get_propval(aRow, 
PR_TRANSPORT_MESSAGE_HEADERS);
+
        retval = octool_get_body(mem_ctx, obj_message, aRow, &body);
 
        /* First line From */
@@ -376,55 +381,74 @@
        if (line) fwrite(line, strlen(line), 1, fp);
        talloc_free(line);
 
-       /* Second line: Date */
-       line = talloc_asprintf(mem_ctx, "Date: %s\n", date);
-       if (line) fwrite(line, strlen(line), 1, fp);
-       talloc_free(line);
-
-       /* Third line From */
-       line = talloc_asprintf(mem_ctx, "From: %s\n", from);
-       if (line) fwrite(line, strlen(line), 1, fp);
-       talloc_free(line);
-
-       /* To, Cc, Bcc */
-       if (to) {
-               line = talloc_asprintf(mem_ctx, "To: %s\n", to);
+       if (msgheaders) {
+               char *mhclean, *mhend;
+               
+               /* Skip past the comment Exchange adds to the beginning */
+               mhclean = strchr(msgheaders, '\n');
+               mhclean++;
+               
+               /* Trim off the empty mime parts that Exchange leaves after 
+                  the end of the headers */
+               mhend = strstr(mhclean, "\n------=");
+               if (mhend) {
+                       mhend++;
+                       *mhend = '\0';
+               }
+               
+               line = talloc_asprintf(mem_ctx, "%s\n", mhclean);
                if (line) fwrite(line, strlen(line), 1, fp);
                talloc_free(line);
-       }
-
-       if (cc) {
-               line = talloc_asprintf(mem_ctx, "Cc: %s\n", cc);
+       } else {
+               /* Second line: Date */
+               line = talloc_asprintf(mem_ctx, "Date: %s\n", date);
                if (line) fwrite(line, strlen(line), 1, fp);
                talloc_free(line);
-       }
-
-       if (bcc) {
-               line = talloc_asprintf(mem_ctx, "Bcc: %s\n", bcc);
+       
+               /* Third line From */
+               line = talloc_asprintf(mem_ctx, "From: %s\n", from);
                if (line) fwrite(line, strlen(line), 1, fp);
                talloc_free(line);
+       
+               /* To, Cc, Bcc */
+               if (to) {
+                       line = talloc_asprintf(mem_ctx, "To: %s\n", to);
+                       if (line) fwrite(line, strlen(line), 1, fp);
+                       talloc_free(line);
+               }
+       
+               if (cc) {
+                       line = talloc_asprintf(mem_ctx, "Cc: %s\n", cc);
+                       if (line) fwrite(line, strlen(line), 1, fp);
+                       talloc_free(line);
+               }
+       
+               if (bcc) {
+                       line = talloc_asprintf(mem_ctx, "Bcc: %s\n", bcc);
+                       if (line) fwrite(line, strlen(line), 1, fp);
+                       talloc_free(line);
+               }
+       
+               /* Subject */
+               if (subject) {
+                       line = talloc_asprintf(mem_ctx, "Subject: %s\n", 
subject);
+                       if (line) fwrite(line, strlen(line), 1, fp);
+                       talloc_free(line);
+               }
+       
+               if (msgid) {
+                       line = talloc_asprintf(mem_ctx, "Message-ID: %s\n", 
msgid);
+                       if (line) fwrite(line, strlen(line), 1, fp);
+                       talloc_free(line);
+               }
+       
+               /* Set multi-type if we have attachment */
+               if (has_attach && *has_attach) {
+                       line = talloc_asprintf(mem_ctx, "Content-Type: 
multipart/mixed; boundary=\"%s\"\n", BOUNDARY);
+                       if (line) fwrite(line, strlen(line), 1, fp);
+                       talloc_free(line);
+               }
        }
-
-       /* Subject */
-       if (subject) {
-               line = talloc_asprintf(mem_ctx, "Subject: %s\n", subject);
-               if (line) fwrite(line, strlen(line), 1, fp);
-               talloc_free(line);
-       }
-
-       if (msgid) {
-               line = talloc_asprintf(mem_ctx, "Message-ID: %s\n", msgid);
-               if (line) fwrite(line, strlen(line), 1, fp);
-               talloc_free(line);
-       }
-
-       /* Set multi-type if we have attachment */
-       if (has_attach && *has_attach) {
-               line = talloc_asprintf(mem_ctx, "Content-Type: multipart/mixed; 
boundary=\"%s\"\n", BOUNDARY);
-               if (line) fwrite(line, strlen(line), 1, fp);
-               talloc_free(line);
-       }
-
        /* body */
        if (body.length) {
                if (has_attach && *has_attach) {
@@ -713,7 +737,7 @@
                                             rowset.aRow[i].lpProps[1].value.d, 
                                             &obj_message, 0);
                        if (GetLastError() == MAPI_E_SUCCESS) {
-                               SPropTagArray = set_SPropTagArray(mem_ctx, 0x13,
+                               SPropTagArray = set_SPropTagArray(mem_ctx, 0x14,
                                                                  
PR_INTERNET_MESSAGE_ID,
                                                                  
PR_INTERNET_MESSAGE_ID_UNICODE,
                                                                  
PR_CONVERSATION_TOPIC,
@@ -732,7 +756,8 @@
                                                                  
PR_DISPLAY_CC_UNICODE,
                                                                  
PR_DISPLAY_BCC,
                                                                  
PR_DISPLAY_BCC_UNICODE,
-                                                                 PR_HASATTACH);
+                                                                 PR_HASATTACH,
+                                                                 
PR_TRANSPORT_MESSAGE_HEADERS);
                                retval = GetProps(&obj_message, SPropTagArray, 
&lpProps, &count);
                                MAPIFreeBuffer(SPropTagArray);
                                if (retval != MAPI_E_SUCCESS) return false;
_______________________________________________
devel mailing list
[email protected]
http://mailman.openchange.org/listinfo/devel

Reply via email to