@@ -174,6 +174,28 @@ int textcontent(char *type)
174
174
return 0 ;
175
175
}
176
176
177
+ static int applemail_ua (char * ua_string )
178
+ {
179
+ /* returns TRUE if the ua_string is one of the declared applemail
180
+ * clients */
181
+
182
+ int res = FALSE;
183
+
184
+ if (ua_string && * ua_string != '\0' ) {
185
+ char * buff ;
186
+ char * ptr ;
187
+
188
+ buff = strsav (ua_string );
189
+ ptr = strstr (buff , " (" );
190
+ if (ptr ) {
191
+ * ptr = '\0' ;
192
+ res = inlist (set_applemail_ua_value , buff );
193
+ }
194
+ free (buff );
195
+ }
196
+
197
+ return TRUE;
198
+ }
177
199
178
200
/*
179
201
* Should return TRUE if the input is a Re: start. The end pointer should
@@ -1197,24 +1219,6 @@ static int do_uudecode(FILE *fp, char *line, char *line_buf,
1197
1219
return 1 ;
1198
1220
}
1199
1221
1200
- /*
1201
- * If we have a multipart/alternative header,
1202
- * return a new header that uses multipart/mixed. This will allow to see the
1203
- * the attachments that are only added to the text/html alternative.
1204
- */
1205
- static char * mpa_as_mpm (char * content_type )
1206
- {
1207
- char * new_header ;
1208
-
1209
- if (!strncasecmp (content_type + 14 , "multipart/alternative" , 21 )) {
1210
- new_header = replace (content_type , "/alternative" , "/mixed" );
1211
- } else {
1212
- new_header = NULL ;
1213
- }
1214
-
1215
- return new_header ;
1216
- }
1217
-
1218
1222
static void write_txt_file (struct emailinfo * emp , struct Push * raw_text_buf )
1219
1223
{
1220
1224
char * txt_filename ;
@@ -1272,6 +1276,7 @@ int parsemail(char *mbox, /* file name */
1272
1276
time_t delete_newer_than = (set_delete_newer ? convtoyearsecs (set_delete_newer ) : 0 );
1273
1277
int is_deleted = 0 ;
1274
1278
int parse_multipart_alternative_as_mixed = 0 ; /* the hack needed for applemail */
1279
+ int old_set_save_alts = 0 ;
1275
1280
int applemail_ua_header_len = (set_applemail_mimehack ) ? strlen (set_applemail_ua_header ) : 0 ;
1276
1281
int pos ;
1277
1282
bool * require_filter , * require_filter_full ;
@@ -1399,6 +1404,9 @@ int parsemail(char *mbox, /* file name */
1399
1404
bp = NULL ;
1400
1405
subject = NOSUBJECT ;
1401
1406
1407
+ parse_multipart_alternative_as_mixed = 0 ;
1408
+ old_set_save_alts = 0 ;
1409
+
1402
1410
require_filter_len = require_filter_full_len = 0 ;
1403
1411
for (tlist = set_filter_require ; tlist != NULL ; require_filter_len ++ , tlist = tlist -> next )
1404
1412
;
@@ -1582,17 +1590,20 @@ int parsemail(char *mbox, /* file name */
1582
1590
else if (!strncasecmp (head -> line , "Content-Type:" , 13 )) {
1583
1591
content_type_p = head ;
1584
1592
}
1585
- else if (set_applemail_mimehack
1593
+ else if (!set_save_alts
1594
+ && set_applemail_mimehack
1595
+ && set_applemail_ua_header && * set_applemail_ua_header
1586
1596
&& Mime_B
1587
1597
&& !alternativeparser
1588
1598
&& !strncasecmp (head_name ,
1589
1599
set_applemail_ua_header ,
1590
- applemail_ua_header_len )
1591
- && !strncasecmp (head -> line + applemail_ua_header_len + 2 ,
1592
- set_applemail_ua_value ,
1593
- strlen (set_applemail_ua_value ))) {
1594
- /* If we need the applemail hack, set a flag if we detected the UA */
1595
- parse_multipart_alternative_as_mixed = 1 ;
1600
+ applemail_ua_header_len )) {
1601
+ /* If we need the applemail hack, set a flag
1602
+ * if we detected the UA */
1603
+ head -> parsedheader = TRUE;
1604
+ if (applemail_ua (head -> line + applemail_ua_header_len + 2 )) {
1605
+ parse_multipart_alternative_as_mixed = 1 ;
1606
+ }
1596
1607
}
1597
1608
}
1598
1609
@@ -1610,16 +1621,14 @@ int parsemail(char *mbox, /* file name */
1610
1621
if (email_time != -1 && email_time > delete_newer_than )
1611
1622
is_deleted = FILTERED_NEW ;
1612
1623
}
1613
- if (set_applemail_mimehack && parse_multipart_alternative_as_mixed ) {
1614
- char * new_header ;
1615
-
1616
- new_header = mpa_as_mpm (content_type_p -> line );
1617
- if (new_header ) {
1618
- free (content_type_p -> line );
1619
- content_type_p -> line = new_header ;
1624
+ if (parse_multipart_alternative_as_mixed == 1 ) {
1625
+ if (!strncasecmp (content_type_p -> line + 14 , "multipart/alternative" , 21 )) {
1626
+ old_set_save_alts = set_save_alts ;
1627
+ set_save_alts = 1 ;
1620
1628
}
1629
+
1621
1630
/* turn off the flag to avoid redoing this check again */
1622
- parse_multipart_alternative_as_mixed = 0 ;
1631
+ parse_multipart_alternative_as_mixed = 2 ;
1623
1632
}
1624
1633
if (!headp )
1625
1634
headp = bp ;
@@ -2287,7 +2296,11 @@ msgid);
2287
2296
2288
2297
alternativeparser = FALSE; /* there is none anymore */
2289
2298
2290
- parse_multipart_alternative_as_mixed = 0 ;
2299
+ if (parse_multipart_alternative_as_mixed ) {
2300
+ set_save_alts = old_set_save_alts ;
2301
+ old_set_save_alts = 0 ;
2302
+ parse_multipart_alternative_as_mixed = 0 ;
2303
+ }
2291
2304
2292
2305
if (!(num % 10 ) && set_showprogress && !readone ) {
2293
2306
print_progress (num - startnum , NULL , NULL );
0 commit comments