I prepared the following macros to format e-mail adresses in a e-mail header.
\usepackage{xifthen}% Provides \ifthenelse and \isempty
% E-Mail header strings with format.
\newcommand{\fromString}{\textbf{From:} }
\newcommand{\toString}{\textbf{To:} }
% E-Mail with or without alias.
\newcommand{\email}[2][]{%
\ifthenelse{\isempty{#1}}%
{<#2>}% E-Mail only
{"#1" <#2>}% Alias and E-Mail
}
% E-Mail header From:
\newcommand{\emailFrom}[2][]{%
\ifthenelse{\isempty{#1}}%
{\fromString \email{#2}\\}% E-Mail only
{\fromString \email[#1]{#2}\\}% Alias and E-Mail
}
% E-Mail header To:
\newcommand{\emailTo}[2][]{%
\ifthenelse{\isempty{#1}}%
{\toString \email{#2}\\}% E-Mail only
{\toString \email[#1]{#2}\\}% Alias and E-Mail
}
The macros can be used as illustrated by the following examples. Please mind that []
are used for optional arguments instead of {}
.
\email[Doe, John]{john.doe@stackexchange.com}
\emailFrom[Doe, John]{john.doe@stackexchange.com}
\emailFrom{john.doe@stackexchange.com}
\emailTo[Doe, John]{john.doe@stackexchange.com}
\emailTo{john.doe@stackexchange.com}
The formatted output looks like this:
"Doe, John" <john.doe@stackexchange.com>
From: "Doe, John" <john.doe@stackexchange.com>
From: <john.doe@stackexchange.com>
To: "Doe, John" <john.doe@stackexchange.com>
To: <john.doe@stackexchange.com>
How could I extend the macro so that I can use it with multiple e-mail addresses? The following example should explain the issue. As you can see by the third example, the occurance of the alias is individual for each e-mail entry.
To: "Doe, John" <john.doe@stackexchange.com>, "Doe, Jane" <jane.doe@stackexchange.com>
To: <john.doe@stackexchange.com>, <jane.doe@stackexchange.com>
To: <john.doe@stackexchange.com>, "Doe, Jane" <jane.doe@stackexchange.com>
Since I am new to using macros in latex you are also welcome to generally improve my commands or leave comments to do so.
Update:
While working with several email I realized that it can also happen, that there is no email address given, only the email alias. This happens when someone forwards emails e.g., as an internal conversation in a company. Nevertheless, I accept this format as a valid email header. Do you see any chance to include this schema in the macros? Here is an example.
From: John Doe
Subject: Re: E-Mail headers
Date: Wed, 22 Aug 2012 23:42:00 +0200
To: Jane Doe