use of ws.com.google.android.mms.pdu.EncodedStringValue in project Signal-Android by WhisperSystems.
the class MmsSendJob method getPduBytes.
private byte[] getPduBytes(SendReq message) throws IOException, UndeliverableMessageException, InsecureFallbackApprovalException {
String number = TelephonyUtil.getManager(context).getLine1Number();
message.setBody(SmilUtil.getSmilBody(message.getBody()));
if (!TextUtils.isEmpty(number)) {
message.setFrom(new EncodedStringValue(number));
}
byte[] pduBytes = new PduComposer(context, message).make();
if (pduBytes == null) {
throw new UndeliverableMessageException("PDU composition failed, null payload");
}
return pduBytes;
}
use of ws.com.google.android.mms.pdu.EncodedStringValue in project Signal-Android by WhisperSystems.
the class MmsSendJob method constructSendPdu.
private SendReq constructSendPdu(MasterSecret masterSecret, OutgoingMediaMessage message) throws UndeliverableMessageException {
SendReq sendReq = new SendReq();
PduBody body = new PduBody();
List<String> numbers = message.getRecipients().toNumberStringList(true);
for (String number : numbers) {
if (message.getDistributionType() == DistributionTypes.CONVERSATION) {
sendReq.addTo(new EncodedStringValue(Util.toIsoBytes(number)));
} else {
sendReq.addBcc(new EncodedStringValue(Util.toIsoBytes(number)));
}
}
sendReq.setDate(message.getSentTimeMillis() / 1000L);
if (!TextUtils.isEmpty(message.getBody())) {
PduPart part = new PduPart();
part.setData(Util.toUtf8Bytes(message.getBody()));
part.setCharset(CharacterSets.UTF_8);
part.setContentType(ContentType.TEXT_PLAIN.getBytes());
part.setContentId((System.currentTimeMillis() + "").getBytes());
part.setName(("Text" + System.currentTimeMillis()).getBytes());
body.addPart(part);
}
List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.MMS_CONSTRAINTS, message.getAttachments());
for (Attachment attachment : scaledAttachments) {
try {
if (attachment.getDataUri() == null)
throw new IOException("Assertion failed, attachment for outgoing MMS has no data!");
PduPart part = new PduPart();
part.setData(Util.readFully(PartAuthority.getAttachmentStream(context, masterSecret, attachment.getDataUri())));
part.setContentType(Util.toIsoBytes(attachment.getContentType()));
part.setContentId((System.currentTimeMillis() + "").getBytes());
part.setName((System.currentTimeMillis() + "").getBytes());
body.addPart(part);
} catch (IOException e) {
Log.w(TAG, e);
}
}
sendReq.setBody(body);
return sendReq;
}
use of ws.com.google.android.mms.pdu.EncodedStringValue in project Signal-Android by WhisperSystems.
the class MmsDownloadJob method storeRetrievedMms.
private void storeRetrievedMms(MasterSecret masterSecret, String contentLocation, long messageId, long threadId, RetrieveConf retrieved, int subscriptionId) throws MmsException, NoSessionException, DuplicateMessageException, InvalidMessageException, LegacyMessageException {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
SingleUseBlobProvider provider = SingleUseBlobProvider.getInstance();
String from = null;
List<String> to = new LinkedList<>();
List<String> cc = new LinkedList<>();
String body = null;
List<Attachment> attachments = new LinkedList<>();
if (retrieved.getFrom() != null) {
from = Util.toIsoString(retrieved.getFrom().getTextString());
}
if (retrieved.getTo() != null) {
for (EncodedStringValue toValue : retrieved.getTo()) {
to.add(Util.toIsoString(toValue.getTextString()));
}
}
if (retrieved.getCc() != null) {
for (EncodedStringValue ccValue : retrieved.getCc()) {
cc.add(Util.toIsoString(ccValue.getTextString()));
}
}
if (retrieved.getBody() != null) {
body = PartParser.getMessageText(retrieved.getBody());
PduBody media = PartParser.getSupportedMediaParts(retrieved.getBody());
for (int i = 0; i < media.getPartsNum(); i++) {
PduPart part = media.getPart(i);
if (part.getData() != null) {
Uri uri = provider.createUri(part.getData());
attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()), AttachmentDatabase.TRANSFER_PROGRESS_DONE, part.getData().length));
}
}
}
IncomingMediaMessage message = new IncomingMediaMessage(from, to, cc, body, retrieved.getDate() * 1000L, attachments, subscriptionId, 0, false);
Optional<InsertResult> insertResult = database.insertMessageInbox(new MasterSecretUnion(masterSecret), message, contentLocation, threadId);
if (insertResult.isPresent()) {
database.delete(messageId);
MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId());
}
}
use of ws.com.google.android.mms.pdu.EncodedStringValue in project Signal-Android by WhisperSystems.
the class PduHeadersBuilder method add.
public void add(String key, String charsetKey, int headersKey) {
String value = cursor.getString(cursor.getColumnIndexOrThrow(key));
if (value != null && value.trim().length() > 0) {
int charsetValue = cursor.getInt(cursor.getColumnIndexOrThrow(charsetKey));
EncodedStringValue encodedValue = new EncodedStringValue(charsetValue, getBytes(value));
headers.setEncodedStringValue(encodedValue, headersKey);
}
}
Aggregations