Non ASCII headers
For the same reason that the non-ASCII content has to be encoded, the same applies to email headers. However, the content needs the
transfer encoding header to be set, while a header has the encoding information embedded. For that reason, the additional types
mailio::string_t
and (starting from C++20)
mailio::u8string_t
are defined. They contain the standard string as the underlying buffer,
in addition they keep the character set name and the encoding/decoding type. The charset can be an arbitrary string,
like ascii
, utf-8
,
iso-8859-1
(the case does not matter). The codec type can be one of the following:
ASCII (which is the basic seven bit), UTF-8, Base64, Quoted printable and Percent (URL encoding).
The name part of the email adress is of the type mailio::string_t
. So, a sender with the
cyrillic string can be set as
message msg;
msg.add_from(mail_address(string_t("маилио библиотека", "utf-8", codec::codec_t::BASE64), "address@mailio.dev"));
Same applies to the receiver and other headers using the mail address. In the same manner, the message subject which contains non ASCII
letters could be specified:
message msg;
msg.subject_raw(string_t("маилио библиотека", "utf-8", codec::codec_t::BASE64)));
Of course, the codec (third parameter) can be set to codec::codec_t::QUOTED_PRINTABLE
Attaching a file creates another MIME part within the email message (which is also the MIME). The file name is set by the MIME's name,
which is of the type string_t
. So, it is possible for a file on a disk to set the arbitrary
new name, even in another charset and codec:
ifstream ifs1("aleph0.png", std::ios::binary);
ifstream ifs2("cv.txt");
list<tuple<std::istream&, string_t, message::content_type_t>> atts;
atts.push_back(make_tuple(std::ref(ifs1), "profile.png", message::content_type_t(message::media_type_t::IMAGE, "png")));
atts.push_back(make_tuple(std::ref(ifs2), string_t("TomislavKarastojkovićCV.txt", "UTF-8", codec::codec_t::PERCENT), message::content_type_t(message::media_type_t::TEXT, "txt")));
msg.attach(atts);
The class string_t
has the cast constructor for the standard string, thus enabling using the
string literal or std::string
to be used without explicit mention of the
string_t
(the first attachment in the example).