2 * Copyright 2007 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.result;
19 import com.google.zxing.Result;
21 import java.util.Hashtable;
24 * Represents a result that encodes an e-mail address, either as a plain address
25 * like "joe@example.org" or a mailto: URL like "mailto:joe@example.org".
27 * @author srowen@google.com (Sean Owen)
29 final class EmailAddressResultParser extends ResultParser {
31 public static EmailAddressParsedResult parse(Result result) {
32 String rawText = result.getText();
33 if (rawText == null) {
37 if (rawText.startsWith("mailto:")) {
38 // If it starts with mailto:, assume it is definitely trying to be an email address
39 emailAddress = rawText.substring(7);
40 int queryStart = emailAddress.indexOf('?');
41 if (queryStart >= 0) {
42 emailAddress = emailAddress.substring(0, queryStart);
44 Hashtable nameValues = parseNameValuePairs(rawText);
45 String subject = null;
47 if (nameValues != null) {
48 if (emailAddress.length() == 0) {
49 emailAddress = (String) nameValues.get("to");
51 subject = (String) nameValues.get("subject");
52 body = (String) nameValues.get("body");
54 return new EmailAddressParsedResult(emailAddress, subject, body, rawText);
56 if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText)) {
59 emailAddress = rawText;
60 return new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress);