------- =_aaaaaaaaaa0
Content-Type: multipart/related;
- type="multipart/alternative";
- boundary="subpart__1.1"
+ type="text/plain"; boundary="subpart__1.1"
--subpart__1.1
Content-Type: text/plain; charset="iso-8859-1"
------- =_aaaaaaaaaa0
Content-Type: multipart/related;
- type="multipart/alternative";
- boundary="subpart__1.1"
+ type="text/plain"; boundary="subpart__1.1"
--subpart__1.1
Content-Type: text/plain; charset="iso-8859-1"
check "$expected" "$actual"
-# check that text/plain part is added to lone text/html in multipart/related
-prepare_space >"$expected" <<EOF
+# check that text/plain part is not added to text/html in multipart/related
+# when it shouldn't be
+cat >`mhpath new` <<EOF
MIME-Version: 1.0
Date: Tue, 26 Feb 2013 18:07:20 -0600
Subject: multipart/related, not /alternative
Content-Type: multipart/related;
- boundary="----=_Part_90310_101292502.1"
+ type="text/html"; boundary="----=_Part_90310_101292502.1"
------=_Part_90310_101292502.1
-Content-Type: multipart/alternative; boundary="----=_nmh-multipart1"
-
-------=_nmh-multipart1
-Content-Type: text/plain; charset="us-ascii"
-Content-Transfer-Encoding: 7bit
-
-This is the real content.
-
-------=_nmh-multipart1
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit
</body>
</html>
-------=_nmh-multipart1--
-
------=_Part_90310_101292502.1
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
------=_Part_90310_101292502.1--
EOF
-cat >`mhpath new` <<EOF
-MIME-Version: 1.0
-Date: Tue, 26 Feb 2013 18:07:20 -0600
-Subject: multipart/related, not /alternative
-Content-Type: multipart/related;
- boundary="----=_Part_90310_101292502.1"
-
-------=_Part_90310_101292502.1
-Content-Type: text/html; charset="us-ascii"
-Content-Transfer-Encoding: 7bit
-
-<html><head>
- <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
- <title>HTML Content</title>
- </head>
- <body>
- This is the real content.
- </body>
-</html>
-------=_Part_90310_101292502.1
-Content-Type: text/plain; charset="us-ascii"
-Content-Transfer-Encoding: 7bit
-
-Your email client does not support HTML messages
-------=_Part_90310_101292502.1--
-EOF
+cp -p `mhpath last` "$expected"
if [ $can_reformat_texthtml -eq 1 ]; then
#### lynx inserts multiple blank lines, so squeeze them.
static int fix_multipart_cte (CT, int *);
static int set_ce (CT, int);
static int ensure_text_plain (CT *, CT, int *, int);
+static int find_textplain_sibling (CT, int, int *);
+static int insert_new_text_plain_part (CT, int, CT);
static CT build_text_plain_part (CT);
static CT divide_part (CT);
static void copy_ctinfo (CI, CI);
case NRPRCSW:
rmmproc = NULL;
continue;
- case CHGSW:
- chgflag = 1;
- continue;
- case NCHGSW:
- chgflag = 0;
- continue;
+ case CHGSW:
+ chgflag = 1;
+ continue;
+ case NCHGSW:
+ chgflag = 0;
+ continue;
case VERBSW:
verbosw = 1;
continue;
switch ((*ct)->c_type) {
case CT_TEXT: {
- int has_text_plain = 0;
-
/* Nothing to do for text/plain. */
if ((*ct)->c_subtype == TEXT_PLAIN) { return OK; }
if (parent && parent->c_type == CT_MULTIPART &&
parent->c_subtype == MULTI_ALTERNATE) {
- struct multipart *mp = (struct multipart *) parent->c_ctparams;
- struct part *part, *prev;
int new_subpart_number = 1;
-
- /* See if there is a sibling text/plain. */
- for (prev = part = mp->mp_parts; part; part = part->mp_next) {
- ++new_subpart_number;
- if (part->mp_part->c_type == CT_TEXT &&
- part->mp_part->c_subtype == TEXT_PLAIN) {
- if (replacetextplain) {
- struct part *old_part;
- if (part == mp->mp_parts) {
- old_part = mp->mp_parts;
- mp->mp_parts = part->mp_next;
- } else {
- old_part = prev->mp_next;
- prev->mp_next = part->mp_next;
- }
- if (verbosw) {
- report (NULL, parent->c_partno, parent->c_file,
- "remove text/plain part %s",
- old_part->mp_part->c_partno);
- }
- free_content (old_part->mp_part);
- free (old_part);
- } else {
- has_text_plain = 1;
- }
- break;
- }
- prev = part;
- }
+ int has_text_plain =
+ find_textplain_sibling (parent, replacetextplain,
+ &new_subpart_number);
if (! has_text_plain) {
/* Parent is a multipart/alternative. Insert a new
text/plain subpart. */
- struct part *new_part = mh_xmalloc (sizeof *new_part);
-
- if ((new_part->mp_part = build_text_plain_part (*ct))) {
- char buffer[16];
- snprintf (buffer, sizeof buffer, "%d", new_subpart_number);
-
- new_part->mp_next = mp->mp_parts;
- mp->mp_parts = new_part;
- new_part->mp_part->c_partno =
- concat (parent->c_partno ? parent->c_partno : "1", ".",
- buffer, NULL);
-
+ const int inserted =
+ insert_new_text_plain_part (*ct, new_subpart_number,
+ parent);
+ if (inserted) {
++*message_mods;
if (verbosw) {
report (NULL, parent->c_partno, parent->c_file,
"insert text/plain part");
}
} else {
- free_content (new_part->mp_part);
- free (new_part);
status = NOTOK;
}
}
+ } else if (parent && parent->c_type == CT_MULTIPART &&
+ parent->c_subtype == MULTI_RELATED) {
+ char *type_subtype =
+ concat ((*ct)->c_ctinfo.ci_type, "/",
+ (*ct)->c_ctinfo.ci_subtype, NULL);
+ const char *parent_type =
+ get_param (parent->c_ctinfo.ci_first_pm, "type", '?', 1);
+
+ /* Have to do string comparison, especially on the subtype
+ because we don't enumerate all of them in c_subtype
+ values. */
+ if (strcasecmp (type_subtype, parent_type) == 0) {
+ /* The type of this part matches the root type of the
+ parent multipart/related. Look to see if there's
+ text/plain sibling. */
+ int new_subpart_number = 1;
+ int has_text_plain =
+ find_textplain_sibling (parent, replacetextplain,
+ &new_subpart_number);
+
+ if (! has_text_plain) {
+ /* Parent is a multipart/alternative. Insert a new
+ text/plain subpart. */
+ const int inserted =
+ insert_new_text_plain_part (*ct, new_subpart_number,
+ parent);
+ if (inserted) {
+ ++*message_mods;
+ if (verbosw) {
+ report (NULL, parent->c_partno, parent->c_file,
+ "insert text/plain part");
+ }
+ } else {
+ status = NOTOK;
+ }
+ }
+ }
} else {
/* Slip new text/plain part into a new multipart/alternative. */
CT tp_part = build_text_plain_part (*ct);
}
+/* See if there is a sibling text/plain. */
+static int
+find_textplain_sibling (CT parent, int replacetextplain,
+ int *new_subpart_number) {
+ struct multipart *mp = (struct multipart *) parent->c_ctparams;
+ struct part *part, *prev;
+ int has_text_plain = 0;
+
+ for (prev = part = mp->mp_parts; part; part = part->mp_next) {
+ ++*new_subpart_number;
+ if (part->mp_part->c_type == CT_TEXT &&
+ part->mp_part->c_subtype == TEXT_PLAIN) {
+ if (replacetextplain) {
+ struct part *old_part;
+ if (part == mp->mp_parts) {
+ old_part = mp->mp_parts;
+ mp->mp_parts = part->mp_next;
+ } else {
+ old_part = prev->mp_next;
+ prev->mp_next = part->mp_next;
+ }
+ if (verbosw) {
+ report (NULL, parent->c_partno, parent->c_file,
+ "remove text/plain part %s",
+ old_part->mp_part->c_partno);
+ }
+ free_content (old_part->mp_part);
+ free (old_part);
+ } else {
+ has_text_plain = 1;
+ }
+ break;
+ }
+ prev = part;
+ }
+
+ return has_text_plain;
+}
+
+
+static int
+insert_new_text_plain_part (CT ct, int new_subpart_number, CT parent) {
+ struct multipart *mp = (struct multipart *) parent->c_ctparams;
+ struct part *new_part = mh_xmalloc (sizeof *new_part);
+
+ if ((new_part->mp_part = build_text_plain_part (ct))) {
+ char buffer[16];
+ snprintf (buffer, sizeof buffer, "%d", new_subpart_number);
+
+ new_part->mp_next = mp->mp_parts;
+ mp->mp_parts = new_part;
+ new_part->mp_part->c_partno =
+ concat (parent->c_partno ? parent->c_partno : "1", ".",
+ buffer, NULL);
+
+ return 1;
+ } else {
+ free_content (new_part->mp_part);
+ free (new_part);
+
+ return 0;
+ }
+}
+
+
static CT
build_text_plain_part (CT encoded_part) {
CT tp_part = divide_part (encoded_part);
}
add_param(&ct->c_ctinfo.ci_first_pm, &ct->c_ctinfo.ci_last_pm,
- "boundary", boundary, 0);
+ "boundary", boundary, 0);
p = (struct part *) mh_xmalloc (sizeof *p);
p->mp_next = (struct part *) mh_xmalloc (sizeof *p->mp_next);