
Ralph Fiennes, Alan Cumming & Liam Neeson
In no particular order here are ten love songs from my iTunes library that all have parentheses in their titles.
Drupal is usually great at handling special characters. Unlike other systems everything has always worked out of the box for me in Drupal. Recently however I did end up with an edge case involving mail headers.
What I wanted to do was to send a nicely formatted From-header so the site name would show up instead of just the e-mail address. The header could for example look like this: From: Mÿ Fäncÿ Sitë <mail@example.com>
As e-mail headers can only contain US-ASCII characters any special characters needs to be escaped, but Drupal does this automatically, right? Yes and no. Drupal does run all mail headers through mime_header_encode() to escape non-US-ASCII characters. In our case that results in:
From: =?UTF-8?B?TcO/IEbDpG5jw78gU2l0w6sgPG1haWxAZXhhbXBsZS5jb20+?=
It's a little more garbled than it should be. A correctly formatted header in our case would be:
From: =?UTF-8?B?TcO/IEbDpG5jw78gU2l0w6s=?= <mail@example.com>
As you can see the "name" of the from-address should be escaped with all the UTF-8 magic, but the e-mail address itself should not be encoded. E-mail clients handle these malformed headers badly—often showing no From-name at all or showing a part of the following header as the From-name.
The solution is to do the encoding yourself before sending the header off to drupal_mail(). In our case it would look like this:
$from = mime_header_encode('Mÿ Fäncÿ Sitë'). ' <mail@example.com>';
This of course means that the name is runs through the encode twice—once by you and once by drupal_mail(). Fortunately, mime_header_encode() is smart enough to only encode strings which contain non-US-ASCII characters and you can safely run strings through it multiple times without risking double-encoding issues.
It's been too long since we had a Drupal event in Copenhagen so on October 3 the Drupal Denmark association is putting on a Drupal Day. It'll be a one-day, free event in Barcamp-style with all kinds of Drupal goodness. Come meet us all, we don't bite!
The lumiere project has been a collection of soundless minutes for two years now with Brittany and I collecting videos. The project is still going strong in no small part due to continued participation and support from talented people like Michael and Sam. The first four videos are still online showing rusty tools and cars moving slowly (1, 2, 3, 4).
In the department on non-moving, non-digital images factory takeover has turned one year old. It is full of images from the household's old cameras and it is a very fun thing to produce. The latest addition is a Lubitel 166 and I'm enjoying the medium format film.
This year's the new project is the new Hoist that I mentioned in my previous post. We have taken all the things we learned from making collaboration software for two years and applied it to the new product and the result is software that works like you (rather than software that dictates how you should work). It's a new paradigm for collaboration where the individual is empowered in a way you don't usually see. I'm very excited about showing off the result of 5 months development off next week when we start holding workshops.
The day are busy at Hoist. We are ready to launch our new work tool very soon (workshops are held next week with few spots left—let me know if you're interested).
Working on the user interface goodness I needed to execute some javascript immediately after a node has been posted in Drupal. The javascript should not be included on every node view, only the first. The nodeapi's 'insert' operation can't be used to include javascript because there is a redirect after it is processed and the 'view' operation can't tell if a node is brand new or not.
The solution I used is to set a session variable. It feels a little hackish, but it works great.
function yourmodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'insert') {
$_SESSION['yourmodule'][$node->nid] = $node->nid;
}
if ($op == 'view' && $_SESSION['yourmodule'][$node->nid]) {
// Insert call to drupal_add_js() here.
unset($_SESSION['yourmodule'][$node->nid]);
}
} This is the personal website of Andreas Haugstrup Pedersen: commentary on media, communication, culture and technology. Read more»