2 * Copyright 2010 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;
22 * <p>Parses an "smtp:" URI result, whose format is not standardized but appears to be like:
23 * <code>smtp(:subject(:body))</code>.</p>
25 * <p>See http://code.google.com/p/zxing/issues/detail?id=536</p>
29 final class SMTPResultParser {
31 private SMTPResultParser() {
34 public static EmailAddressParsedResult parse(Result result) {
35 String rawText = result.getText();
36 if (rawText == null) {
39 if (!(rawText.startsWith("smtp:") || rawText.startsWith("SMTP:"))) {
42 String emailAddress = rawText.substring(5);
43 String subject = null;
45 int colon = emailAddress.indexOf(':');
47 subject = emailAddress.substring(colon + 1);
48 emailAddress = emailAddress.substring(0, colon);
49 colon = subject.indexOf(':');
51 body = subject.substring(colon + 1);
52 subject = subject.substring(0, colon);
55 String mailtoURI = "mailto:" + emailAddress;
56 return new EmailAddressParsedResult(emailAddress, subject, body, mailtoURI);