/*
 * Copyright (C) Birb Developers
 *
 * Birb is the legal property of its developers, whose names are too numerous
 * to list here. Please refer to the AUTHORS file distributed with this source
 * distribution
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include "birbemail.h"

#include "birbstr.h"

/******************************************************************************
 * Public API
 *****************************************************************************/
gboolean
birb_email_is_valid(const char *address) {
	if(birb_str_is_empty(address)) {
		return FALSE;
	}

	/* Originally lifted from
	 * http://www.oreillynet.com/pub/a/network/excerpt/spcookbook_chap03/index3.html
	 * ... and slightly modified to be a bit more rfc822 compliant
	 * ... and modified a bit more to make domain checking rfc1035 compliant
	 *     with the exception permitted in rfc1101 for domains to start with
	 *     digit but not completely checking to avoid conflicts with IP
	 *     addresses
	 */
	return g_regex_match_simple("^[^@]+@[^@:]+(:\\d+)?$",
	                            address,
	                            G_REGEX_DEFAULT,
	                            G_REGEX_MATCH_DEFAULT);
}

