Skip to content

Commit 1678679

Browse files
committed
Rather than converting the content-type from multipart/alternative
to multipart/mixed, use hypermail's set_save_alts to do the same in a cleaner way. The Apple Mail ua header value may change depening on what device is used. Changed set_applemail_ua_value to a list so that new ones can be added if needed. The default list values are "Apple iPhone" (concatenanted to "Mail (" during the check (
1 parent efeac9c commit 1678679

File tree

4 files changed

+56
-41
lines changed

4 files changed

+56
-41
lines changed

src/defaults.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@
3131

3232
#define ANTISPAM_AT "_at_"
3333

34+
#define APPLE_MAIL_UA "Apple iPhone"
35+
3436
#endif

src/parse.c

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,28 @@ int textcontent(char *type)
174174
return 0;
175175
}
176176

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+
}
177199

178200
/*
179201
* 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,
11971219
return 1;
11981220
}
11991221

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-
12181222
static void write_txt_file(struct emailinfo *emp, struct Push *raw_text_buf)
12191223
{
12201224
char *txt_filename;
@@ -1272,6 +1276,7 @@ int parsemail(char *mbox, /* file name */
12721276
time_t delete_newer_than = (set_delete_newer ? convtoyearsecs(set_delete_newer) : 0);
12731277
int is_deleted = 0;
12741278
int parse_multipart_alternative_as_mixed = 0; /* the hack needed for applemail */
1279+
int old_set_save_alts = 0;
12751280
int applemail_ua_header_len = (set_applemail_mimehack) ? strlen (set_applemail_ua_header) : 0;
12761281
int pos;
12771282
bool *require_filter, *require_filter_full;
@@ -1399,6 +1404,9 @@ int parsemail(char *mbox, /* file name */
13991404
bp = NULL;
14001405
subject = NOSUBJECT;
14011406

1407+
parse_multipart_alternative_as_mixed = 0;
1408+
old_set_save_alts = 0;
1409+
14021410
require_filter_len = require_filter_full_len = 0;
14031411
for (tlist = set_filter_require; tlist != NULL; require_filter_len++, tlist = tlist->next)
14041412
;
@@ -1582,17 +1590,20 @@ int parsemail(char *mbox, /* file name */
15821590
else if (!strncasecmp (head->line, "Content-Type:", 13)) {
15831591
content_type_p = head;
15841592
}
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
15861596
&& Mime_B
15871597
&& !alternativeparser
15881598
&& !strncasecmp(head_name,
15891599
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+
}
15961607
}
15971608
}
15981609

@@ -1610,16 +1621,14 @@ int parsemail(char *mbox, /* file name */
16101621
if (email_time != -1 && email_time > delete_newer_than)
16111622
is_deleted = FILTERED_NEW;
16121623
}
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;
16201628
}
1629+
16211630
/* turn off the flag to avoid redoing this check again */
1622-
parse_multipart_alternative_as_mixed = 0;
1631+
parse_multipart_alternative_as_mixed = 2;
16231632
}
16241633
if (!headp)
16251634
headp = bp;
@@ -2287,7 +2296,11 @@ msgid);
22872296

22882297
alternativeparser = FALSE; /* there is none anymore */
22892298

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+
}
22912304

22922305
if (!(num % 10) && set_showprogress && !readone) {
22932306
print_progress(num - startnum, NULL, NULL);

src/setup.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ bool set_use_sender_date;
7777
bool set_inline_addlink;
7878
bool set_applemail_mimehack;
7979
char *set_applemail_ua_header;
80-
char *set_applemail_ua_value;
8180

8281
int set_showhtml;
8382
int set_thrdlevels;
@@ -128,6 +127,7 @@ struct hmlist *set_filter_out = NULL;
128127
struct hmlist *set_filter_require = NULL;
129128
struct hmlist *set_filter_out_full_body = NULL;
130129
struct hmlist *set_filter_require_full_body = NULL;
130+
struct hmlist *set_applemail_ua_value;
131131

132132
char *set_ihtmlheader;
133133
char *set_ihtmlfooter;
@@ -497,8 +497,8 @@ struct Config cfg[] = {
497497
"# This option is only useful if you enabled the applemail_mimehack configuration\n"
498498
"# option.\n", FALSE},
499499

500-
{"applemail_ua_value", &set_applemail_ua_value, "Apple Mail (", CFG_STRING,
501-
"# Set to the beginning of the header value that Apple Mail uses to identify\n"
500+
{"applemail_ua_value", &set_applemail_ua_value, APPLE_MAIL_UA, CFG_LIST,
501+
"# Set to the list of the header value that Apple Mail uses to identify\n"
502502
" its mail agent. Do not add the version number unless you know what you're doing.\n"
503503
"# This option is only useful if you enabled the applemail_mimehack configuration\n"
504504
"# option.\n", FALSE},
@@ -1257,8 +1257,6 @@ void dump_config(void)
12571257
printf("set_latest_folder = %s\n",set_latest_folder ? set_latest_folder : "Not set");
12581258
printf("set_antispamdomain = %s\n",set_antispamdomain ? set_antispamdomain : "Not set");
12591259
printf("set_applemail_ua_header = %s\n",set_applemail_ua_header ? set_applemail_ua_header : "Not set");
1260-
printf("set_applemail_ua_value = %s\n",set_applemail_ua_value ? set_applemail_ua_value : "Not set");
1261-
12621260

12631261
/* Boolean or integer */
12641262

@@ -1386,7 +1384,9 @@ void dump_config(void)
13861384
print_list("set_deleted", set_deleted);
13871385
print_list("set_expires", set_expires);
13881386
print_list("set_delete_msgnum", set_delete_msgnum);
1389-
1387+
print_list("set_applemail_ua_value", set_applemail_ua_value);
1388+
1389+
13901390
}
13911391

13921392
#endif

src/setup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ extern bool set_use_sender_date;
9696
extern bool set_inline_addlink;
9797
extern bool set_applemail_mimehack;
9898
extern char *set_applemail_ua_header;
99-
extern char *set_applemail_ua_value;
10099

101100
extern int set_showhtml;
102101
extern int set_thrdlevels;
@@ -143,6 +142,7 @@ extern struct hmlist *set_filter_out;
143142
extern struct hmlist *set_filter_require;
144143
extern struct hmlist *set_filter_out_full_body;
145144
extern struct hmlist *set_filter_require_full_body;
145+
extern struct hmlist *set_applemail_ua_value;
146146

147147
extern char *set_ihtmlheader;
148148
extern char *set_ihtmlfooter;

0 commit comments

Comments
 (0)