? mailhandler_freetagging_d6.patch
Index: mailhandler.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/Attic/mailhandler.module,v
retrieving revision 1.96.2.1
diff -u -p -r1.96.2.1 mailhandler.module
--- mailhandler.module	15 May 2008 10:43:55 -0000	1.96.2.1
+++ mailhandler.module	17 Jul 2008 14:08:32 -0000
@@ -106,6 +106,21 @@ function mailhandler_help($path = 'admin
   $output = '';
   $link->add = l(t('Add mailbox'), 'admin/content/mailhandler/add');

+  // Gather examples of useful commands, and build a definition list with them:
+  $commands[] = array('command' => 'taxonomy: [term1, term2]',
+                      'description' => t('Use this to add the terms <em>term1</em> and <em>term2</em> to the node.<br />
+                      Both of the terms should already exist. In case they do not exist already, they will be quietly ommitted'));
+  $commands[] = array('command' => 'taxonomy[v]: [term1, term2]',
+                      'description' => t('Similar to the above: adds the terms <em>term1</em> and <em>term2</em> to the node, but uses the vocabulary with the vocabulary id <em>v</em>. For example <em>taxonomy[3]</em> will chose only terms from the vocabulary which id is 3.<br />
+                      In case some of the terms do not exist already, the behavior will depend on whether the vocabulary is a free tagging vocabulary or not. If it is a free tagging vocabulary, the term will be added, otherwise, it will be quietly ommitted'));
+
+  $commands_list = '<dl>';
+  foreach ($commands as $command) {
+    $commands_list .= '<dt>'. $command['command'] .'</dt>';
+    $commands_list .= '<dl>'. $command['description'] .'</dl>';
+  }
+  $commands_list .= '</dl>';
+
   switch ($path) {
     case 'admin/help#mailhandler':
       $output = '<p>'. t('The mailhandler module allows registered users to create or edit nodes and comments via e-mail. Users may post taxonomy terms, teasers, and other post attributes using the mail commands capability.  This module is useful because e-mail is the preferred method of communication by community members.') .'</p>';
@@ -126,6 +141,8 @@ function mailhandler_help($path = 'admin
      '@admin-mailhandler' => url('admin/content/mailhandler'),
      '@admin-mailhandler-settings' => url('admin/settings/mailhandler'),
    ));
+      $output .= '<h3 id="commands">'. t('Useful Commands') .'</h3>';
+      $output .= $commands_list;
       $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%mailhandler">Mailhandler page</a>.', array('%mailhandler' => 'http://www.drupal.org/handbook/modules/mailhandler/')) .'</p>';
       return $output;
     case 'admin/content/mailhandler':
Index: mailhandler.retrieve.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/Attic/mailhandler.retrieve.inc,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 mailhandler.retrieve.inc
--- mailhandler.retrieve.inc	15 Jul 2008 14:23:48 -0000	1.1.2.6
+++ mailhandler.retrieve.inc	17 Jul 2008 14:08:34 -0000
@@ -256,6 +256,12 @@ function mailhandler_process_message($he
     $body = trim($mailbox['commands']) ."\n". $body;
   }

+  // Set a default type if none provided
+  if (!$node->type) $node->type = mailhandler_default_type();
+
+  // Reset $node->taxonomy
+  $node->taxonomy = array();
+
   // Process the commands and the body
   $lines = explode("\n", $body);
   for ($i = 0; $i < count($lines); $i++) {
@@ -278,6 +284,28 @@ function mailhandler_process_message($he
       // if needed, map term names into IDs. this should move to taxonomy_mailhandler()
       if ($data[0] == 'taxonomy' && !is_numeric($data[1][0])) {
         array_walk($data[1], 'mailhandler_term_map');
+        $node->taxonomy = array_merge($node->taxonomy, $data[1]);
+        unset($data[0]);
+      }
+      else if (substr($data[0], 0, 9) == 'taxonomy[' && substr($data[0], -1, 1) == ']'){
+        // make sure a valid vid is passed in:
+        $vid = substr($data[0], 9, -1);
+        $vocabulary = taxonomy_get_vocabulary($vid);
+        // if the vocabulary is not activated for that node type, unset $data[0], so the command will be ommited from $node
+        // TODO: add an error message
+        if (!in_array($node->type, $vocabulary->nodes)) {
+          unset($data[0]);
+        }
+        else if (!$vocabulary->tags) {
+          array_walk($data[1], 'mailhandler_term_map');
+          $node->taxonomy = array_merge($node->taxonomy, $data[1]);
+          unset($data[0]);
+        }
+        else if ($vocabulary->tags) {
+          // for freetagging vocabularies, we just pass the list of terms
+          $node->taxonomy['tags'][$vid] = implode(',', $data[1]);
+          unset($data[0]); // unset, so it won't be included when populating the node object
+        }
       }
       if (!empty($data[0])) {
         $node->$data[0] = $data[1];
@@ -301,8 +329,6 @@ function mailhandler_process_message($he

   if (!$node->teaser) $node->teaser = node_teaser($node->body);

-  // Set a default type if none provided
-  if (!$node->type) $node->type = mailhandler_default_type();
   // decode encoded subject line
   $subjectarr = imap_mime_header_decode($header->subject);
   for ($i = 0; $i < count($subjectarr); $i++) {
