Skip to main content

address_with_name

Function address_with_name 

Source
pub fn address_with_name(name: &str, address: &str) -> String
Expand description

Formats Name <address>, quoting the name when needed, like Rails’ email_address_with_name.

Double quotes and line breaks in name become spaces, so a user-typed name cannot break the header. An empty name gives the bare address.

§Examples

use ocre::mail::address_with_name;

assert_eq!(address_with_name("Ada Lovelace", "ada@example.com"), "Ada Lovelace <ada@example.com>");
assert_eq!(address_with_name("Acme, Inc.", "x@acme.test"), "\"Acme, Inc.\" <x@acme.test>");
assert_eq!(address_with_name(" ", "ada@example.com"), "ada@example.com");