Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

# 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" content-type, we should not use plain text alternative view template (the CB's behaviour is to use txt or html, or both depending what of them exists). Additionally, we cannot use file attachments since CB does much more crippled message then usually. This is one of the very few things that I hate on CB. Otherwise, CB is great piece of software!

View demo_outgoing_mail_controller.erl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
-module (demo_outgoing_mail_controller).
-export ([register_confirm/2]).
 
-define (DEMO_MAIL_FROM, "no-reply@demo.app.example.org").
-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) ->
From = ?DEMO_MAIL_FROM,
HumanFrom = string:join ([?DEMO_MAIL_NAME, " <", From, ">"], ""),
SubjLocal = demo_i18n:translate (SubjOrig, Lang),
SubjFull = case SubjTail of
[] -> SubjLocal;
_ -> lists:concat ([SubjLocal, ": ", SubjTail])
end,
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
Something went wrong with that request. Please try again.