2 * Copyright 2007 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using Result = com.google.zxing.Result;
\r
18 namespace com.google.zxing.client.result
\r
21 /// <summary> Implements the "MATMSG" email message entry format.
\r
23 /// Supported keys: TO, SUB, BODY
\r
26 /// <author> Sean Owen
\r
28 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
30 sealed class EmailDoCoMoResultParser:AbstractDoCoMoResultParser
\r
33 //UPGRADE_NOTE: Final was removed from the declaration of 'ATEXT_SYMBOLS'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
34 private static readonly char[] ATEXT_SYMBOLS = new char[]{'@', '.', '!', '#', '$', '%', '&', '\'', '*', '+', '-', '/', '=', '?', '^', '_', '`', '{', '|', '}', '~'};
\r
36 public static EmailAddressParsedResult parse(Result result)
\r
38 System.String rawText = result.Text;
\r
39 if (rawText == null || !rawText.StartsWith("MATMSG:"))
\r
43 System.String[] rawTo = matchDoCoMoPrefixedField("TO:", rawText, true);
\r
48 System.String to = rawTo[0];
\r
49 if (!isBasicallyValidEmailAddress(to))
\r
53 System.String subject = matchSingleDoCoMoPrefixedField("SUB:", rawText, false);
\r
54 System.String body = matchSingleDoCoMoPrefixedField("BODY:", rawText, false);
\r
55 return new EmailAddressParsedResult(to, subject, body, "mailto:" + to);
\r
58 /// <summary> This implements only the most basic checking for an email address's validity -- that it contains
\r
59 /// an '@' contains no characters disallowed by RFC 2822. This is an overly lenient definition of
\r
60 /// validity. We want to generally be lenient here since this class is only intended to encapsulate what's
\r
61 /// in a barcode, not "judge" it.
\r
63 internal static bool isBasicallyValidEmailAddress(System.String email)
\r
69 bool atFound = false;
\r
70 for (int i = 0; i < email.Length; i++)
\r
73 if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9') && !isAtextSymbol(c))
\r
89 private static bool isAtextSymbol(char c)
\r
91 for (int i = 0; i < ATEXT_SYMBOLS.Length; i++)
\r
93 if (c == ATEXT_SYMBOLS[i])
\r