⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailaddress.java

📁 基于UDP的可靠邮件系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @return the hashcode.	 */	public int hashCode() {		return toString().toLowerCase(Locale.US).hashCode();	}	private String parseQuotedLocalPart(String address) throws Exception {		StringBuffer resultSB = new StringBuffer();		resultSB.append('\"');		pos++;		// <quoted-string> ::= """ <qtext> """		// <qtext> ::= "\" <x> | "\" <x> <qtext> | <q> | <q> <qtext>		while (true) {			if (address.charAt(pos) == '\"') {				resultSB.append('\"');				// end of quoted string... move forward				pos++;				break;			}			if (address.charAt(pos) == '\\') {				resultSB.append('\\');				pos++;				// <x> ::= any one of the 128 ASCII characters (no exceptions)				char x = address.charAt(pos);				if (x < 0 || x > 127) {					throw new Exception(							"Invalid \\ syntaxed character at position "									+ (pos + 1));				}				resultSB.append(x);				pos++;			} else {				// <q> ::= any one of the 128 ASCII characters except <CR>,				// <LF>, quote ("), or backslash (\)				char q = address.charAt(pos);				if (q <= 0 || q == '\n' || q == '\r' || q == '\"' || q == '\\') {					throw new Exception(							"Unquoted local-part (user account) must be one of the 128 ASCI characters exception <CR>, <LF>, quote (\"), or backslash (\\) at position "									+ (pos + 1));				}				resultSB.append(q);				pos++;			}		}		return resultSB.toString();	}	private String parseUnquotedLocalPart(String address) throws Exception {		StringBuffer resultSB = new StringBuffer();		// <dot-string> ::= <string> | <string> "." <dot-string>		boolean lastCharDot = false;		while (true) {			// <string> ::= <char> | <char> <string>			// <char> ::= <c> | "\" <x>			if (address.charAt(pos) == '\\') {				resultSB.append('\\');				pos++;				// <x> ::= any one of the 128 ASCII characters (no exceptions)				char x = address.charAt(pos);				if (x < 0 || x > 127) {					throw new Exception(							"Invalid \\ syntaxed character at position "									+ (pos + 1));				}				resultSB.append(x);				pos++;				lastCharDot = false;			} else if (address.charAt(pos) == '.') {				resultSB.append('.');				pos++;				lastCharDot = true;			} else if (address.charAt(pos) == '@') {				// End of local-part				break;			} else {				// <c> ::= any one of the 128 ASCII characters, but not any				// <special> or <SP>				// <special> ::= "<" | ">" | "(" | ")" | "[" | "]" | "\" | "."				// | "," | ";" | ":" | "@" """ | the control				// characters (ASCII codes 0 through 31 inclusive and				// 127)				// <SP> ::= the space character (ASCII code 32)				char c = address.charAt(pos);				if (c <= 31 || c >= 127 || c == ' ') {					throw new Exception(							"Invalid character in local-part (user account) at position "									+ (pos + 1));				}				for (int i = 0; i < SPECIAL.length; i++) {					if (c == SPECIAL[i]) {						throw new Exception(								"Invalid character in local-part (user account) at position "										+ (pos + 1));					}				}				resultSB.append(c);				pos++;				lastCharDot = false;			}		}		if (lastCharDot) {			throw new Exception(					"local-part (user account) ended with a \".\", which is invalid.");		}		return resultSB.toString();	}	private String parseNumber(String address) throws Exception {		// <number> ::= <d> | <d> <number>		StringBuffer resultSB = new StringBuffer();		// We keep the position from the class level pos field		while (true) {			if (pos >= address.length()) {				break;			}			// <d> ::= any one of the ten digits 0 through 9			char d = address.charAt(pos);			if (d == '.') {				break;			}			if (d < '0' || d > '9') {				throw new Exception(						"In domain, did not find a number in # address at position "								+ (pos + 1));			}			resultSB.append(d);			pos++;		}		return resultSB.toString();	}	private String parseDotNum(String address) throws Exception {		// throw away all irrelevant '\' they're not necessary for escaping of		// '.' or digits, and are illegal as part of the domain-literal		while (address.indexOf("\\") > -1) {			address = address.substring(0, address.indexOf("\\"))					+ address.substring(address.indexOf("\\") + 1);		}		StringBuffer resultSB = new StringBuffer();		// we were passed the string with pos pointing the the [ char.		// take the first char ([), put it in the result buffer and increment		// pos		resultSB.append(address.charAt(pos));		pos++;		// <dotnum> ::= <snum> "." <snum> "." <snum> "." <snum>		for (int octet = 0; octet < 4; octet++) {			// <snum> ::= one, two, or three digits representing a decimal			// integer value in the range 0 through 255			// <d> ::= any one of the ten digits 0 through 9			StringBuffer snumSB = new StringBuffer();			for (int digits = 0; digits < 3; digits++) {				char d = address.charAt(pos);				if (d == '.') {					break;				}				if (d == ']') {					break;				}				if (d < '0' || d > '9') {					throw new Exception("Invalid number at position "							+ (pos + 1));				}				snumSB.append(d);				pos++;			}			if (snumSB.toString().length() == 0) {				throw new Exception("Number not found at position " + (pos + 1));			}			try {				int snum = Integer.parseInt(snumSB.toString());				if (snum > 255) {					throw new Exception("Invalid number at position "							+ (pos + 1));				}			} catch (NumberFormatException nfe) {				throw new Exception("Invalid number at position " + (pos + 1));			}			resultSB.append(snumSB.toString());			if (address.charAt(pos) == ']') {				if (octet < 3) {					throw new Exception("End of number reached too quickly at "							+ (pos + 1));				} else {					break;				}			}			if (address.charAt(pos) == '.') {				resultSB.append('.');				pos++;			}		}		if (address.charAt(pos) != ']') {			throw new Exception(					"Did not find closing bracket \"]\" in domain at position "							+ (pos + 1));		}		resultSB.append(']');		pos++;		return resultSB.toString();	}	private String parseDomainName(String address) throws Exception {		StringBuffer resultSB = new StringBuffer();		// <name> ::= <a> <ldh-str> <let-dig>		// <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>		// <let-dig> ::= <a> | <d>		// <let-dig-hyp> ::= <a> | <d> | "-"		// <a> ::= any one of the 52 alphabetic characters A through Z		// in upper case and a through z in lower case		// <d> ::= any one of the ten digits 0 through 9		// basically, this is a series of letters, digits, and hyphens,		// but it can't start with a digit or hypthen		// and can't end with a hyphen		// in practice though, we should relax this as domain names can start		// with digits as well as letters. So only check that doesn't start		// or end with hyphen.		while (true) {			if (pos >= address.length()) {				break;			}			char ch = address.charAt(pos);			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z')					|| (ch >= 'A' && ch <= 'Z') || (ch == '-')) {				resultSB.append(ch);				pos++;				continue;			}			if (ch == '.') {				break;			}			throw new Exception("Invalid character at " + pos);		}		String result = resultSB.toString();		if (result.startsWith("-") || result.endsWith("-")) {			throw new Exception(					"Domain name cannot begin or end with a hyphen \"-\" at position "							+ (pos + 1));		}		return result;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -