فهرست منبع

Add parameter vrfy to parseAddress

Pascal Peridont 17 سال پیش
والد
کامیت
6bd6e47b29
2فایلهای تغییر یافته به همراه16 افزوده شده و 6 حذف شده
  1. 1 1
      std/mtwin/mail/Browser.hx
  2. 15 5
      std/mtwin/mail/Tools.hx

+ 1 - 1
std/mtwin/mail/Browser.hx

@@ -198,7 +198,7 @@ class Browser extends MetaPart<Browser> {
 
 	public function getAddress( name, ?charset ){
 		var e = getHeader(name,charset);
-		return Tools.parseAddress(e);
+		return Tools.parseAddress(e,false);
 	}
 
 	function mkBody() : {ctype_primary: String,ctype_secondary: String,charset: String,content: String} {

+ 15 - 5
std/mtwin/mail/Tools.hx

@@ -446,7 +446,9 @@ class Tools {
 	static var REG_ATOM = ~/^([^()<>@,;:"\[\]\s[:cntrl:]]+)/i;
 	static var REG_QSTRING = ~/^"((\\"|[^"])*)"/;
 	static var REG_SEPARATOR = ~/,\s*/;
-	public static function parseAddress( str : String ) : Array<Address> {
+	public static function parseAddress( str : String, ?vrfy : Bool ) : Array<Address> {
+		if( vrfy == null )
+			vrfy = true;
 		var a = new Array();
 		var name = null;
 		var address = null;
@@ -464,11 +466,12 @@ class Tools {
 				name += t;
 				s = REG_QSTRING.matchedRight();
 			}else if( REG_ADDRESS.match(s) ){
-				if( address != null ) throw Exception.ParseError(str+", near: "+s.substr(0,15));
+				if( address != null && vrfy ) throw Exception.ParseError(str+", near: "+s.substr(0,15));
 				address = REG_ADDRESS.matched(1);
 				s = REG_ADDRESS.matchedRight();
 			}else if( REG_ROUTE_ADDR.match(s) ){
-				if( address != null ) throw Exception.ParseError(str+", near: "+s.substr(0,15));
+				if( address != null )
+					name = (name!=null)?name+" "+address : address;
 				address = REG_ROUTE_ADDR.matched(1);
 				s = REG_ROUTE_ADDR.matchedRight();
 			}else if( REG_ATOM.match(s) ){
@@ -483,14 +486,21 @@ class Tools {
 					name = null;
 				}
 				s = REG_SEPARATOR.matchedRight();
-			}else{
+			}else if( vrfy ){
 				throw Exception.ParseError(str+", near: "+s.substr(0,15));
+			}else{
+				break;
 			}
 		}
-
 		if( address != null ){
 			a.push({name: if( name != null && name.length > 0 ) name else null, address: address});
 		}
+		if( a.length == 0 ){
+			if( vrfy )
+				throw Exception.ParseError(str+", no address found");
+			else
+				a.push({name: null,address: null});
+		}
 		return a;
 	}