mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Support SMTP URLs
git-svn-id: https://zxing.googlecode.com/svn/trunk@1609 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
5abef2f3aa
commit
c01ee70804
|
@ -55,6 +55,8 @@ public abstract class ResultParser {
|
|||
return result;
|
||||
} else if ((result = EmailAddressResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = SMTPResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = TelResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = SMSMMSResultParser.parse(theResult)) != null) {
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* <p>Parses an "smtp:" URI result, whose format is not standardized but appears to be like:
|
||||
* <code>smtp(:subject(:body))</code>.</p>
|
||||
*
|
||||
* <p>See http://code.google.com/p/zxing/issues/detail?id=536</p>
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
final class SMTPResultParser {
|
||||
|
||||
private SMTPResultParser() {
|
||||
}
|
||||
|
||||
public static EmailAddressParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null) {
|
||||
return null;
|
||||
}
|
||||
if (!(rawText.startsWith("smtp:") || rawText.startsWith("SMTP:"))) {
|
||||
return null;
|
||||
}
|
||||
String emailAddress = rawText.substring(5);
|
||||
String subject = null;
|
||||
String body = null;
|
||||
int colon = emailAddress.indexOf(':');
|
||||
if (colon >= 0) {
|
||||
subject = emailAddress.substring(colon + 1);
|
||||
emailAddress = emailAddress.substring(0, colon);
|
||||
colon = subject.indexOf(':');
|
||||
if (colon >= 0) {
|
||||
body = subject.substring(colon + 1);
|
||||
subject = subject.substring(0, colon);
|
||||
}
|
||||
}
|
||||
String mailtoURI = "mailto:" + emailAddress;
|
||||
return new EmailAddressParsedResult(emailAddress, subject, body, mailtoURI);
|
||||
}
|
||||
}
|
|
@ -39,6 +39,13 @@ public final class EmailAddressParsedResultTestCase extends TestCase {
|
|||
"Stuff", "This is some text");
|
||||
}
|
||||
|
||||
public void testSMTP() {
|
||||
doTest("smtp:srowen@example.org", "srowen@example.org", null, null);
|
||||
doTest("SMTP:srowen@example.org", "srowen@example.org", null, null);
|
||||
doTest("smtp:srowen@example.org:foo", "srowen@example.org", "foo", null);
|
||||
doTest("smtp:srowen@example.org:foo:bar", "srowen@example.org", "foo", "bar");
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String email, String subject, String body) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
|
|
Loading…
Reference in a new issue