parse method
Attempts to parse the raw Result's contents as a particular type of information (email, URL, etc.) and return a ParsedResult encapsulating the result of parsing.
@param theResult the raw Result to parse @return ParsedResult encapsulating the parsing result
Implementation
@override
EmailAddressParsedResult? parse(Result result) {
final rawText = ResultParser.getMassagedText(result);
if (rawText.startsWith('mailto:') || rawText.startsWith('MAILTO:')) {
// If it starts with mailto:, assume it is definitely trying to be an email address
String hostEmail = rawText.substring(7);
final queryStart = hostEmail.indexOf('?');
if (queryStart >= 0) {
hostEmail = hostEmail.substring(0, queryStart);
}
try {
hostEmail = urlDecode(hostEmail);
} catch (_) {
// IllegalArgumentException
return null;
}
List<String>? tos;
if (hostEmail.isNotEmpty) {
tos = hostEmail.split(_comma);
}
final nameValues = parseNameValuePairs(rawText);
List<String>? ccs;
List<String>? bccs;
String? subject;
String? body;
if (nameValues != null) {
if (tos == null) {
final tosString = nameValues['to'];
if (tosString != null) {
tos = tosString.split(_comma);
}
}
final ccString = nameValues['cc'];
if (ccString != null) {
ccs = ccString.split(_comma);
}
final bccString = nameValues['bcc'];
if (bccString != null) {
bccs = bccString.split(_comma);
}
subject = nameValues['subject'];
body = nameValues['body'];
}
return EmailAddressParsedResult(tos, ccs, bccs, subject, body);
} else {
if (!isBasicallyValidEmailAddress(rawText)) {
return null;
}
return EmailAddressParsedResult(rawText);
}
}