Gets the email address.
Email email = new Email();
int begin = rest.indexOf("(");
try {
if (begin != -1) {
// e=mjh@isi.edu (Mark Handley)
String emailTemp = rest.substring(0, begin);
int i = emailTemp.indexOf("@");
if (i != -1) {
email.setUserName(emailTemp.substring(0, i));
email.setHostName(emailTemp.substring(i+1));
} else {
// Pb: the email is not well formatted
}
} else {
// The alternative RFC822 name quoting convention is
// also allowed for
// email addresses. ex: e=Mark Handley <mjh@isi.edu>
int ind = rest.indexOf("<");
int end = rest.indexOf(">");
if (ind != -1) {
String emailTemp = rest.substring(ind+1, end);
int i = emailTemp.indexOf("@");
if (i != -1) {
email.setUserName(emailTemp.substring(0, i));
email.setHostName(emailTemp.substring(i+1));
} else {
// Pb: the email is not well formatted
}
} else {
int i = rest.indexOf("@");
int j = rest.indexOf("\n");
if (i != -1) {
email.setUserName(rest.substring(0, i));
email.setHostName(rest.substring(i+1, j));
} else {
// Pb: the email is not well formatted
}
}
}
return email;
} catch (IndexOutOfBoundsException iobe) {
return new Email();
}