Copy isEmailAddress
Copy the util method from Telephony.Mms so we're not using the hidden API. Bug: 146834818 Test: atest GsmSmsTest#testIsEmailAddress Change-Id: I003bf504d25b65ce4fc544d918007034471d7040
This commit is contained in:
@@ -18,19 +18,26 @@ package com.android.internal.telephony;
|
||||
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
import android.os.Build;
|
||||
import android.provider.Telephony;
|
||||
import android.telephony.SmsMessage;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Patterns;
|
||||
|
||||
import com.android.internal.telephony.GsmAlphabet.TextEncodingDetails;
|
||||
|
||||
import java.text.BreakIterator;
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Base class declaring the specific methods and members for SmsMessage.
|
||||
* {@hide}
|
||||
*/
|
||||
public abstract class SmsMessageBase {
|
||||
// Copied from Telephony.Mms.NAME_ADDR_EMAIL_PATTERN
|
||||
public static final Pattern NAME_ADDR_EMAIL_PATTERN =
|
||||
Pattern.compile("\\s*(\"[^\"]*\"|[^<>\"]+)\\s*<([^<>]+)>\\s*");
|
||||
|
||||
/** {@hide} The address of the SMSC. May be null */
|
||||
@UnsupportedAppUsage
|
||||
protected String mScAddress;
|
||||
@@ -355,6 +362,31 @@ public abstract class SmsMessageBase {
|
||||
}
|
||||
}
|
||||
|
||||
private static String extractAddrSpec(String messageHeader) {
|
||||
Matcher match = NAME_ADDR_EMAIL_PATTERN.matcher(messageHeader);
|
||||
|
||||
if (match.matches()) {
|
||||
return match.group(2);
|
||||
}
|
||||
return messageHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the message header string indicates that the message is from a email address.
|
||||
*
|
||||
* @param messageHeader message header
|
||||
* @return {@code true} if it's a message from an email address, {@code false} otherwise.
|
||||
*/
|
||||
public static boolean isEmailAddress(String messageHeader) {
|
||||
if (TextUtils.isEmpty(messageHeader)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String s = extractAddrSpec(messageHeader);
|
||||
Matcher match = Patterns.EMAIL_ADDRESS.matcher(s);
|
||||
return match.matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to parse this message as an email gateway message
|
||||
* There are two ways specified in TS 23.040 Section 3.8 :
|
||||
@@ -375,11 +407,11 @@ public abstract class SmsMessageBase {
|
||||
* -or-
|
||||
* 2. [x@y][ ]/[body]
|
||||
*/
|
||||
String[] parts = mMessageBody.split("( /)|( )", 2);
|
||||
if (parts.length < 2) return;
|
||||
mEmailFrom = parts[0];
|
||||
mEmailBody = parts[1];
|
||||
mIsEmail = Telephony.Mms.isEmailAddress(mEmailFrom);
|
||||
String[] parts = mMessageBody.split("( /)|( )", 2);
|
||||
if (parts.length < 2) return;
|
||||
mEmailFrom = parts[0];
|
||||
mEmailBody = parts[1];
|
||||
mIsEmail = isEmailAddress(mEmailFrom);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user