mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
8524cc5598
1) Fixed the "Unsupported Encoding!" problem. 2) Workaround for the Sprint issue, where the MMSC is adding a single extra byte to the end of each encrypted message. 3) Fixed the "large blob of base64 text" on encrypted MMS problem.
69 lines
1.8 KiB
Java
69 lines
1.8 KiB
Java
package org.thoughtcrime.securesms.mms;
|
|
|
|
import android.util.Log;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import ws.com.google.android.mms.ContentType;
|
|
import ws.com.google.android.mms.pdu.CharacterSets;
|
|
import ws.com.google.android.mms.pdu.PduBody;
|
|
|
|
public class PartParser {
|
|
public static String getMessageText(PduBody body) {
|
|
String bodyText = null;
|
|
|
|
for (int i=0;i<body.getPartsNum();i++) {
|
|
if (ContentType.isTextType(Util.toIsoString(body.getPart(i).getContentType()))) {
|
|
String partText;
|
|
|
|
try {
|
|
String characterSet = CharacterSets.getMimeName(body.getPart(i).getCharset());
|
|
|
|
if (characterSet.equals(CharacterSets.MIMENAME_ANY_CHARSET))
|
|
characterSet = CharacterSets.MIMENAME_ISO_8859_1;
|
|
|
|
partText = new String(body.getPart(i).getData(), characterSet);
|
|
} catch (UnsupportedEncodingException e) {
|
|
Log.w("PartParser", e);
|
|
partText = "Unsupported Encoding!";
|
|
}
|
|
|
|
bodyText = (bodyText == null) ? partText : bodyText + " " + partText;
|
|
}
|
|
}
|
|
|
|
return bodyText;
|
|
}
|
|
|
|
public static PduBody getNonTextParts(PduBody body) {
|
|
PduBody stripped = new PduBody();
|
|
|
|
for (int i=0;i<body.getPartsNum();i++) {
|
|
if (!ContentType.isTextType(Util.toIsoString(body.getPart(i).getContentType()))) {
|
|
stripped.addPart(body.getPart(i));
|
|
}
|
|
}
|
|
|
|
return stripped;
|
|
}
|
|
|
|
public static int getDisplayablePartCount(PduBody body) {
|
|
int partCount = 0;
|
|
|
|
for (int i=0;i<body.getPartsNum();i++) {
|
|
String contentType = Util.toIsoString(body.getPart(i).getContentType());
|
|
|
|
if (ContentType.isImageType(contentType) ||
|
|
ContentType.isAudioType(contentType) ||
|
|
ContentType.isVideoType(contentType))
|
|
{
|
|
partCount++;
|
|
}
|
|
}
|
|
|
|
return partCount;
|
|
}
|
|
}
|