Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 957f110d authored by Hall Liu's avatar Hall Liu Committed by Android (Google) Code Review
Browse files

Merge "Copy isEmailAddress"

parents 0122611b 15bc4d22
Loading
Loading
Loading
Loading
+38 −6
Original line number Diff line number Diff line
@@ -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 :
@@ -379,7 +411,7 @@ public abstract class SmsMessageBase {
        if (parts.length < 2) return;
        mEmailFrom = parts[0];
        mEmailBody = parts[1];
         mIsEmail = Telephony.Mms.isEmailAddress(mEmailFrom);
        mIsEmail = isEmailAddress(mEmailFrom);
    }

    /**