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
|
|
|
|
|
|
|
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;
|
2014-01-14 08:26:43 +00:00
|
|
|
private final String groupId;
|
2013-07-19 00:42:45 +00:00
|
|
|
|
|
|
|
public IncomingMediaMessage(RetrieveConf retreived) {
|
|
|
|
this.headers = retreived.getPduHeaders();
|
|
|
|
this.body = retreived.getBody();
|
2014-01-14 08:26:43 +00:00
|
|
|
this.groupId = null;
|
2013-07-19 00:42:45 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 01:19:05 +00:00
|
|
|
public IncomingMediaMessage(MasterSecret masterSecret, String localNumber,
|
|
|
|
IncomingPushMessage message,
|
2014-01-14 08:26:43 +00:00
|
|
|
PushMessageContent messageContent,
|
|
|
|
String groupId)
|
2013-07-19 00:42:45 +00:00
|
|
|
{
|
|
|
|
this.headers = new PduHeaders();
|
|
|
|
this.body = new PduBody();
|
2014-01-14 08:26:43 +00:00
|
|
|
this.groupId = groupId;
|
2013-07-19 00:42:45 +00:00
|
|
|
|
|
|
|
this.headers.setEncodedStringValue(new EncodedStringValue(message.getSource()), PduHeaders.FROM);
|
|
|
|
this.headers.appendEncodedStringValue(new EncodedStringValue(localNumber), PduHeaders.TO);
|
|
|
|
this.headers.setLongInteger(message.getTimestampMillis() / 1000, PduHeaders.DATE);
|
|
|
|
|
2014-01-14 08:26:43 +00:00
|
|
|
if (!org.whispersystems.textsecure.util.Util.isEmpty(messageContent.getBody())) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-01-14 08:26:43 +00:00
|
|
|
public String getGroupId() {
|
|
|
|
return groupId;
|
|
|
|
}
|
|
|
|
|
2013-07-19 00:42:45 +00:00
|
|
|
public boolean isGroupMessage() {
|
2014-01-14 08:26:43 +00:00
|
|
|
return groupId != null ||
|
|
|
|
!Util.isEmpty(headers.getEncodedStringValues(PduHeaders.CC)) ||
|
|
|
|
(headers.getEncodedStringValues(PduHeaders.TO) != null &&
|
|
|
|
headers.getEncodedStringValues(PduHeaders.TO).length > 1);
|
2013-07-19 00:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|