Mercurial > libpst
comparison 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 |
comparison
equal
deleted
inserted
replaced
372:5b52efe35bd8 | 373:0ccc746c8079 |
---|---|
64 int write_extra_categories(FILE* f_output, pst_item* item); | 64 int write_extra_categories(FILE* f_output, pst_item* item); |
65 void write_journal(FILE* f_output, pst_item* item); | 65 void write_journal(FILE* f_output, pst_item* item); |
66 void write_appointment(FILE* f_output, pst_item *item); | 66 void write_appointment(FILE* f_output, pst_item *item); |
67 void create_enter_dir(struct file_ll* f, pst_item *item); | 67 void create_enter_dir(struct file_ll* f, pst_item *item); |
68 void close_enter_dir(struct file_ll *f); | 68 void close_enter_dir(struct file_ll *f); |
69 char* quote_string(char *inp); | |
69 | 70 |
70 const char* prog_name; | 71 const char* prog_name; |
71 char* output_dir = "."; | 72 char* output_dir = "."; |
72 | 73 |
73 // Normal mode just creates mbox format files in the current directory. Each file is named | 74 // Normal mode just creates mbox format files in the current directory. Each file is named |
1149 } | 1150 } |
1150 | 1151 |
1151 DEBUG_RET(); | 1152 DEBUG_RET(); |
1152 } | 1153 } |
1153 | 1154 |
1155 /** | |
1156 * Backslash-escape quotes and backslashes in the given string. | |
1157 */ | |
1158 char *quote_string(char *inp) { | |
1159 int i = 0; | |
1160 int count = 0; | |
1161 char *curr = inp; | |
1162 while (*curr) { | |
1163 *curr++; | |
1164 if (*curr == '\"' || *curr == '\\') { | |
1165 count++; | |
1166 } | |
1167 i++; | |
1168 } | |
1169 char *res = malloc(i + count + 1); | |
1170 char *curr_in = inp; | |
1171 char *curr_out = res; | |
1172 while (*curr_in) { | |
1173 if (*curr_in == '\"' || *curr_in == '\\') { | |
1174 *curr_out++ = '\\'; | |
1175 } | |
1176 *curr_out++ = *curr_in++; | |
1177 } | |
1178 *curr_out = '\0'; | |
1179 return res; | |
1180 } | |
1154 | 1181 |
1155 void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst) | 1182 void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst) |
1156 { | 1183 { |
1157 DEBUG_ENT("write_inline_attachment"); | 1184 DEBUG_ENT("write_inline_attachment"); |
1158 DEBUG_INFO(("Attachment Size is %#"PRIx64", data = %#"PRIxPTR", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->data.data, attach->i_id)); | 1185 DEBUG_INFO(("Attachment Size is %#"PRIx64", data = %#"PRIxPTR", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->data.data, attach->i_id)); |
1180 } | 1207 } |
1181 | 1208 |
1182 if (attach->filename2.str) { | 1209 if (attach->filename2.str) { |
1183 // use the long filename, converted to proper encoding if needed. | 1210 // use the long filename, converted to proper encoding if needed. |
1184 // it is already utf8 | 1211 // it is already utf8 |
1212 char *escaped = quote_string(attach->filename2.str); | |
1185 pst_rfc2231(&attach->filename2); | 1213 pst_rfc2231(&attach->filename2); |
1186 fprintf(f_output, "Content-Disposition: attachment; \n filename*=%s\n\n", attach->filename2.str); | 1214 fprintf(f_output, "Content-Disposition: attachment; \n filename*=%s;\n", attach->filename2.str); |
1215 // Also include the (escaped) utf8 filename in the 'filename' header directly - this is not strictly valid | |
1216 // (since this header should be ASCII) but is almost always handled correctly (and in fact this is the only | |
1217 // way to get MS Outlook to correctly read a UTF8 filename, AFAICT, which is why we're doing it). | |
1218 fprintf(f_output, " filename=\"%s\"\n\n", escaped); | |
1219 free(escaped); | |
1187 } | 1220 } |
1188 else if (attach->filename1.str) { | 1221 else if (attach->filename1.str) { |
1189 // short filename never needs encoding | 1222 // short filename never needs encoding |
1190 fprintf(f_output, "Content-Disposition: attachment; filename=\"%s\"\n\n", attach->filename1.str); | 1223 fprintf(f_output, "Content-Disposition: attachment; filename=\"%s\"\n\n", attach->filename1.str); |
1191 } | 1224 } |