X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fresult%2FSMSMMSResultParser.java;h=e309132cae634934f76f0b2abc5f4681e24a8807;hp=88bcfa38e6a4ef5409c9b89c46939fa112720550;hb=4084c9891a340f1c60e9de42b045f9ecb962253e;hpb=ab7205b1675d56027e56deacc5d2fb92a3e9fd4c diff --git a/core/src/com/google/zxing/client/result/SMSMMSResultParser.java b/core/src/com/google/zxing/client/result/SMSMMSResultParser.java index 88bcfa38..e309132c 100644 --- a/core/src/com/google/zxing/client/result/SMSMMSResultParser.java +++ b/core/src/com/google/zxing/client/result/SMSMMSResultParser.java @@ -19,15 +19,20 @@ package com.google.zxing.client.result; import com.google.zxing.Result; import java.util.Hashtable; +import java.util.Vector; /** - *

Parses an "sms:" URI result, which specifies a number to SMS and optional - * "via" number. See - * the IETF draft on this.

+ *

Parses an "sms:" URI result, which specifies a number to SMS. + * See RFC 5724 on this.

* - *

This actually also parses URIs starting with "mms:", "smsto:", "mmsto:", "SMSTO:", and - * "MMSTO:", and treats them all the same way, and effectively converts them to an "sms:" URI - * for purposes of forwarding to the platform.

+ *

This class supports "via" syntax for numbers, which is not part of the spec. + * For example "+12125551212;via=+12124440101" may appear as a number. + * It also supports a "subject" query parameter, which is not mentioned in the spec. + * These are included since they were mentioned in earlier IETF drafts and might be + * used.

+ * + *

This actually also parses URIs starting with "mms:" and treats them all the same way, + * and effectively converts them to an "sms:" URI for purposes of forwarding to the platform.

* * @author Sean Owen */ @@ -41,14 +46,8 @@ final class SMSMMSResultParser extends ResultParser { if (rawText == null) { return null; } - int prefixLength; - if (rawText.startsWith("sms:") || rawText.startsWith("SMS:") || - rawText.startsWith("mms:") || rawText.startsWith("MMS:")) { - prefixLength = 4; - } else if (rawText.startsWith("smsto:") || rawText.startsWith("SMSTO:") || - rawText.startsWith("mmsto:") || rawText.startsWith("MMSTO:")) { - prefixLength = 6; - } else { + if (!(rawText.startsWith("sms:") || rawText.startsWith("SMS:") || + rawText.startsWith("mms:") || rawText.startsWith("MMS:"))) { return null; } @@ -64,40 +63,45 @@ final class SMSMMSResultParser extends ResultParser { } // Drop sms, query portion - int queryStart = rawText.indexOf('?', prefixLength); + int queryStart = rawText.indexOf('?', 4); String smsURIWithoutQuery; // If it's not query syntax, the question mark is part of the subject or message if (queryStart < 0 || !querySyntax) { - smsURIWithoutQuery = rawText.substring(prefixLength); + smsURIWithoutQuery = rawText.substring(4); } else { - smsURIWithoutQuery = rawText.substring(prefixLength, queryStart); + smsURIWithoutQuery = rawText.substring(4, queryStart); } - int numberEnd = smsURIWithoutQuery.indexOf(';'); - String number; - String via; + + int lastComma = -1; + int comma; + Vector numbers = new Vector(1); + Vector vias = new Vector(1); + while ((comma = smsURIWithoutQuery.indexOf(',', lastComma + 1)) > lastComma) { + String numberPart = smsURIWithoutQuery.substring(lastComma + 1, comma); + addNumberVia(numbers, vias, numberPart); + lastComma = comma; + } + addNumberVia(numbers, vias, smsURIWithoutQuery.substring(lastComma + 1)); + + return new SMSParsedResult(toStringArray(numbers), toStringArray(vias), subject, body); + } + + private static void addNumberVia(Vector numbers, Vector vias, String numberPart) { + int numberEnd = numberPart.indexOf(';'); if (numberEnd < 0) { - number = smsURIWithoutQuery; - via = null; + numbers.addElement(numberPart); + vias.addElement(null); } else { - number = smsURIWithoutQuery.substring(0, numberEnd); - String maybeVia = smsURIWithoutQuery.substring(numberEnd + 1); + numbers.addElement(numberPart.substring(0, numberEnd)); + String maybeVia = numberPart.substring(numberEnd + 1); + String via; if (maybeVia.startsWith("via=")) { via = maybeVia.substring(4); } else { via = null; } + vias.addElement(via); } - - // Thanks to dominik.wild for suggesting this enhancement to support - // smsto:number:body URIs - if (body == null) { - int bodyStart = number.indexOf(':'); - if (bodyStart >= 0) { - body = number.substring(bodyStart + 1); - number = number.substring(0, bodyStart); - } - } - return new SMSParsedResult("sms:" + number, number, via, subject, body, null); } } \ No newline at end of file