All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.bloodshura.sparkium.mail.component.Email Maven / Gradle / Ivy

Go to download

An API which aims to facilitate the usage of javax.mail, also including other mailing services.

The newest version!
package com.github.bloodshura.sparkium.mail.component;

import com.github.bloodshura.ignitium.object.Base;
import com.github.bloodshura.sparkium.mail.MailException;

import javax.annotation.Nonnull;

public class Email extends Base {
	private final String email;
	private final String prefix;
	private final String suffix;

	public Email(@Nonnull CharSequence mail) throws MailException {
		this.email = mail.toString();

		if (!email.contains("@")) {
			throw new MailException("Input e-mail does not contains '@'");
		}

		String[] split = email.split("@");

		if (split.length > 2) {
			throw new MailException("Input e-mail contains multiple '@'");
		}

		if (split.length < 2) {
			throw new MailException("Input e-mail has '@', but not a suffix.");
		}

		int dotIndex = split[1].indexOf('.');

		if (dotIndex == -1) {
			throw new MailException("Input e-mail suffix does not contains '.'");
		}

		if (dotIndex == split[1].length() - 1) {
			throw new MailException("Input e-mail suffix must have domain type after '.'");
		}

		this.prefix = split[0];
		this.suffix = split[1];
	}

	@Nonnull
	public String get() {
		return email;
	}

	@Nonnull
	public String getPrefix() {
		return prefix;
	}

	@Nonnull
	public String getSuffix() {
		return suffix;
	}

	@Nonnull
	@Override
	public String toString() {
		return get();
	}

	@Nonnull
	@Override
	protected Object[] stringValues() {
		return new Object[] { get() };
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy