|
Email Generator 2.1.3
Email addresses in each country's style for C++23
|
This guide covers every feature of the email-generator library. For a quick overview, see the README. For the data and how it was built, see Data and Method. For the full API reference, run doxygen Doxyfile from the repository root and open doc/api/html/index.html.
Copy dasmig/emailgen.hpp, dasmig/core.hpp and the dasmig/core/ directory into your include path, keeping them together. Supply resources/ next to the program, or define DASMIG_EMAIL_EMBED to compile the lite tier in.
instance() loads the lite tier on first use (or full if there is no lite), from the compiled-in copy or from the first of resources/, ../resources, email-generator/resources and ../email-generator/resources that has it. lite holds the 195 sovereign states, full the territories as well.
Each load replaces the data and every layer loaded before.
first.last, flast, last_first, first85, first.last1988, the nickname alone, handles such as quietfox42. Only the styles the request can fill are eligible: a call with no names draws among the handle styles, a call with no birth year never produces a year.Ø is o, ß is ss), the given name is its first word, the family name its first word that is not a particle (de la Cruz is cruz, Müller-Schmidt is muller). A name in a script with no ASCII form is dropped; pass its Latin form to use it.[a-z0-9._-], no leading, trailing or doubled marks, at most 64 characters.weighted = false draws countries, styles and domains uniformly.safe = true makes an address that cannot reach a real person: the domain is example.com, example.net or example.org (RFC 2606), reserved is true and kind is empty. phone.reserved means the same for numbers. The local part is unchanged.
get_email(request, seed) gives the same result for the same request, seed and data, on every platform, without advancing the instance engine.get_email(request) draws a fresh seed from the instance engine, initially seeded from system entropy. There are no generator-level seed() or unseed() controls; for deterministic sequences, keep a dasmig::core::rng in the caller and pass its next value as the seed.e.seed() is the seed a result was generated from: it replays it with the same request and data."country", "style", "local", "number", "domain"), so adding a field later does not change the others.The shipped data is a base layer in seven tables (see Data and Method): countries, fold, particles, profiles, email_styles, providers and words. A layer adds, changes or removes rows of one table without editing the shipped files.
dasmig::core::tsv_error with the file, line and column, and the data stays as it was.layers(table) lists what is loaded for a table: source, mode, rows added, replaced and removed, and warnings such as unknown columns.load(...) replaces the base and drops every layer.Every result records the seed and the data it came from:
to_json() gives the result as JSON, the form the WebAssembly layer and the game consume. Seeds are strings because JavaScript numbers cannot hold every 64-bit value. to_json(writer) writes into an existing dasmig::core::json_writer, for composing larger documents.
Define DASMIG_EMAIL_EMBED before including the header to compile the lite tier into the program. load(dataset::lite) and instance() then use it and need no files. The compiled-in data has the same data_hash() as the files, so seeds replay the same either way.
dasmig/emailgen_data.hpp is generated from resources/lite by make embed; CI checks it is up to date. It is about 185 KB.
Each emg instance is independent. Concurrent calls to get_email(request, seed) on the same instance are safe; calls that use the instance engine (get_email(request)), loading and extending require external synchronisation (e.g. a std::mutex).
get_email_batch returns a std::vector, and for_each_email streams the items to a sink in index order without holding the batch.
i is exactly get_email(request, core::item_seed(batch_seed, first + i)). A range can be generated directly (first = 1000 starts at item 1000), two batches that follow each other equal one, and the output is the same for any threads (0 means the hardware count). Without a batch_seed one is drawn like the single getter draws its own.core::batch_options has count, first, threads and unique. The request describes one item; the options describe the batch..unique = core::unique_rule::by<email>(key) regenerates an item whose key already appeared in the batch, with a deterministic retry seed, and throws std::runtime_error naming the item when the attempts run out. With a fixed name in one country the styles and domains give only so many distinct addresses; vary the request or leave the names out for large unique batches.core::jsonl_writer writes one to_json() per line, core::csv_writer flattens each result's JSON into dotted columns. Any callable (std::uint64_t index, email&) works.| Exception | When |
|---|---|
std::runtime_error | Any generation call before data is loaded; no style fits or no domain exists for the country; a unique batch that runs out of attempts |
std::invalid_argument | An unknown country |
dasmig::core::tsv_error | A malformed table or layer (message gives file, line and column); the data is unchanged |