Skip to content

Commit 334dc0b

Browse files
committed
Parse "multipart/vnd.wap.multipart.alternative" which is a part of multipart body (nested multipart).
And take the first part of parsed as a parent part data. Change-Id: I2752654f41d642524061802772e2a7eaa10a4e2d
1 parent 85ff3fe commit 334dc0b

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

core/java/com/google/android/mms/ContentType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class ContentType {
2626
public static final String MMS_GENERIC = "application/vnd.wap.mms-generic";
2727
public static final String MULTIPART_MIXED = "application/vnd.wap.multipart.mixed";
2828
public static final String MULTIPART_RELATED = "application/vnd.wap.multipart.related";
29+
public static final String MULTIPART_ALTERNATIVE = "application/vnd.wap.multipart.alternative";
2930

3031
public static final String TEXT_PLAIN = "text/plain";
3132
public static final String TEXT_HTML = "text/html";

core/java/com/google/android/mms/pdu/PduParser.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -778,26 +778,34 @@ protected static PduBody parseParts(ByteArrayInputStream pduDataStream) {
778778
/* get part's data */
779779
if (dataLength > 0) {
780780
byte[] partData = new byte[dataLength];
781+
String partContentType = new String(part.getContentType());
781782
pduDataStream.read(partData, 0, dataLength);
782-
// Check Content-Transfer-Encoding.
783-
byte[] partDataEncoding = part.getContentTransferEncoding();
784-
if (null != partDataEncoding) {
785-
String encoding = new String(partDataEncoding);
786-
if (encoding.equalsIgnoreCase(PduPart.P_BASE64)) {
787-
// Decode "base64" into "binary".
788-
partData = Base64.decodeBase64(partData);
789-
} else if (encoding.equalsIgnoreCase(PduPart.P_QUOTED_PRINTABLE)) {
790-
// Decode "quoted-printable" into "binary".
791-
partData = QuotedPrintable.decodeQuotedPrintable(partData);
792-
} else {
793-
// "binary" is the default encoding.
783+
if (partContentType.equalsIgnoreCase(ContentType.MULTIPART_ALTERNATIVE)) {
784+
// parse "multipart/vnd.wap.multipart.alternative".
785+
PduBody childBody = parseParts(new ByteArrayInputStream(partData));
786+
// take the first part of children.
787+
part = childBody.getPart(0);
788+
} else {
789+
// Check Content-Transfer-Encoding.
790+
byte[] partDataEncoding = part.getContentTransferEncoding();
791+
if (null != partDataEncoding) {
792+
String encoding = new String(partDataEncoding);
793+
if (encoding.equalsIgnoreCase(PduPart.P_BASE64)) {
794+
// Decode "base64" into "binary".
795+
partData = Base64.decodeBase64(partData);
796+
} else if (encoding.equalsIgnoreCase(PduPart.P_QUOTED_PRINTABLE)) {
797+
// Decode "quoted-printable" into "binary".
798+
partData = QuotedPrintable.decodeQuotedPrintable(partData);
799+
} else {
800+
// "binary" is the default encoding.
801+
}
794802
}
803+
if (null == partData) {
804+
log("Decode part data error!");
805+
return null;
806+
}
807+
part.setData(partData);
795808
}
796-
if (null == partData) {
797-
log("Decode part data error!");
798-
return null;
799-
}
800-
part.setData(partData);
801809
}
802810

803811
/* add this part to body */

0 commit comments

Comments
 (0)