Mercurial > libpst
diff src/readpst.c @ 373:0ccc746c8079
Zachary Travis - Add support for the OST 2013 format, and Content-Disposition filename key fix for outlook compatibility
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 21 Jul 2017 20:01:44 -0700 |
parents | 6b7c19a820e1 |
children | 1e1970f93f94 |
line wrap: on
line diff
--- a/src/readpst.c Fri Jul 21 19:54:46 2017 -0700 +++ b/src/readpst.c Fri Jul 21 20:01:44 2017 -0700 @@ -66,6 +66,7 @@ void write_appointment(FILE* f_output, pst_item *item); void create_enter_dir(struct file_ll* f, pst_item *item); void close_enter_dir(struct file_ll *f); +char* quote_string(char *inp); const char* prog_name; char* output_dir = "."; @@ -1151,6 +1152,32 @@ DEBUG_RET(); } +/** + * Backslash-escape quotes and backslashes in the given string. + */ +char *quote_string(char *inp) { + int i = 0; + int count = 0; + char *curr = inp; + while (*curr) { + *curr++; + if (*curr == '\"' || *curr == '\\') { + count++; + } + i++; + } + char *res = malloc(i + count + 1); + char *curr_in = inp; + char *curr_out = res; + while (*curr_in) { + if (*curr_in == '\"' || *curr_in == '\\') { + *curr_out++ = '\\'; + } + *curr_out++ = *curr_in++; + } + *curr_out = '\0'; + return res; +} void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst) { @@ -1182,8 +1209,14 @@ if (attach->filename2.str) { // use the long filename, converted to proper encoding if needed. // it is already utf8 + char *escaped = quote_string(attach->filename2.str); pst_rfc2231(&attach->filename2); - fprintf(f_output, "Content-Disposition: attachment; \n filename*=%s\n\n", attach->filename2.str); + fprintf(f_output, "Content-Disposition: attachment; \n filename*=%s;\n", attach->filename2.str); + // Also include the (escaped) utf8 filename in the 'filename' header directly - this is not strictly valid + // (since this header should be ASCII) but is almost always handled correctly (and in fact this is the only + // way to get MS Outlook to correctly read a UTF8 filename, AFAICT, which is why we're doing it). + fprintf(f_output, " filename=\"%s\"\n\n", escaped); + free(escaped); } else if (attach->filename1.str) { // short filename never needs encoding