Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# ChicagoBoss outgoing mail controller versus localization, internalization, and unicode. When the mail view template is in Unicode, we have to override Content-Type by hand as well as we have to encode headers (especially Subject) to declare it's encoding and to be base64-encoded. Another problem is that since we "hardcode" the "text/html" cont…
-module (demo_outgoing_mail_controller).
-export ([register_confirm/2]).
-define (DEMO_MAIL_FROM, "").
-define (DEMO_MAIL_NAME, "DEMO Application").
%% Lang is not neccessarily the same as User:lang (),
%% but rather the language of the sign-up form
register_confirm (User, Lang) ->
SubjOrig = ?DEMO_MAIL_NAME ++ "Sign-Up Confirmation",
{From, To, Headers} = hdr_prepare (User:email (), Lang, SubjOrig),
{ok, From, To, Headers, [{user, User}]}.
%% Helper functions, not a sender action!
hdr_prepare (To, Lang, SubjOrig) ->
hdr_prepare (To, Lang, SubjOrig, []).
hdr_prepare (To, Lang, SubjOrig, SubjTail) ->
HumanFrom = string:join ([?DEMO_MAIL_NAME, " <", From, ">"], ""),
SubjLocal = demo_i18n:translate (SubjOrig, Lang),
SubjFull = case SubjTail of
[] -> SubjLocal;
_ -> lists:concat ([SubjLocal, ": ", SubjTail])
SubjB64 = base64:encode_to_string (SubjFull),
Subject = string:join (["=?UTF-8?B?", SubjB64, "?="], ""),
Headers = [
{"To", To}, {"From", HumanFrom},
{"Subject", Subject}, {"Content-Language", Lang},
{"Content-Type", "text/html; charset=UTF-8"}
{From, To, Headers}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment