Mandrill - Send HTML tags inside X-MC-MergeVars - mandrill

I tried to send HTML tags inside X-MC-MergeVars for my Mandrill handlebar template, but doesn't seem to work.
PHP part:
[...]
$message->getHeaders()->addTextHeader("X-MC-MergeVars", json_encode(["foo" => "b<strong>a</strong>r"]));
Mandrill template part:
[...]
Here is my var {{foo}}
And the result
Here is my var b<strong>a</strong>r
Do you know if it's possible to Mandrill to translate HTML inside a string?
Thank you

The solution is pretty easy actually.
You have to replace your double brace {{by triple brace {{{
[...]
Here is my var {{{foo}}}
Mandrill API (HTML escaping)
Handlebars HTML-escapes values returned by an {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", "{{{.

Related

The twitter API seems to escape ampersand, <, > but nothing else?

I wrote the following test tweet:
&“”‘’®©™¶•·§–—
Then fetched it using the 'user_timeline' api call. The following json was returned:
...
"text": "&“”‘’®©™¶•·§–—",
...
It seems strange the ampersand is the only escaped symbol.
Are there any other escaped symbols? I can't find a definitive list in the docs.
Alternatively, is it possible to specify if the api should return escaped/ unescaped characters?
Edit
Test tweet:
<>=+
Returns:
...
'text': '<>=+'
...

Get raw data in symfony 2 request

i'm trying to get some HTML code in a post Request with the symfony 2 API.
For example when i post something like "< p > hello < / p > "
I got in my request action handler (using $request->request->get(X)) an escaped string => "p hello /p"
Is there any way to get the raw data in the action handler ?
$request->request->get(X) doesn't escape values. To view posted data use Profiler. Your data are escaped by something else.

Net::HTTP.post_form cannot send parameter

Hi I'm using rails and socket.io in node.js What I'm trying to do is send a param in rails model using Net::HTTP.post_form and get the param in node.js file which is server.js
model send.rb
def self.push(userid)
url = "http://socket.mydomain.com/push"
res = Net::HTTP.post_form(URI.parse(URI.encode(url)),data)
end
server.js
app.post('/push', function (req, res) {
console.log(req.param.userid)
});
req variable
req.ip =127.0.0.1
req.protocol= http
req.path = /push
req.host = socket.mydomain.com
req.param
I printed all the values but param always empty is there any solution for this? thanks in advance! :D
In Express you can retrieve values posted (HTTP POST) in an HTML form via req.body.searchText if you issue use app.use(express.bodyParser()); Notice that HTML form values come in req.body, not req.params.
Having said that, I am not sure how these values are submitted to the server when you use Socket.io rather than a "normal" HTTP POST on an HTML form.
I realize this is not an exact answer to your question, but wanted to mention how "normal" HTML form values are handled in case it helps and this was way to long to include as a comment.

Receive an email with Actionmailer and read the plain body text

I am using IMAP to receive some emails from gmail and then parse them with the new Rails 3 ActionMailer receive method.
raw_email = imap.uid_fetch(uid, ['RFC822']).first.attr['RFC822']
email = UserMailer.receive(raw_email)
email is now a Mail::Message Class and to:, :from and :subject works fine. However I can't figure out how to get the plain text from the body. Before Rails 3 I could use the tmail_body_extractors plugin to get the plain body.
How would you do this with Rails 3?
Jakobinsky:
email.body.raw_source is a bit closer be still gives me a lot of garbage.
"--001636310325efcc88049508323d\r\nContent-Type: text/plain;
charset=ISO-8859-1\r\nContent-Transfer-Encoding:
quoted-printable\r\n\r\nThis is some body
content\r\n\r\n--=20\r\nVenlig Hilsen\r\nAsbj=F8rn
Morell\r\n\r\n--001636310325efcc88049508323d\r\nContent-Type:
text/html; charset=ISO-8859-1\r\nContent-Transfer-Encoding:
quoted-printable\r\n\r\naf mail-- Venlig
HilsenAsbj=F8rn
Morell\r\n\r\n--001636310325efcc88049508323d--"
Should I roll my own helpers for cleaning up the raw_source or is there already a method ,gem or helper for that?
See the answer on this question:
Rails - Mail, getting the body as Plain Text
In short the solution is:
plain_part = message.multipart? ? (message.text_part ? message.text_part.body.decoded : nil) : message.body.decoded
But I recommend reading the full answer as it is very good and comprehensive.
You can extract the plain body from body.parts. There is still however some headers left in the body:
if body.multipart?
body.parts.each do |p|
if p.mime_type == "text/plain"
body = p.body
end
end
end
body.to_s
You should be able to retrieve the body as simple as email.body.raw_source.
I haven't tested it myself, but you can take a look as the source code for ActionMailer:: Message#body.

Strange issue about # in url

http://localhost/test/editformquestions.php#?formid=1
And
http://localhost/test/editformquestions.php?formid=1
I failed to retrieve $_GET['formid'] in the first one,why?
The content of test/editformquestions.php is simply:
<?php
echo $_GET['formid'];
?>
Characters after the hash # are to be used by the browser, they are not sent back to the server.
# is a hash character, not a GET variable.
You need to put the ? before any hashes, otherwise the $_GET array will not be populated.
# is used by the browser, and is never sent to the server. Everything after a # (regardless of what it is) is used by the browser to jump to a location on the page.
So:
http://localhost/test/editformquestions.php#?formid=1
Will be split as follows:
Server request to http://localhost/test/editformquestions.php
Browser then searches in page for:
<a name="?formid=1">named anchor tag</a>
What you should do is:
http://localhost/test/editformquestions.php?formid=1&othervar=2#anchorinpage
Or, if you need the # in a query-string parameter:
http://localhost/test/editformquestions.php?formid=1&othervar=textwith%23init
The # is fragment identifier for a URL: http://en.wikipedia.org/wiki/Fragment_identifier
To use it as part of an array variable you'll need to url encode it:
'#' becomes '%23' when url-encoded
In javascript you can accomplish url encoding with the encodeURI() function
A HTTP URL may contain these parts:
protocol: http://
domain: localhost
path: /test/editformquestions.php
query string: ?formid=1 - always starts with a ?
fragment: #something - always starts with a # - whatever comes after the # mark is NOT sent to the server.
What you have in your first example (http://localhost/test/editformquestions.php#?formid=1) is a fragment containing this: #?formid=1. It does not matter that there's a ? in the fragment; as soon as it's behind the #, it is not sent from the browser.
So, in essence, you are sending to the server only this: http://localhost/test/editformquestions.php - as you can see, there is no formid in that request.

Resources