![]() |
libtld 2.0.14
A library to determine the Top-Level Domain name of any Internet URI.
|
Implementation of an email parser. More...
#include "libtld/tld.h"
#include <stdio.h>
#include <string.h>
#include <memory>
#include <iostream>
#include <algorithm>
Go to the source code of this file.
Functions | |
struct tld_email_list * | tld_email_alloc () |
Allocate a list of emails object. | |
int | tld_email_count (struct tld_email_list *list) |
Return the number of emails found after a parse. | |
void | tld_email_free (struct tld_email_list *list) |
Free the list of emails. | |
int | tld_email_next (struct tld_email_list *list, struct tld_email *e) |
Retrieve the next email. | |
tld_result | tld_email_parse (struct tld_email_list *list, char const *emails, int flags) |
Parse a list of emails in the email list object. | |
void | tld_email_rewind (struct tld_email_list *list) |
Rewind the reading of the emails. | |
This file includes all the functions available in the C library of libtld. The format of emails is described in RFC 5322 paragraph 3.4. That RFC uses the ABNF defined in RFC 5234. We limit our implementation to reading a line of email addresses, not a full email buffer. Thus we are limited to the content of a field such as the "To:" field. We support emails that are written as:
usern.nosp@m.ame@.nosp@m.domai.nosp@m.n.tl.nosp@m.d "First & Last Name" usern.nosp@m.ame@.nosp@m.domai.nosp@m.n.tl.nosp@m.d
And we support lists thereof (emails separated by commas.)
Also, emails may include internationalized characters (Unicode). Since our systems make use of UTF-8, the input format can be considered as UTF-8 in which case we simply accept all characters from 0xA0 to 0x10FFFF (the full Unicode range.) However, we also support the Q and B encoding to directly support email fields. The B encoding is base64 of UTF-8 data which works in ASCII 7 bit. The Q is ASCII with characters marked with the equal sign and their 2 byte codes. This works well when all the characters fit in one character set. Note that all characters can be represented because more than one encoding can be used within a phrase, but it is unlikely to be used that way.
Text versions:
http://www.ietf.org/rfc/rfc5322.txt http://www.ietf.org/rfc/rfc5234.txt http://www.ietf.org/rfc/rfc1522.txt
HTML versions (with links):
http://tools.ietf.org/html/rfc5322 http://tools.ietf.org/html/rfc5234 http://tools.ietf.org/html/rfc1522
The ABNF is a bit complicated to use as is, so there is a lex and yacc which I find easier to implement to my point of view:
Definition in file tld_emails.cpp.
struct tld_email_list * tld_email_alloc | ( | ) |
This function allocates a list of emails object that can then be used to parse a string representing a list of emails and retrieve those emails with the use of the tld_email_next() function.
Definition at line 1480 of file tld_emails.cpp.
References tld_email_list::tld_email_list().
Referenced by PHP_FUNCTION().
int tld_email_count | ( | struct tld_email_list * | list | ) |
This function returns the number of emails that were found in the list of emails passed to the tld_email_parse() function.
[in] | list | The email list object. |
Definition at line 1525 of file tld_emails.cpp.
References list().
void tld_email_free | ( | struct tld_email_list * | list | ) |
This function frees the list of emails as allocated by the tld_email_alloc(). Afterward the list
pointer is not valid anymore.
[in] | list | The list to be freed. |
Definition at line 1493 of file tld_emails.cpp.
References list().
Referenced by PHP_FUNCTION().
int tld_email_next | ( | struct tld_email_list * | list, |
struct tld_email * | e | ||
) |
This function retrieves the next email found when parsing the emails passed to to the tld_email_parse() function. The function returns 1 when another email was defined. It returns 0 when no more emails exist and the e
parameter does not get set. The function can be called any number of times after it returned zero (0).
[in] | list | The list from which the email is to be read. |
[out] | e | The buffer where the email is to be written. |
Definition at line 1559 of file tld_emails.cpp.
References list().
Referenced by PHP_FUNCTION().
tld_result tld_email_parse | ( | struct tld_email_list * | list, |
char const * | emails, | ||
int | flags | ||
) |
This function parses the email listed in the emails
parameter and saves the result in the list parameter. The function saves the information as a list of email list in the list
object.
[in] | list | The list of emails object. |
[in] | emails | The list of emails to be parsed. |
[in] | flags | The flags are used to change the behavior of the parser. |
Definition at line 1511 of file tld_emails.cpp.
References list(), and tld_email_list::parse().
Referenced by PHP_FUNCTION().
void tld_email_rewind | ( | struct tld_email_list * | list | ) |
This function resets the position to the start of the list. The next call to the tld_email_next() function will return the first email again.
[in] | list | The list of email object to reset. |
Definition at line 1538 of file tld_emails.cpp.
References list().
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.