|
13 | 13 | import java.util.HashMap; |
14 | 14 | import java.util.Map; |
15 | 15 | import java.util.regex.Pattern; |
16 | | -import org.apache.commons.validator.routines.EmailValidator; |
17 | 16 |
|
18 | 17 | /** |
19 | 18 | * The email information for the transaction. |
@@ -340,7 +339,7 @@ public Builder(boolean enableValidation) { |
340 | 339 | * @throws IllegalArgumentException when address is not a valid email address. |
341 | 340 | */ |
342 | 341 | public Email.Builder address(String address) { |
343 | | - if (enableValidation && !EmailValidator.getInstance().isValid(address)) { |
| 342 | + if (enableValidation && !isValidEmail(address)) { |
344 | 343 | throw new IllegalArgumentException( |
345 | 344 | "The email address " + address + " is not valid."); |
346 | 345 | } |
@@ -460,6 +459,34 @@ private String cleanAddress(String address) { |
460 | 459 | return localPart + "@" + domain; |
461 | 460 | } |
462 | 461 |
|
| 462 | + private static boolean isValidEmail(String email) { |
| 463 | + if (email == null || email.isEmpty()) { |
| 464 | + return false; |
| 465 | + } |
| 466 | + |
| 467 | + // RFC 5321 the forward path limits the mailbox to 254 characters |
| 468 | + // even though a domain can be 255 and the local part 64 |
| 469 | + if (email.length() > 254) { |
| 470 | + return false; |
| 471 | + } |
| 472 | + |
| 473 | + int atIndex = email.lastIndexOf('@'); |
| 474 | + if (atIndex <= 0) { |
| 475 | + return false; |
| 476 | + } |
| 477 | + |
| 478 | + String localPart = email.substring(0, atIndex); |
| 479 | + String domainPart = email.substring(atIndex + 1); |
| 480 | + |
| 481 | + // The local-part has a maximum length of 64 characters. |
| 482 | + if (localPart.length() > 64) { |
| 483 | + return false; |
| 484 | + } |
| 485 | + |
| 486 | + return isValidDomain(domainPart); |
| 487 | + } |
| 488 | + |
| 489 | + |
463 | 490 | private String cleanDomain(String domain) { |
464 | 491 | if (domain == null) { |
465 | 492 | return null; |
|
0 commit comments