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 public final class EmailAddressParsedResult extends AbstractDoCoMoParsedResult {
31 private final String emailAddress;
32 private final String subject;
33 private final String body;
34 private final String mailtoURI;
36 private EmailAddressParsedResult(String emailAddress, String subject, String body, String mailtoURI) {
37 super(ParsedReaderResultType.EMAIL_ADDRESS);
38 this.emailAddress = emailAddress;
39 this.subject = subject;
41 this.mailtoURI = mailtoURI;
44 public static EmailAddressParsedResult parse(Result result) {
45 String rawText = result.getText();
46 if (rawText == null) {
50 if (rawText.startsWith("mailto:")) {
51 // If it starts with mailto:, assume it is definitely trying to be an email address
52 emailAddress = rawText.substring(7);
53 int queryStart = emailAddress.indexOf('?');
54 if (queryStart >= 0) {
55 emailAddress = emailAddress.substring(0, queryStart);
57 Hashtable nameValues = parseNameValuePairs(rawText);
58 String subject = null;
60 if (nameValues != null) {
61 if (emailAddress.length() == 0) {
62 emailAddress = (String) nameValues.get("to");
64 subject = (String) nameValues.get("subject");
65 body = (String) nameValues.get("body");
67 return new EmailAddressParsedResult(emailAddress, subject, body, rawText);
69 if (!EmailDoCoMoParsedResult.isBasicallyValidEmailAddress(rawText)) {
72 emailAddress = rawText;
73 return new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress);
77 public String getEmailAddress() {
81 public String getSubject() {
85 public String getBody() {
89 public String getMailtoURI() {
93 public String getDisplayResult() {