+ POST("post://", false),
+
+ FREEMAIL("", true) {
+ @Override
+ public Optional<NextLink> findNext(String line) {
+ int nextFreemailSuffix = line.indexOf(".freemail");
+ if (nextFreemailSuffix < 54) {
+ /* 52 chars for the id, 1 on @, at least 1 for the local part. */
+ return absent();
+ }
+ if (line.charAt(nextFreemailSuffix - 53) != '@') {
+ return absent();
+ }
+ if (!line.substring(nextFreemailSuffix - 52, nextFreemailSuffix).matches("^[a-z2-7]*$")) {
+ return absent();
+ }
+ int startOfLocalPart = nextFreemailSuffix - 54;
+ if (!isAllowedInLocalPart(line.charAt(startOfLocalPart))) {
+ return absent();
+ }
+ while ((startOfLocalPart > 0) && isAllowedInLocalPart(line.charAt(startOfLocalPart - 1))) {
+ startOfLocalPart--;
+ }
+ return of(new NextLink(startOfLocalPart, line.substring(startOfLocalPart, nextFreemailSuffix + 9), line.substring(nextFreemailSuffix + 9), this));
+ }
+
+ private boolean isAllowedInLocalPart(char character) {
+ return ((character >= 'A') && (character <= 'Z'))
+ || ((character >= 'a') && (character <= 'z'))
+ || ((character >= '0') && (character <= '9'))
+ || (character == '.') || (character == '-') || (character == '_');
+ }
+ };