Index: utils/exchange2mbox.c =================================================================== --- utils/exchange2mbox.c (revision 943) +++ utils/exchange2mbox.c (working copy) @@ -340,7 +340,6 @@ const uint32_t *has_attach = NULL; const uint32_t *attach_num = NULL; char *magic; - char *line = NULL; struct SPropTagArray *SPropTagArray = NULL; struct SPropValue *lpProps; struct SRow aRow2; @@ -372,91 +371,60 @@ retval = octool_get_body(mem_ctx, obj_message, aRow, &body); /* First line From */ - line = talloc_asprintf(mem_ctx, "From \"%s\" %s\n", from, date); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "From \"%s\" %s\n", from, date); /* Second line: Date */ - line = talloc_asprintf(mem_ctx, "Date: %s\n", date); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "Date: %s\n", date); /* Third line From */ - line = talloc_asprintf(mem_ctx, "From: %s\n", from); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "From: %s\n", from); /* 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); + fprintf(fp, "To: %s\n", to); } - if (cc) { - line = talloc_asprintf(mem_ctx, "Cc: %s\n", cc); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + if (cc && strlen(cc)) { + fprintf(fp, "Cc: %s\n", cc); } if (bcc) { - line = talloc_asprintf(mem_ctx, "Bcc: %s\n", bcc); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "Bcc: %s\n", bcc); } /* Subject */ if (subject) { - line = talloc_asprintf(mem_ctx, "Subject: %s\n", subject); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "Subject: %s\n", subject); } if (msgid) { - line = talloc_asprintf(mem_ctx, "Message-ID: %s\n", msgid); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "Message-ID: %s\n", msgid); } /* 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); + fprintf(fp, "Content-Type: multipart/mixed; boundary=\"%s\"\n", BOUNDARY); } /* body */ if (body.length) { if (has_attach && *has_attach) { - line = talloc_asprintf(mem_ctx, "--%s\n", BOUNDARY); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "--%s\n", BOUNDARY); } retval = GetBestBody(obj_message, &format); switch (format) { case olEditorText: - line = talloc_asprintf(mem_ctx, "Content-Type: text/plain; charset=us-ascii\n"); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "Content-Type: text/plain; charset=us-ascii\n"); /* Just display UTF8 content inline */ - line = talloc_asprintf(mem_ctx, "Content-Disposition: inline\n"); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "Content-Disposition: inline\n"); break; case olEditorHTML: - line = talloc_asprintf(mem_ctx, "Content-Type: text/html\n"); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "Content-Type: text/html\n"); break; case olEditorRTF: - line = talloc_asprintf(mem_ctx, "Content-Type: text/rtf\n"); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); - - line = talloc_asprintf(mem_ctx, "--%s\n", BOUNDARY); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "Content-Type: text/rtf\n"); + fprintf(fp, "--%s\n", BOUNDARY); break; } @@ -500,39 +468,24 @@ attach_size = (const uint32_t *) octool_get_propval(&aRow2, PR_ATTACH_SIZE); attachment_data = get_base64_attachment(mem_ctx, obj_attach, *attach_size, &magic); if (attachment_data) { - line = talloc_asprintf(mem_ctx, "\n\n--%s\n", BOUNDARY); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); - - line = talloc_asprintf(mem_ctx, "Content-Disposition: attachment; filename=\"%s\"\n", attach_filename); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); - - line = talloc_asprintf(mem_ctx, "Content-Type: \"%s\"\n", magic); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); - - line = talloc_asprintf(mem_ctx, "Content-Transfer-Encoding: base64\n\n"); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); - - fwrite(attachment_data, strlen(attachment_data), 1, fp); - talloc_free(attachment_data); + fprintf(fp, "\n\n--%s\n", BOUNDARY); + fprintf(fp, "Content-Disposition: attachment; filename=\"%s\"\n", attach_filename); + fprintf(fp, "Content-Type: \"%s\"\n", magic); + fprintf(fp, "Content-Transfer-Encoding: base64\n\n"); + fputs(attachment_data, fp); } } MAPIFreeBuffer(lpProps); } } if (has_attach && *has_attach) { - line = talloc_asprintf(mem_ctx, "\n\n--%s--\n\n\n", BOUNDARY); - if (line) fwrite(line, strlen(line), 1, fp); - talloc_free(line); + fprintf(fp, "\n\n--%s--\n\n\n", BOUNDARY); } } } - fwrite("\n\n\n", 3, 1, fp); + fputs("\n\n\n", fp); return true; }