|  |  | @ -4,6 +4,7 @@ import android.app.PendingIntent; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.content.Context; |  |  |  | import android.content.Context; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.content.Intent; |  |  |  | import android.content.Intent; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.net.Uri; |  |  |  | import android.net.Uri; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import android.telephony.PhoneNumberUtils; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.telephony.SmsManager; |  |  |  | import android.telephony.SmsManager; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.util.Log; |  |  |  | import android.util.Log; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -19,7 +20,6 @@ import org.thoughtcrime.securesms.jobs.requirements.ServiceRequirement; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.notifications.MessageNotifier; |  |  |  | import org.thoughtcrime.securesms.notifications.MessageNotifier; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.recipients.Recipients; |  |  |  | import org.thoughtcrime.securesms.recipients.Recipients; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.service.SmsDeliveryListener; |  |  |  | import org.thoughtcrime.securesms.service.SmsDeliveryListener; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.transport.UndeliverableMessageException; |  |  |  | import org.thoughtcrime.securesms.transport.UndeliverableMessageException; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.util.NumberUtil; |  |  |  | import org.thoughtcrime.securesms.util.NumberUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.util.TextSecurePreferences; |  |  |  | import org.thoughtcrime.securesms.util.TextSecurePreferences; | 
			
		
	
	
		
		
			
				
					|  |  | @ -78,27 +78,28 @@ public class SmsSendJob extends SendJob { | 
			
		
	
		
		
			
				
					
					|  |  |  |   private void deliver(SmsMessageRecord message) |  |  |  |   private void deliver(SmsMessageRecord message) | 
			
		
	
		
		
			
				
					
					|  |  |  |       throws UndeliverableMessageException |  |  |  |       throws UndeliverableMessageException | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |   { | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (!NumberUtil.isValidSmsOrEmail(message.getIndividualRecipient().getNumber())) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       throw new UndeliverableMessageException("Not a valid SMS destination! " + message.getIndividualRecipient().getNumber()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (message.isSecure() || message.isKeyExchange() || message.isEndSession()) { |  |  |  |     if (message.isSecure() || message.isKeyExchange() || message.isEndSession()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |       throw new UndeliverableMessageException("Trying to send a secure SMS?"); |  |  |  |       throw new UndeliverableMessageException("Trying to send a secure SMS?"); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     ArrayList<String> messages                = SmsManager.getDefault().divideMessage(message.getBody().getBody()); |  |  |  |     String recipient = message.getIndividualRecipient().getNumber(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     ArrayList<PendingIntent> sentIntents      = constructSentIntents(message.getId(), message.getType(), messages, false); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     ArrayList<PendingIntent> deliveredIntents = constructDeliveredIntents(message.getId(), message.getType(), messages); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     String recipient                          = message.getIndividualRecipient().getNumber(); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     // remove characters for visible number formatting - they break sending sms on some phones (issue #1516)
 |  |  |  |     // See issue #1516 for bug report, and discussion on commits related to #4833 for problems
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // stripSeparator() to rigid? what will people try to send here? - see discussion on #3099
 |  |  |  |     // related to the original fix to #1516. This still may not be a correct fix if networks allow
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     //recipient = PhoneNumberUtils.stripSeparators(recipient);
 |  |  |  |     // SMS/MMS sending to alphanumeric recipients other than email addresses, but should also
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // minimum required to fix the issue - brackets are no dialable chars...
 |  |  |  |     // help to fix issue #3099.
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     if (!NumberUtil.isValidEmail(recipient)) { |  |  |  |     if (!NumberUtil.isValidEmail(recipient)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |       recipient = recipient.replaceAll("[^0-9+]", ""); |  |  |  |       recipient = PhoneNumberUtils.stripSeparators(PhoneNumberUtils.convertKeypadLettersToDigits(recipient)); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (!NumberUtil.isValidSmsOrEmail(recipient)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       throw new UndeliverableMessageException("Not a valid SMS destination! " + recipient); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     ArrayList<String> messages                = SmsManager.getDefault().divideMessage(message.getBody().getBody()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     ArrayList<PendingIntent> sentIntents      = constructSentIntents(message.getId(), message.getType(), messages, false); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     ArrayList<PendingIntent> deliveredIntents = constructDeliveredIntents(message.getId(), message.getType(), messages); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     // NOTE 11/04/14 -- There's apparently a bug where for some unknown recipients
 |  |  |  |     // NOTE 11/04/14 -- There's apparently a bug where for some unknown recipients
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     // and messages, this will throw an NPE.  We have no idea why, so we're just
 |  |  |  |     // and messages, this will throw an NPE.  We have no idea why, so we're just
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     // catching it and marking the message as a failure.  That way at least it doesn't
 |  |  |  |     // catching it and marking the message as a failure.  That way at least it doesn't
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |