diff --git a/include/ajax.draft.php b/include/ajax.draft.php
index b01054ed8b9d6bf8c193e8420e4d54769c1cfce2..e963605ad9d22890aa65732c5c44aa3f4e795cf5 100644
--- a/include/ajax.draft.php
+++ b/include/ajax.draft.php
@@ -381,19 +381,20 @@ class DraftAjaxAPI extends AjaxController {
     function _findDraftBody($vars) {
         if (isset($vars['name'])) {
             $parts = array();
+            // Support nested `name`, like trans[lang]
             if (preg_match('`(\w+)(?:\[(\w+)\])?(?:\[(\w+)\])?`', $_POST['name'], $parts)) {
                 array_shift($parts);
                 $focus = $vars;
                 foreach ($parts as $p)
                     $focus = $focus[$p];
-                return urldecode($focus);
+                return $focus;
             }
         }
         $field_list = array('response', 'note', 'answer', 'body',
              'message', 'issue', 'description');
         foreach ($field_list as $field) {
             if (isset($vars[$field])) {
-                return urldecode($vars[$field]);
+                return $vars[$field];
             }
         }
 
diff --git a/include/class.attachment.php b/include/class.attachment.php
index 748266003819edd0fbde1f248b0afdf15657a8a8..3247d06912d8baafaa895843556b6236f809a35d 100644
--- a/include/class.attachment.php
+++ b/include/class.attachment.php
@@ -22,10 +22,10 @@ class Attachment extends VerySimpleModel {
         'pk' => array('id'),
         'select_related' => array('file'),
         'joins' => array(
-            'thread_entry' => array(
+            'draft' => array(
                 'constraint' => array(
-                    'type' => "'H'",
-                    'object_id' => 'ThreadEntry.id',
+                    'type' => "'D'",
+                    'object_id' => 'Draft.id',
                 ),
             ),
             'file' => array(
@@ -33,6 +33,12 @@ class Attachment extends VerySimpleModel {
                     'file_id' => 'AttachmentFile.id',
                 ),
             ),
+            'thread_entry' => array(
+                'constraint' => array(
+                    'type' => "'H'",
+                    'object_id' => 'ThreadEntry.id',
+                ),
+            ),
         ),
     );
 
diff --git a/include/class.draft.php b/include/class.draft.php
index 5b2d8462bc5515eec588df3fed2c05aa8fe7294d..1938064f8bfe5dd605bfc1c56077f0be58e06bd1 100644
--- a/include/class.draft.php
+++ b/include/class.draft.php
@@ -167,14 +167,12 @@ class Draft extends VerySimpleModel {
      * are cleaned up.
      */
     static function deleteForNamespace($namespace, $staff_id=false) {
-        $sql = 'DELETE attach FROM '.ATTACHMENT_TABLE.' attach
-                INNER JOIN '.DRAFT_TABLE.' draft
-                ON (attach.object_id = draft.id AND attach.`type`=\'D\')
-                WHERE draft.`namespace` LIKE '.db_input($namespace);
+        $attachments = Attachment::objects()
+            ->filter(array('draft__namespace__like' => $namespace));
         if ($staff_id)
-            $sql .= ' AND draft.staff_id='.db_input($staff_id);
-        if (!db_query($sql))
-            return false;
+            $attachments->filter(array('draft__staff_id' => $staff_id));
+
+        $attachments->delete();
 
         $criteria = array('namespace__like'=>$namespace);
         if ($staff_id)
@@ -183,11 +181,10 @@ class Draft extends VerySimpleModel {
     }
 
     static function cleanup() {
-        // Keep client drafts for two weeks (14 days)
+        // Keep drafts for two weeks (14 days)
         $sql = 'DELETE FROM '.DRAFT_TABLE
-            ." WHERE `namespace` LIKE 'ticket.client.%'
-            AND ((updated IS NULL AND datediff(now(), created) > 14)
-                OR datediff(now(), updated) > 14)";
+            ." WHERE (updated IS NULL AND datediff(now(), created) > 14)
+                OR datediff(now(), updated) > 14";
         return db_query($sql);
     }
 }