/[drupal]/contributions/modules/mailhandler/mailhandler.module
ViewVC logotype

Diff of /contributions/modules/mailhandler/mailhandler.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.87.2.14, Thu Jul 17 19:44:59 2008 UTC revision 1.87.2.15, Sat Aug 9 11:56:00 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: mailhandler.module,v 1.87.2.13 2008/07/15 14:25:07 weitzman Exp $  // $Id: mailhandler.module,v 1.87.2.14 2008/07/17 19:44:59 weitzman Exp $
3    
4  /**  /**
5   * Retrieve all msgs from a given mailbox and process them.   * Retrieve all msgs from a given mailbox and process them.
# Line 259  function mailhandler_process_message($he Line 259  function mailhandler_process_message($he
259      $body = trim($mailbox['commands']) ."\n". $body;      $body = trim($mailbox['commands']) ."\n". $body;
260    }    }
261    
262      // We set the type now, because we need it in the next block
263      if (!$node->type) $node->type = 'blog';
264    
265      // Reset $node->taxonomy
266      $node->taxonomy = array();
267    
268    // process the commands and the body    // process the commands and the body
269    $lines = explode("\n", $body);    $lines = explode("\n", $body);
270    for ($i = 0; $i < count($lines); $i++) {    for ($i = 0; $i < count($lines); $i++) {
# Line 279  function mailhandler_process_message($he Line 285  function mailhandler_process_message($he
285        // if needed, map term names into IDs. this should move to taxonomy_mailhandler()        // if needed, map term names into IDs. this should move to taxonomy_mailhandler()
286        if ($data[0] == 'taxonomy' && !is_numeric($data[1][0])) {        if ($data[0] == 'taxonomy' && !is_numeric($data[1][0])) {
287          array_walk($data[1], 'mailhandler_term_map');          array_walk($data[1], 'mailhandler_term_map');
288            $node->taxonomy = array_merge($node->taxonomy, $data[1]);
289            unset($data[0]);
290          }
291          else if (substr($data[0], 0, 9) == 'taxonomy[' && substr($data[0], -1, 1) == ']'){
292            // make sure a valid vid is passed in:
293            $vid = substr($data[0], 9, -1);
294            $vocabulary = taxonomy_get_vocabulary($vid);
295            // if the vocabulary is not activated for that node type, unset $data[0], so the command will be ommited from $node
296            // TODO: add an error message
297            if (!in_array($node->type, $vocabulary->nodes)) {
298              unset($data[0]);
299            }
300            else if (!$vocabulary->tags) {
301              array_walk($data[1], 'mailhandler_term_map');
302              $node->taxonomy = array_merge($node->taxonomy, $data[1]);
303              unset($data[0]);
304            }
305            else if ($vocabulary->tags) {
306              // for freetagging vocabularies, we just pass the list of terms
307              $node->taxonomy['tags'][$vid] = implode(',', $data[1]);
308              unset($data[0]); // unset, so it won't be included when populating the node object
309            }
310        }        }
311        if (!empty($data[0])) {        if (!empty($data[0])) {
312          $node->$data[0] = $data[1];          $node->$data[0] = $data[1];
# Line 301  function mailhandler_process_message($he Line 329  function mailhandler_process_message($he
329    $node->body = implode("\n", $tmp);    $node->body = implode("\n", $tmp);
330    
331    if (!$node->teaser) $node->teaser = node_teaser($node->body);    if (!$node->teaser) $node->teaser = node_teaser($node->body);
332    if (!$node->type) $node->type = 'blog';  
333    // decode encoded subject line    // decode encoded subject line
334    $subjectarr = imap_mime_header_decode($header->subject);    $subjectarr = imap_mime_header_decode($header->subject);
335    for ($i = 0; $i < count($subjectarr); $i++) {    for ($i = 0; $i < count($subjectarr); $i++) {
# Line 767  function mailhandler_form($edit = array( Line 795  function mailhandler_form($edit = array(
795    $form['security'] = array('#type' => 'radios', '#title' => t('Security'), '#options' => array(t('Disabled'), t('Require password')), '#default_value' => $edit['security'], '#description' => t('Disable security if your site does not require a password in the Commands section of incoming e-mails. Note: Security=Enabled and Mime preference=HTML is an unsupported combination.'));    $form['security'] = array('#type' => 'radios', '#title' => t('Security'), '#options' => array(t('Disabled'), t('Require password')), '#default_value' => $edit['security'], '#description' => t('Disable security if your site does not require a password in the Commands section of incoming e-mails. Note: Security=Enabled and Mime preference=HTML is an unsupported combination.'));
796    $form['replies'] = array('#type' => 'radios', '#title' => t('Send error replies'), '#options' => array(t('Disabled'), t('Enabled')), '#default_value' => $edit['replies'], '#description' => t('Send helpful replies to all unsuccessful e-mail submissions. Consider disabling when a listserv posts to this mailbox.'));    $form['replies'] = array('#type' => 'radios', '#title' => t('Send error replies'), '#options' => array(t('Disabled'), t('Enabled')), '#default_value' => $edit['replies'], '#description' => t('Send helpful replies to all unsuccessful e-mail submissions. Consider disabling when a listserv posts to this mailbox.'));
797    $form['fromheader'] = array('#type' => 'textfield', '#title' => t('From header'), '#default_value' => $edit['fromheader'], '#description' => t('Use this e-mail header to determine the author of the resulting node. Admins usually leave this field blank (thus using the <strong>From</strong> header), but <strong>Sender</strong> is also useful when working with listservs.'));    $form['fromheader'] = array('#type' => 'textfield', '#title' => t('From header'), '#default_value' => $edit['fromheader'], '#description' => t('Use this e-mail header to determine the author of the resulting node. Admins usually leave this field blank (thus using the <strong>From</strong> header), but <strong>Sender</strong> is also useful when working with listservs.'));
798    $form['commands'] = array('#type' => 'textarea', '#title' => t('Default commands'), '#default_value' => $edit['commands'], '#description' => t('A set of commands which are added to each message. One command per line. See %link.', array('%link' => l(t('Commands'), 'admin/help/mailhandler/#commands'))));    $form['commands'] = array('#type' => 'textarea', '#title' => t('Default commands'), '#default_value' => $edit['commands'], '#description' => t('A set of commands which are added to each message. One command per line. See !link.', array('!link' => l(t('Commands'), 'admin/help/mailhandler#commands'))));
799    $form['sigseparator'] = array('#type' => 'textfield', '#title' => t('Signature separator'), '#default_value' => $edit['sigseparator'], '#description' => t('All text after this string will be discarded. A typical value is <strong>"-- "</strong> that is two dashes followed by a blank in an otherwise empty line. Leave blank to include signature text in nodes.'));    $form['sigseparator'] = array('#type' => 'textfield', '#title' => t('Signature separator'), '#default_value' => $edit['sigseparator'], '#description' => t('All text after this string will be discarded. A typical value is <strong>"-- "</strong> that is two dashes followed by a blank in an otherwise empty line. Leave blank to include signature text in nodes.'));
800    $form['delete_after_read'] = array('#type' => 'checkbox', '#title' => t('Delete messages after they are processed?'), '#default_value' => $edit['delete_after_read'], '#description' => t('Uncheck this box to leave read messages in the mailbox. They will not be processed again unless they become marked as unread.'));    $form['delete_after_read'] = array('#type' => 'checkbox', '#title' => t('Delete messages after they are processed?'), '#default_value' => $edit['delete_after_read'], '#description' => t('Uncheck this box to leave read messages in the mailbox. They will not be processed again unless they become marked as unread.'));
801    $form['enabled'] = array('#type' => 'radios', '#title' => t('Cron processing'), '#options' => array(t('Disabled'), t('Enabled')), '#default_value' => $edit['enabled'], '#description' => t('Select disable to temporarily stop cron processing for this mailbox.'));    $form['enabled'] = array('#type' => 'radios', '#title' => t('Cron processing'), '#options' => array(t('Disabled'), t('Enabled')), '#default_value' => $edit['enabled'], '#description' => t('Select disable to temporarily stop cron processing for this mailbox.'));
# Line 859  function mailhandler_help($section = 'ad Line 887  function mailhandler_help($section = 'ad
887    $output = '';    $output = '';
888    $link->add = l(t('Add mailbox'), 'admin/content/mailhandler/add');    $link->add = l(t('Add mailbox'), 'admin/content/mailhandler/add');
889    
890      // Gather examples of useful commands, and build a definition list with them:
891      $commands[] = array('command' => 'taxonomy: [term1, term2]',
892                          'description' => t('Use this to add the terms <em>term1</em> and <em>term2</em> to the node.<br />
893                          Both of the terms should already exist. In case they do not exist already, they will be quietly ommitted'));
894      $commands[] = array('command' => 'taxonomy[v]: [term1, term2]',
895                          '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 />
896                          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'));
897    
898      $commands_list = '<dl>';
899      foreach ($commands as $command) {
900        $commands_list .= '<dt>'. $command['command'] .'</dt>';
901        $commands_list .= '<dl>'. $command['description'] .'</dl>';
902      }
903      $commands_list .= '</dl>';
904    
905    switch ($section) {    switch ($section) {
906      case 'admin/help#mailhandler':      case 'admin/help#mailhandler':
907        $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>';        $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>';
# Line 871  function mailhandler_help($section = 'ad Line 914  function mailhandler_help($section = 'ad
914  <li>administer mailhandler at <a href="@admin-mailhandler">administer &gt;&gt; mailhandler</a>.</li>  <li>administer mailhandler at <a href="@admin-mailhandler">administer &gt;&gt; mailhandler</a>.</li>
915  <li>set default commands, (password, type, taxonomy, promote, status), for how to work with incoming mail at <a href="%admin-mailhandler">admin >> mailhandler</a> select <strong>edit</strong> for the email address being handled.  Set commands in the default command field.</li>  <li>set default commands, (password, type, taxonomy, promote, status), for how to work with incoming mail at <a href="%admin-mailhandler">admin >> mailhandler</a> select <strong>edit</strong> for the email address being handled.  Set commands in the default command field.</li>
916  <li>post email, such as from a mailing list, to a forum by adding the term id (number found in the URL) to the default commands using <strong>tid: #</strong>.', array('@admin-mailhandler-add' => url('admin/content/mailhandler/add'), '@admin-mailhandler' => url('admin/content/mailhandler'))) .'</ul>';  <li>post email, such as from a mailing list, to a forum by adding the term id (number found in the URL) to the default commands using <strong>tid: #</strong>.', array('@admin-mailhandler-add' => url('admin/content/mailhandler/add'), '@admin-mailhandler' => url('admin/content/mailhandler'))) .'</ul>';
917          $output .= '<h3 id="commands">'. t('Useful Commands') .'</h3>';
918          $output .= $commands_list;
919        $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>';        $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>';
920        return $output;        return $output;
921      case 'admin/content/mailhandler':      case 'admin/content/mailhandler':

Legend:
Removed from v.1.87.2.14  
changed lines
  Added in v.1.87.2.15

  ViewVC Help
Powered by ViewVC 1.1.2