2013-07-19 00:42:45 +00:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2013-09-09 01:19:05 +00:00
|
|
|
import org.whispersystems.textsecure.crypto.MasterCipher;
|
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2013-07-19 00:42:45 +00:00
|
|
|
import org.whispersystems.textsecure.push.IncomingPushMessage;
|
2013-09-09 01:19:05 +00:00
|
|
|
import org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent;
|
|
|
|
import org.whispersystems.textsecure.util.Base64;
|
2013-07-19 00:42:45 +00:00
|
|
|
|
2013-09-09 01:19:05 +00:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2013-07-19 00:42:45 +00:00
|
|
|
|
|
|
|
import ws.com.google.android.mms.pdu.CharacterSets;
|
|
|
|
import ws.com.google.android.mms.pdu.EncodedStringValue;
|
|
|
|
import ws.com.google.android.mms.pdu.PduBody;
|
|
|
|
import ws.com.google.android.mms.pdu.PduHeaders;
|
|
|
|
import ws.com.google.android.mms.pdu.PduPart;
|
|
|
|
import ws.com.google.android.mms.pdu.RetrieveConf;
|
|
|
|
|
|
|
|
public class IncomingMediaMessage {
|
|
|
|
|
|
|
|
private final PduHeaders headers;
|
|
|
|
private final PduBody body;
|
|
|
|
|
|
|
|
public IncomingMediaMessage(RetrieveConf retreived) {
|
|
|
|
this.headers = retreived.getPduHeaders();
|
|
|
|
this.body = retreived.getBody();
|
|
|
|
}
|
|
|
|
|
2013-09-09 01:19:05 +00:00
|
|
|
public IncomingMediaMessage(MasterSecret masterSecret, String localNumber,
|
|
|
|
IncomingPushMessage message,
|
|
|
|
PushMessageContent messageContent)
|
2013-07-19 00:42:45 +00:00
|
|
|
{
|
|
|
|
this.headers = new PduHeaders();
|
|
|
|
this.body = new PduBody();
|
|
|
|
|
|
|
|
this.headers.setEncodedStringValue(new EncodedStringValue(message.getSource()), PduHeaders.FROM);
|
|
|
|
this.headers.appendEncodedStringValue(new EncodedStringValue(localNumber), PduHeaders.TO);
|
|
|
|
|
|
|
|
for (String destination : message.getDestinations()) {
|
2013-09-09 01:19:05 +00:00
|
|
|
this.headers.appendEncodedStringValue(new EncodedStringValue(destination), PduHeaders.CC);
|
2013-07-19 00:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.headers.setLongInteger(message.getTimestampMillis() / 1000, PduHeaders.DATE);
|
|
|
|
|
2013-09-09 01:19:05 +00:00
|
|
|
if (messageContent.getBody() != null && messageContent.getBody().length() > 0) {
|
2013-07-19 00:42:45 +00:00
|
|
|
PduPart text = new PduPart();
|
2013-09-09 01:19:05 +00:00
|
|
|
text.setData(Util.toIsoBytes(messageContent.getBody()));
|
|
|
|
text.setContentType(Util.toIsoBytes("text/plain"));
|
2013-07-19 00:42:45 +00:00
|
|
|
body.addPart(text);
|
|
|
|
}
|
|
|
|
|
2013-09-09 01:19:05 +00:00
|
|
|
if (messageContent.getAttachmentsCount() > 0) {
|
|
|
|
for (PushMessageContent.AttachmentPointer attachment : messageContent.getAttachmentsList()) {
|
|
|
|
PduPart media = new PduPart();
|
|
|
|
byte[] encryptedKey = new MasterCipher(masterSecret).encryptBytes(attachment.getKey().toByteArray());
|
2013-07-19 00:42:45 +00:00
|
|
|
|
2013-09-09 01:19:05 +00:00
|
|
|
media.setContentType(Util.toIsoBytes(attachment.getContentType()));
|
|
|
|
media.setContentLocation(Util.toIsoBytes(String.valueOf(attachment.getId())));
|
|
|
|
media.setContentDisposition(Util.toIsoBytes(Base64.encodeBytes(encryptedKey)));
|
2013-10-20 01:16:11 +00:00
|
|
|
|
|
|
|
if (message.getRelay() != null) {
|
|
|
|
media.setName(Util.toIsoBytes(message.getRelay()));
|
|
|
|
}
|
|
|
|
|
2013-09-09 01:19:05 +00:00
|
|
|
media.setPendingPush(true);
|
2013-07-19 00:42:45 +00:00
|
|
|
|
|
|
|
body.addPart(media);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public PduHeaders getPduHeaders() {
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PduBody getBody() {
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGroupMessage() {
|
|
|
|
return !Util.isEmpty(headers.getEncodedStringValues(PduHeaders.CC));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|