@@ -1503,7 +1503,7 @@ int parsemail(char *mbox, /* file name */
1503
1503
FileStatus alternative_lastfile_created = NO_FILE ; /* previous alternative attachments, for non-inline MIME types */
1504
1504
char alternative_file [129 ]; /* file name where we store the non-inline alternatives */
1505
1505
char alternative_lastfile [129 ]; /* last file name where we store the non-inline alternatives */
1506
- char alternative_type [129 ]; /* the alternative Content-Type value */
1506
+ char last_alternative_type [129 ]; /* the alternative Content-Type value */
1507
1507
int att_counter = 0 ; /* used to generate a unique name for attachments */
1508
1508
int parse_multipart_alternative_force_save_alts = 0 ; /* used to control if we are parsing alternative as multipart */
1509
1509
int old_set_save_alts = -1 ; /* used to store the set_save_alts when overriding it for apple mail */
@@ -1534,7 +1534,7 @@ int parsemail(char *mbox, /* file name */
1534
1534
1535
1535
struct boundary * multipartp = NULL ; /* This variable is used to store a stack of
1536
1536
mimetypes in cases with mulitpart mails */
1537
- bool waiting_for_boundary = FALSE; /* This variable is used to help skip multipart/foo
1537
+ bool skip_mime_epilogue = FALSE; /* This variable is used to help skip multipart/foo
1538
1538
epilogues */
1539
1539
1540
1540
char multilinenoend = FALSE; /* This variable is set TRUE if we have read
@@ -1673,7 +1673,16 @@ int parsemail(char *mbox, /* file name */
1673
1673
progerr ("Can't write to \"mbox\"" ); /* revisit me */
1674
1674
}
1675
1675
}
1676
- line = line_buf + set_ietf_mbox ;
1676
+ line = line_buf + set_ietf_mbox ;
1677
+
1678
+ if (skip_mime_epilogue ) {
1679
+ if (line [0 ] == '\n' ) {
1680
+ continue ;
1681
+ } else {
1682
+ skip_mime_epilogue = FALSE;
1683
+ }
1684
+ }
1685
+
1677
1686
if (!is_deleted &&
1678
1687
inlist_regex_pos (set_filter_out_full_body , line ) != -1 ) {
1679
1688
is_deleted = FILTERED_OUT ;
@@ -1824,8 +1833,8 @@ int parsemail(char *mbox, /* file name */
1824
1833
content_type_p = head ;
1825
1834
}
1826
1835
else if (applemail_ua_header_len > 0
1827
- && !strncasecmp (head_name , set_applemail_ua_header ,
1828
- applemail_ua_header_len )) {
1836
+ && !strncasecmp (head_name , set_applemail_ua_header ,
1837
+ applemail_ua_header_len )) {
1829
1838
/* we only need to set this one up once per message*/
1830
1839
head -> parsedheader = TRUE;
1831
1840
if (alternativeparser
@@ -1842,19 +1851,22 @@ int parsemail(char *mbox, /* file name */
1842
1851
*/
1843
1852
if (!parse_multipart_alternative_force_save_alts
1844
1853
&& is_applemail_ua (head -> line + applemail_ua_header_len + 2 )) {
1845
-
1854
+
1846
1855
parse_multipart_alternative_force_save_alts = 1 ;
1847
- old_set_save_alts = set_save_alts ;
1848
- /* to avoid confusion and quoting out of
1856
+
1857
+ /* to avoid confusion and quoting out of
1849
1858
** context, we won't show the alternatives
1850
1859
** in-line.
1851
1860
*/
1861
+
1862
+ old_set_save_alts = set_save_alts ;
1852
1863
set_save_alts = 2 ;
1864
+
1853
1865
#if DEBUG_PARSE
1854
1866
printf ("Applemail_hack force save_alts: yes\n" );
1855
- printf ("Applemail_hack set_save_alts changed from %d to %d\n" ,
1867
+ printf ("Applemail_hack set_save_alts changed from %d to %d\n" ,
1856
1868
old_set_save_alts , set_save_alts );
1857
- #endif
1869
+ #endif
1858
1870
}
1859
1871
}
1860
1872
}
@@ -1877,7 +1889,6 @@ int parsemail(char *mbox, /* file name */
1877
1889
if (!headp )
1878
1890
headp = bp ;
1879
1891
1880
-
1881
1892
savealternative = FALSE;
1882
1893
attach_force = FALSE;
1883
1894
@@ -2040,16 +2051,38 @@ int parsemail(char *mbox, /* file name */
2040
2051
if (alternativeparser ) {
2041
2052
struct body * next ;
2042
2053
struct body * temp_bp = NULL ;
2043
-
2054
+
2044
2055
/* We are parsing alternatives... */
2045
2056
2057
+ if (parse_multipart_alternative_force_save_alts
2058
+ && multipartp
2059
+ && !strcasecmp (multipartp -> line , "multipart/alternative" )
2060
+ && * last_alternative_type
2061
+ && !strcasecmp (last_alternative_type , "text/plain" )) {
2062
+
2063
+ /* if the UA is Apple mail and if the only
2064
+ ** alternatives are text/plain and
2065
+ ** text/html and if the preference is
2066
+ ** text/plain, skip the text/html version
2067
+ ** if the applemail_hack is enabled
2068
+ */
2069
+ if (!strcasecmp (type , "text/html" )) {
2070
+ #if DEBUG_PARSE
2071
+ fprintf (stderr , "Discarding apparently equivalent text//html alternative\n" );
2072
+ #endif
2073
+ content = CONTENT_IGNORE ;
2074
+ break ;
2075
+ }
2076
+ }
2077
+
2046
2078
if (preferedcontent (& alternative_weight , type , decode )) {
2047
2079
/* ... this is a prefered type, we want to store
2048
2080
this [instead of the earlier one]. */
2049
2081
/* erase the previous alternative info */
2050
2082
temp_bp = alternative_bp ; /* remember the value of bp for GC */
2051
2083
alternative_bp = alternative_lp = NULL ;
2052
- strcpy (alternative_type , type );
2084
+ strncpy (last_alternative_type , type ,
2085
+ sizeof (last_alternative_type ) - 1 );
2053
2086
alternative_lastfile_created = NO_FILE ;
2054
2087
content = CONTENT_UNKNOWN ;
2055
2088
if (alternative_lastfile [0 ] != '\0' ) {
@@ -2064,7 +2097,7 @@ int parsemail(char *mbox, /* file name */
2064
2097
/* ...and this type is not a prefered one. Thus, we
2065
2098
* shall ignore it completely! */
2066
2099
content = CONTENT_IGNORE ;
2067
- /* erase the current alternative info */
2100
+ /* erase the current alternative info */
2068
2101
temp_bp = bp ; /* remember the value of bp for GC */
2069
2102
lp = alternative_lp ;
2070
2103
bp = alternative_bp ;
@@ -2077,7 +2110,8 @@ int parsemail(char *mbox, /* file name */
2077
2110
alternative_lastfile [0 ] = '\0' ;
2078
2111
/* we haven't yet created any attachment file, so there's no need
2079
2112
to erase it yet */
2080
- }
2113
+ }
2114
+
2081
2115
/* free any previous alternative */
2082
2116
while (temp_bp ) {
2083
2117
next = temp_bp -> next ;
@@ -2086,34 +2120,13 @@ int parsemail(char *mbox, /* file name */
2086
2120
free (temp_bp );
2087
2121
temp_bp = next ;
2088
2122
}
2123
+
2089
2124
/* @@ not sure if I should add a diff flag to do this break */
2090
2125
if (content == CONTENT_IGNORE )
2091
2126
/* end the header parsing... we already know what we want */
2092
2127
break ;
2093
2128
}
2094
2129
2095
- if (content == CONTENT_BINARY
2096
- && set_save_alts && alternativeparser
2097
- && parse_multipart_alternative_force_save_alts
2098
- && multipartp
2099
- && !strcasecmp (multipartp -> line , "multipart/alternative" )
2100
- && (!strcasecmp (type , "text/html" )
2101
- && * alternative_type
2102
- && !strcasecmp (alternative_type , "text/plain" ))) {
2103
- /* if the UA is Apple mail and if the only
2104
- ** alternatives are text/plain and
2105
- ** text/html and if the preference is
2106
- ** text/plain, skip the text/html version
2107
- ** if the applemail_hack is enabled
2108
- */
2109
- content = CONTENT_IGNORE ;
2110
-
2111
- #if DEBUG_PARSE
2112
- printf ("Discarding apparently equivalent text//html alternative\n" );
2113
- #endif
2114
- continue ;
2115
- }
2116
-
2117
2130
if (content == CONTENT_IGNORE )
2118
2131
continue ;
2119
2132
else if (ignorecontent (type ))
@@ -2268,7 +2281,7 @@ int parsemail(char *mbox, /* file name */
2268
2281
*/
2269
2282
boundp = bound (boundp , boundbuffer );
2270
2283
multipartp = multipart (multipartp , type );
2271
- waiting_for_boundary = FALSE;
2284
+ skip_mime_epilogue = FALSE;
2272
2285
2273
2286
/* printf("set new boundary: %s\n", boundp->line); */
2274
2287
@@ -2388,7 +2401,7 @@ int parsemail(char *mbox, /* file name */
2388
2401
alternative_lp = alternative_bp = NULL ;
2389
2402
alternative_lastfile_created = NO_FILE ;
2390
2403
alternative_file [0 ] = alternative_lastfile [0 ] = '\0' ;
2391
- alternative_type [0 ] = '\0' ;
2404
+ last_alternative_type [0 ] = '\0' ;
2392
2405
}
2393
2406
headp = lp ; /* start at this point next time */
2394
2407
}
@@ -2588,7 +2601,7 @@ msgid);
2588
2601
content = CONTENT_TEXT ;
2589
2602
decode = ENCODE_NORMAL ;
2590
2603
Mime_B = FALSE;
2591
- waiting_for_boundary = FALSE;
2604
+ skip_mime_epilogue = FALSE;
2592
2605
headp = NULL ;
2593
2606
content_type_p = NULL ;
2594
2607
multilinenoend = FALSE;
@@ -2681,14 +2694,13 @@ msgid);
2681
2694
printf ("alternativeparser %d\n" , alternativeparser );
2682
2695
printf ("has_more_alternatives %d\n" , has_multipart (multipartp , "multipart/alternative" ));
2683
2696
#endif
2697
+
2684
2698
boundp = bound (boundp , NULL );
2685
2699
if (!boundp ) {
2686
2700
bodyflags &= ~BODY_ATTACHED ;
2687
- waiting_for_boundary = FALSE;
2688
- } else {
2689
- /* skip the MIME epilogue until the next section */
2690
- waiting_for_boundary = TRUE;
2691
2701
}
2702
+ /* skip the MIME epilogue until the next section (or next message!) */
2703
+ skip_mime_epilogue = TRUE;
2692
2704
multipartp = multipart (multipartp , NULL );
2693
2705
if (alternativeparser
2694
2706
&& !has_multipart (multipartp , "multipart/alternative" )) {
@@ -2709,16 +2721,16 @@ msgid);
2709
2721
alternative_lastfile_created = NO_FILE ;
2710
2722
alternative_file [0 ] =
2711
2723
alternative_lastfile [0 ] = '\0' ;
2712
- alternative_type [0 ] = '\0' ;
2724
+ last_alternative_type [0 ] = '\0' ;
2713
2725
#if DEBUG_PARSE
2714
2726
printf ("We DUMP the chosen alternative\n" );
2715
2727
#endif
2716
2728
if (bp != origbp )
2717
2729
origbp = append_body (origbp , & origlp , bp );
2718
2730
bp = origbp ;
2719
2731
lp = origlp ;
2720
- origbp = origlp = NULL ;
2721
-
2732
+ origbp = origlp = NULL ;
2733
+
2722
2734
headp = NULL ;
2723
2735
}
2724
2736
#if DEBUG_PARSE
@@ -2735,7 +2747,7 @@ msgid);
2735
2747
}
2736
2748
else {
2737
2749
/* we found the beginning of a new section */
2738
- waiting_for_boundary = FALSE;
2750
+ skip_mime_epilogue = FALSE;
2739
2751
2740
2752
if (alternativeparser && !set_save_alts ) {
2741
2753
/*
@@ -2748,17 +2760,12 @@ msgid);
2748
2760
file_created ;
2749
2761
strcpy (alternative_lastfile ,
2750
2762
alternative_file );
2751
- strcpy (alternative_type , type );
2763
+ strncpy (last_alternative_type , type ,
2764
+ sizeof (last_alternative_type ) - 1 );
2752
2765
2753
2766
/* and now reset them */
2754
2767
headp = bp = lp = NULL ;
2755
2768
alternative_file [0 ] = '\0' ;
2756
- #if 0
2757
- /* @@ JK: review if att_counter is updated even with content ignore */
2758
- if (set_save_alts && parse_multipart_alternative_force_save_alts ) {
2759
- att_counter ++ ;
2760
- }
2761
- #endif
2762
2769
}
2763
2770
else {
2764
2771
att_counter ++ ;
@@ -2794,10 +2801,6 @@ msgid);
2794
2801
}
2795
2802
continue ;
2796
2803
}
2797
- else if (waiting_for_boundary ) {
2798
- /* waiting for the next '--foo' */
2799
- continue ;
2800
- }
2801
2804
}
2802
2805
2803
2806
switch (decode ) {
@@ -3074,9 +3077,8 @@ msgid);
3074
3077
1 );
3075
3078
/* save the last mime type to help deal with the
3076
3079
* apple mail hack */
3077
- strncpy (alternative_type , type ,
3078
- sizeof (alternative_type ) -
3079
- 1 );
3080
+ strncpy (last_alternative_type , type ,
3081
+ sizeof (last_alternative_type ) - 1 );
3080
3082
}
3081
3083
3082
3084
}
@@ -3086,7 +3088,7 @@ msgid);
3086
3088
alternative_file [0 ] = '\0' ;
3087
3089
/* save the last mime type to help deal with the apple
3088
3090
* hack */
3089
- alternative_type [0 ] = '\0' ;
3091
+ last_alternative_type [0 ] = '\0' ;
3090
3092
}
3091
3093
}
3092
3094
@@ -3349,7 +3351,7 @@ msgid);
3349
3351
content = CONTENT_TEXT ;
3350
3352
decode = ENCODE_NORMAL ;
3351
3353
Mime_B = FALSE;
3352
- waiting_for_boundary = FALSE;
3354
+ skip_mime_epilogue = FALSE;
3353
3355
headp = NULL ;
3354
3356
multilinenoend = FALSE;
3355
3357
if (att_dir ) {
@@ -3370,6 +3372,21 @@ msgid);
3370
3372
att_name_list = NULL ;
3371
3373
description = NULL ;
3372
3374
3375
+ if (parse_multipart_alternative_force_save_alts ) {
3376
+ parse_multipart_alternative_force_save_alts = 0 ;
3377
+
3378
+ #if DEBUG_PARSE
3379
+ printf ("Applemail_hack resetting parse_multipart_alternative_force_save_alts\n" );
3380
+ #endif
3381
+ if (old_set_save_alts != -1 ) {
3382
+ set_save_alts = old_set_save_alts ;
3383
+ old_set_save_alts = -1 ;
3384
+ #if DEBUG_PARSE
3385
+ printf ("Applemail_hack resetting save_alts to %d\n" , old_set_save_alts );
3386
+ #endif
3387
+ }
3388
+ }
3389
+
3373
3390
/* by default we have none! */
3374
3391
hassubject = 0 ;
3375
3392
hasdate = 0 ;
@@ -4658,4 +4675,3 @@ int count_deleted(int limit)
4658
4675
}
4659
4676
return total ;
4660
4677
}
4661
-
0 commit comments