FileDocCategorySizeDatePackage
MailTo.javaAPI DocAndroid 5.1 API5455Thu Mar 12 22:22:10 GMT 2015android.net

MailTo

public class MailTo extends Object
MailTo URL parser This class parses a mailto scheme URL and then can be queried for the parsed parameters. This implements RFC 2368.

Fields Summary
public static final String
MAILTO_SCHEME
private HashMap
mHeaders
private static final String
TO
private static final String
BODY
private static final String
CC
private static final String
SUBJECT
Constructors Summary
private MailTo()
Private constructor. The only way to build a Mailto object is through the parse() method.

        mHeaders = new HashMap<String, String>();
    
Methods Summary
public java.lang.StringgetBody()
Retrieve the body line from the parsed mailto URL. If no body line was specified, then null is return

return
body or null

        return mHeaders.get(BODY);
    
public java.lang.StringgetCc()
Retrieve the CC address line from the parsed mailto URL. This could be several email address that are comma-space delimited. If no CC line was specified, then null is return

return
comma delimited email addresses or null

        return mHeaders.get(CC);
    
public java.util.MapgetHeaders()
Retrieve all the parsed email headers from the mailto URL

return
map containing all parsed values

        return mHeaders;
    
public java.lang.StringgetSubject()
Retrieve the subject line from the parsed mailto URL. If no subject line was specified, then null is return

return
subject or null

        return mHeaders.get(SUBJECT);
    
public java.lang.StringgetTo()
Retrieve the To address line from the parsed mailto URL. This could be several email address that are comma-space delimited. If no To line was specified, then null is return

return
comma delimited email addresses or null

        return mHeaders.get(TO);
    
public static booleanisMailTo(java.lang.String url)
Test to see if the given string is a mailto URL

param
url string to be tested
return
true if the string is a mailto URL


    
                                   
         
        if (url != null && url.startsWith(MAILTO_SCHEME)) {
            return true;
        }
        return false;
    
public static android.net.MailToparse(java.lang.String url)
Parse and decode a mailto scheme string. This parser implements RFC 2368. The returned object can be queried for the parsed parameters.

param
url String containing a mailto URL
return
MailTo object
exception
ParseException if the scheme is not a mailto URL

        if (url == null) {
            throw new NullPointerException();
        }
        if (!isMailTo(url)) {
             throw new ParseException("Not a mailto scheme");
        }
        // Strip the scheme as the Uri parser can't cope with it.
        String noScheme = url.substring(MAILTO_SCHEME.length());
        Uri email = Uri.parse(noScheme);
        MailTo m = new MailTo();
        
        // Parse out the query parameters
        String query = email.getQuery();
        if (query != null ) {
            String[] queries = query.split("&");
            for (String q : queries) {
                String[] nameval = q.split("=");
                if (nameval.length == 0) {
                    continue;
                }
                // insert the headers with the name in lowercase so that
                // we can easily find common headers
                m.mHeaders.put(Uri.decode(nameval[0]).toLowerCase(Locale.ROOT),
                        nameval.length > 1 ? Uri.decode(nameval[1]) : null);
            }
        }
        
        // Address can be specified in both the headers and just after the
        // mailto line. Join the two together.
        String address = email.getPath();
        if (address != null) {
            String addr = m.getTo();
            if (addr != null) {
                address += ", " + addr;
            }
            m.mHeaders.put(TO, address);
        }
        
        return m;
    
public java.lang.StringtoString()

        StringBuilder sb = new StringBuilder(MAILTO_SCHEME);
        sb.append('?");
        for (Map.Entry<String,String> header : mHeaders.entrySet()) {
            sb.append(Uri.encode(header.getKey()));
            sb.append('=");
            sb.append(Uri.encode(header.getValue()));
            sb.append('&");
        }
        return sb.toString();