Mstdlib-1.24.0
m_verify.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2017 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24
25#ifndef M_EMAIL_VERIFY_H
26#define M_EMAIL_VERIFY_H
27
28
29/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
30
31#include <mstdlib/base/m_defs.h>
32#include <mstdlib/base/m_types.h>
33
34/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
35
36__BEGIN_DECLS
37
38/*! \addtogroup m_verify Verification
39 * \ingroup m_text
40 *
41 * \brief Validation of strings against various standards (email address, domain name, etc.).
42 *
43 * @{
44 */
45
46typedef enum {
51
52
53/*! Verify that the given single email address is valid.
54 *
55 * An email address is composed of the following parts:
56 * \verbatim display_name<local_part@domain>\endverbatim
57 *
58 * The display name may contain double-quotes. Within double-quotes, the full range of symbols may be used (dot,
59 * comma, semicolon, at, escaped double-quote, etc.). The space and tab characters are allowed in the display name,
60 * even outside of quotes.
61 *
62 * If the display name is not provided, the angle brackets around the rest of the email address are optional.
63 *
64 * This email address validator differs from the RFC standards for email in the following ways:
65 *
66 * \li Double quotes are not allowed, except in the display name (a.k.a. friendly name).
67 * \li Comments (chunks of text enclosed by parentheses) are not allowed, though parenthesis are allowed in the
68 * display name if they're surrounded by double-quotes.
69 * \li Consecutive dots are allowed in the local part of the address, since they are accepted by gmail.
70 * \li Only the following non-alphanumeric characters are allowed in the local part: \verbatim '*+-=^_{}.~ \endverbatim
71 * \li IP address domains are not allowed (e.g., joe.smith\@[192.168.2.1] is invalid).
72 * \li UTF-8 is not allowed in any part of the address (display name, local part, or domain name).
73 *
74 * Example of valid address:
75 * \verbatim "Public, John Q. (Support)" <jq..public+support@generic-server.com> \endverbatim
76 *
77 * \see M_verify_email_address_list
78 *
79 * \param[in] addr email address to verify
80 * \return TRUE if the address is valid
81 */
82M_API M_bool M_verify_email_address(const char *addr);
83
84
85/*! Verify that the given domain name is valid.
86 *
87 * Valid domain names are composed of letters, digits, and hyphens ('-'), separated into sections
88 * by dots ('.'). Each section is limited to 63 chars, and may not begin or end with a hyphen.
89 * The entire domain name is limited to 253 characters - note that a 253 character domain name
90 * takes 255 bytes to store with the length-prefixed encoding used by DNS.
91 *
92 * \param[in] dname domain name to verify
93 * \return TRUE if the domain name is valid
94 */
95M_API M_bool M_verify_domain(const char *dname);
96
97
98/*! Verify that the given list of email addresses is valid.
99 *
100 * The list may be delimited by either commas (',') or semicolons (';'), but not both.
101 * This function limits the number of addresses in the list to 100 - this isn't a true
102 * standard, but it's the limit used virutally everywhere in practice.
103 *
104 * The list parser is tolerant of whitespace - individual addresses are trimmed before they're
105 * passed to the email address validator.
106 *
107 * The individual addresses in the list may include display names (a.k.a friendly names).
108 *
109 * \see M_verify_email_address
110 *
111 * \param[in] addr_list list of email addresses to verify
112 * \param[in] delim_type Type of delimiter to expect. Can be auto detected.
113 * \return TRUE if the list and all emails in it are valid
114 */
115M_API M_bool M_verify_email_address_list(const char *addr_list, M_verify_email_listdelim_t delim_type);
116
117/*! @} */
118
119__END_DECLS
120
121#endif /* M_EMAIL_VERIFY_H */
M_verify_email_listdelim_t
Definition: m_verify.h:46
M_bool M_verify_email_address(const char *addr)
M_bool M_verify_email_address_list(const char *addr_list, M_verify_email_listdelim_t delim_type)
M_bool M_verify_domain(const char *dname)
@ M_VERIFY_EMAIL_LISTDELIM_COMMA
Definition: m_verify.h:49
@ M_VERIFY_EMAIL_LISTDELIM_AUTO
Definition: m_verify.h:47
@ M_VERIFY_EMAIL_LISTDELIM_SEMICOLON
Definition: m_verify.h:48