/[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, Thu Feb 1 05:34:50 2007 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.86 2006/08/08 23:01:24 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 32  function mailhandler_retrieve($mailbox) Line 32  function mailhandler_retrieve($mailbox)
32          continue;          continue;
33        }        }
34    
35        $mime = explode(',', variable_get('mime', 'TEXT/HTML,TEXT/PLAIN'));        $mime = explode(',', $mailbox['mime']);
36    
37          // Get the first text part - this will be the node body
38        $origbody = mailhandler_get_part($result, $i, $mime[0]);        $origbody = mailhandler_get_part($result, $i, $mime[0]);
39    
40          // If we didn't get a body from our first attempt, try the alternate format (HTML or PLAIN)
41        if (!$origbody) {        if (!$origbody) {
42          $origbody = mailhandler_get_part($result, $i, $mime[1]);          $origbody = mailhandler_get_part($result, $i, $mime[1]);
43          if (!$origbody) {        }
44            // @TODO: Log that we got an empty email?  
45            continue;        // Parse MIME parts, so all mailhandler modules have access to
46          }        // the full array of mime parts without having to process the email.
47          $mimeparts = mailhandler_get_parts($result, $i);
48    
49          // Is this an empty message with no body and no mimeparts?
50          if (!$origbody && !$mimeparts) {
51            // @TODO: Log that we got an empty email?
52            continue;
53        }        }
54    
55        $num_processed++;        $num_processed++;
# Line 50  function mailhandler_retrieve($mailbox) Line 60  function mailhandler_retrieve($mailbox)
60        // check if mail originates from an authenticated user        // check if mail originates from an authenticated user
61        $node = mailhandler_authenticate($node, $header, $origbody, $mailbox);        $node = mailhandler_authenticate($node, $header, $origbody, $mailbox);
62    
63          // Put $mimeparts on the node
64          $node->mimeparts = $mimeparts;
65    
66        // we need to change the current user        // we need to change the current user
67        // this has to be done here to allow modules        // this has to be done here to allow modules
68        // to create users        // to create users
# Line 87  function mailhandler_retrieve($mailbox) Line 100  function mailhandler_retrieve($mailbox)
100    }    }
101    else {    else {
102      if ($err) {      if ($err) {
103        watchdog('error', t('Mailhandler %c connection failed: %m', array('%c' => ($mailbox['imap'] ? 'imap' : 'POP3'), '%m' => $mailbox['mail'])));        watchdog('mailhandler', t('Mailhandler %c connection failed: %m', array('%c' => ($mailbox['imap'] ? 'imap' : 'POP3'), '%m' => $mailbox['mail'])), WATCHDOG_ERROR);
104        return t('Mailhandler %c connection failed: %m', array('%c' => ($mailbox['imap'] ? 'imap' : 'POP3'), '%m' => $mailbox['mail']));        return t('Mailhandler %c connection failed: %m', array('%c' => ($mailbox['imap'] ? 'imap' : 'POP3'), '%m' => $mailbox['mail']));
105      }      }
106      else {      else {
107        watchdog('error', t('Mailhandler: Could not access local folder: %m', array('%m' => $mailbox['mail'])));        watchdog('mailhandler', t('Mailhandler: Could not access local folder: %m', array('%m' => $mailbox['mail'])), WATCHDOG_ERROR);
108        return t('Mailhandler could not access local folder: %m', array('%m' => $mailbox['mail']));        return t('Mailhandler could not access local folder: %m', array('%m' => $mailbox['mail']));
109      }      }
110    }    }
# Line 114  function mailhandler_comment_submit($nod Line 127  function mailhandler_comment_submit($nod
127      list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox);      list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox);
128      $error_txt = t("Sorry, your comment experienced an error and was not posted. Possible reasons are\n- you have insufficient permission to post comments\n- The node is no longer open for comments.\n\n");      $error_txt = t("Sorry, your comment experienced an error and was not posted. Possible reasons are\n- you have insufficient permission to post comments\n- The node is no longer open for comments.\n\n");
129      $error = $error_txt. t("\n\nYou sent:\n\nFrom: %f\nSubject: %t\nBody:\n%b", array('%f' => $fromaddress, '%t' => $header->subject, '%b' => $origbody));      $error = $error_txt. t("\n\nYou sent:\n\nFrom: %f\nSubject: %t\nBody:\n%b", array('%f' => $fromaddress, '%t' => $header->subject, '%b' => $origbody));
130      $sitemail = variable_get('site_mail', ini_get('sendmail_from'));      drupal_mail('mailhandler_error_comment', $fromaddress, t('Email submission to %sn failed - %subj', array('%sn' => variable_get('site_name', 'Drupal'), '%subj' => $header->subject)));
     $headers = "From: $sitemail\nReply-to: $sitemail\nX-Mailer: Drupal\nReturn-path: $sitemail\nErrors-to: $sitemail";  
     drupal_mail($fromaddress, t('Email submission to %sn failed - %subj', array('%sn' => variable_get('site_name', 'Drupal'), '%subj' => $header->subject)), $error, $headers);  
131      $watchdog = t('Mailhandler: comment submission failure: %subject.', array('%subject' => $edit['subject']));      $watchdog = t('Mailhandler: comment submission failure: %subject.', array('%subject' => $edit['subject']));
132      watchdog('error', $watchdog);      watchdog('mailhandler', $watchdog, WATCHDOG_ERROR);
133    }    }
134  }  }
135    
# Line 138  function mailhandler_node_submit($node, Line 149  function mailhandler_node_submit($node,
149    list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox);    list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox);
150    
151    //dprint_r($node); //DEBUG    //dprint_r($node); //DEBUG
152    
153      // Drupal 5.x & 6.x don't support multiple validations: each node_validate()
154      // call will ADD error messages to previous ones, so if some validation error
155      // occours in one message it will be reported in all messages after it.
156      // Since there is no way to reset form errors, the only method to avoid this
157      // problem is working with $_SESSION['messages'], used by form_set_error().
158      // See http://drupal.org/node/271975 for more info.
159      // Warning: with this method, if the same error message is reported for 2+ different
160      // fields it will be detected only for the last one.
161      if (!isset($_SESSION['messages'])) {
162        $_SESSION['messages'] = array();
163      }
164      $saved_errors = is_array($_SESSION['messages']['error']) ? $_SESSION['messages']['error'] : array();
165      $_SESSION['messages']['error'] = array();
166    node_validate($node);    node_validate($node);
167    $error = form_get_errors();    $error = array();
168      if (count($_SESSION['messages']['error'])) {
169        $allerrors = form_get_errors();
170        foreach ($_SESSION['messages']['error'] as $message) {
171          $keys = array_keys($allerrors, $message);
172          if (!$keys || !count($keys)) {
173            // Not a validation error (but an error, i'll print it)
174            $saved_errors[] = $message;
175          } else {
176            // This is a validation error, i take the last field with it (previous fields
177            // should be about previous validations)
178            $error[$keys[count($keys) - 1]] = $message;
179          }
180        }
181      }
182      if (is_array($saved_errors) && count($saved_errors)) {
183        $_SESSION['messages']['error'] = $saved_errors;
184      }
185      else {
186        unset($_SESSION['messages']['error']);
187      }
188    
189    if (!$error) {    if (!$error) {
190      // Prepare the node for save and allow modules make changes      // Prepare the node for save and allow modules make changes
191      $node = node_submit($node);      $node = node_submit($node);
# Line 148  function mailhandler_node_submit($node, Line 193  function mailhandler_node_submit($node,
193      if ($node->nid) {      if ($node->nid) {
194        if (node_access('update', $node)) {        if (node_access('update', $node)) {
195          node_save($node);          node_save($node);
196          watchdog('special', t("Mailhandler: Updated '%t' by %f", array('%t' => $node->title, '%f' => $fromaddress)));          watchdog('mailhandler', t("Mailhandler: Updated '%t' by %f", array('%t' => $node->title, '%f' => $fromaddress)), WATCHDOG_NOTICE);
197        }        }
198        else {        else {
199          $errortxt = t("The e-mail address '%f' may not update %t items.", array('%f' => $fromaddress, '%t' => $node->type));          $errortxt = t("The e-mail address '%f' may not update %t items.", array('%f' => $fromaddress, '%t' => $node->type));
# Line 157  function mailhandler_node_submit($node, Line 202  function mailhandler_node_submit($node,
202      else {      else {
203        if (node_access('create', $node)) {        if (node_access('create', $node)) {
204          node_save($node);          node_save($node);
205          watchdog('special', t("Mailhandler: Added '%t' by %f", array('%t' => $node->title, '%f' => $fromaddress)));          watchdog('mailhandler', t("Mailhandler: Added '%t' by %f", array('%t' => $node->title, '%f' => $fromaddress)), WATCHDOG_NOTICE);
206        }        }
207        else {        else {
208          $errortxt = t("The e-mail address '%f' may not create %t items.", array('%f' => $fromaddress, '%t' => $node->type));          $errortxt = t("The e-mail address '%f' may not create %t items.", array('%f' => $fromaddress, '%t' => $node->type));
# Line 172  function mailhandler_node_submit($node, Line 217  function mailhandler_node_submit($node,
217    }    }
218    
219    if ($errortxt) {    if ($errortxt) {
220      watchdog('error', "Mailhandler: $errortxt");      watchdog('mailhandler', "Mailhandler: $errortxt", WATCHDOG_ERROR);
221      if ($mailbox['replies']) {      if ($mailbox['replies']) {
222        $errortxt .= t("\n\nYou sent:\n\nFrom: %f\nSubject: %t\nBody:\n%b", array('%f' => $fromaddress, '%t' => $header->subject, '%b' => $origbody));        $errortxt .= t("\n\nYou sent:\n\nFrom: %f\nSubject: %t\nBody:\n%b", array('%f' => $fromaddress, '%t' => $header->subject, '%b' => $origbody));
223        $sitemail = variable_get('site_mail', ini_get('sendmail_from'));        drupal_mail('mailhandler_error_node', $fromaddress, t('Email submission to %sn failed - %subj', array('%sn' => variable_get('site_name', 'Drupal'), '%subj' => $node->title)), $errortxt);
       $headers = "From: $sitemail\nReply-to: $sitemail\nX-Mailer: Drupal\nReturn-path: $sitemail\nErrors-to: $sitemail";  
       drupal_mail($fromaddress, t('Email submission to %sn failed - %subj', array('%sn' => variable_get('site_name', 'Drupal'), '%subj' => $node->title)), $errortxt, $headers);  
224      }      }
225    }    }
226  }  }
# Line 216  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 236  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])) {
312            $node->$data[0] = $data[1];
313        }        }
       $node->$data[0] = $data[1];  
314      }      }
315      else {      else {
316        if (is_null($endcommands)) $endcommands = $i;        if (is_null($endcommands)) $endcommands = $i;
# Line 256  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 325  function mailhandler_switch_user($uid = Line 398  function mailhandler_switch_user($uid =
398    static $orig_user = array();    static $orig_user = array();
399    
400    if (isset($uid)) {    if (isset($uid)) {
401        session_save_session(FALSE);
402      $user = user_load(array('uid' => $uid));      $user = user_load(array('uid' => $uid));
403    }    }
404    // retrieve the initial user, can be called multiple times    // retrieve the initial user, can be called multiple times
405    else if (count($orig_user)) {    else if (count($orig_user)) {
406      $user = array_shift($orig_user);      $user = array_shift($orig_user);
407        session_save_session(TRUE);
408      array_unshift($orig_user, $user);      array_unshift($orig_user, $user);
409    }    }
410    // store the initial user    // store the initial user
# Line 387  function mailhandler_get_part($stream, $ Line 462  function mailhandler_get_part($stream, $
462          $part_number = '1';          $part_number = '1';
463        }        }
464        $text = imap_fetchbody($stream, $msg_number, $part_number);        $text = imap_fetchbody($stream, $msg_number, $part_number);
465        if ($structure->encoding == 3) {        if ($structure->encoding == ENCBASE64) {
466          return drupal_convert_to_utf8(imap_base64($text), $encoding);          return drupal_convert_to_utf8(imap_base64($text), $encoding);
467        }        }
468        else if ($structure->encoding == 4) {        else if ($structure->encoding == ENCQUOTEDPRINTABLE) {
469          return drupal_convert_to_utf8(quoted_printable_decode($text), $encoding);          return drupal_convert_to_utf8(quoted_printable_decode($text), $encoding);
470        }        }
471        else {        else {
472          return drupal_convert_to_utf8($text, $encoding);          return drupal_convert_to_utf8($text, $encoding);
473        }        }
474      }      }
475      if ($structure->type == 1) { /* multipart */      if ($structure->type == TYPEMULTIPART) { /* multipart */
476        while (list($index, $sub_structure) = each ($structure->parts)) {        while (list($index, $sub_structure) = each ($structure->parts)) {
477          if ($part_number) {          if ($part_number) {
478            $prefix = $part_number .'.';            $prefix = $part_number .'.';
# Line 413  function mailhandler_get_part($stream, $ Line 488  function mailhandler_get_part($stream, $
488    return false;    return false;
489  }  }
490    
491    
492    /**
493     * Returns an array of parts as file objects
494     *
495     * @param
496     * @param $structure
497     *   A message structure, usually used to recurse into specific parts
498     * @param $max_depth
499     *   Maximum Depth to recurse into parts.
500     * @param $depth
501     *   The current recursion depth.
502     * @param $part_number
503     *   A message part number to track position in a message during recursion.
504     * @return
505     *   An array of file objects.
506     */
507    function mailhandler_get_parts($stream, $msg_number, $max_depth = 10, $depth = 0, $structure = FALSE, $part_number = FALSE) {
508      $parts = array();
509    
510      // Load Structure.
511      if (!$structure && !$structure = imap_fetchstructure($stream, $msg_number)) {
512        watchdog('mailhandler', t('Could not fetch structure for message number %msg_number', array('%msg_number' => $msg_number)), WATCHDOG_NOTICE);
513        return $parts;
514      }
515    
516      // Recurse into multipart messages.
517      if ($structure->type == TYPEMULTIPART) {
518        // Restrict recursion depth.
519        if ($depth >= $max_depth) {
520          watchdog('mailhandler', t('Maximum recursion depths met in mailhander_get_structure_part for
521                      message number %msg_number.',  array('%msg_number' => $msg_number)), WATCHDOG_NOTICE);
522          return $parts;
523        }
524        foreach($structure->parts as $index => $sub_structure) {
525          // If a part number was passed in and we are a multitype message, prefix the
526          // the part number for the recursive call to match the imap4 dot seperated part indexing.
527          if ($part_number) {
528            $prefix = $part_number .'.';
529          }
530          $sub_parts =  mailhandler_get_parts($stream, $msg_number, $max_depth, $depth + 1,
531            $sub_structure, $prefix . ($index + 1));
532          $parts = array_merge($parts, $sub_parts);
533        }
534        return $parts;
535      }
536    
537      // Per Part Parsing.
538    
539      // Initalize file object like part structure.
540      $part = new StdClass();
541      $part->attributes = array();
542      $part->filename = 'unnamed_attachment';
543      if (!$part->filemime = mailhandler_get_mime_type($structure)) {
544        watchdog('mailhandler', t('Could not fetch mime type for message part. Defaulting to application/octet-stream.'),
545          WATCHDOG_NOTICE);
546        $part->filemime = 'application/octet-stream';
547      }
548    
549      if ($structure->ifparameters) {
550        foreach ($structure->parameters as $parameter) {
551          switch (strtoupper($parameter->attribute)) {
552            case 'NAME':
553            case 'FILENAME':
554              $part->filename = $parameter->value;
555              break;
556            default:
557              // put every thing else in the attributes array;
558              $part->attributes[$parameter->attribute] = $parameter->value;
559          }
560        }
561      }
562    
563      // Handle Content-Disposition parameters for non-text types.
564      if ($structure->type != TYPETEXT && $structure->ifdparameters) {
565        foreach ($structure->dparameters as $parameter) {
566          switch (strtoupper($parameter->attribute)) {
567            case 'NAME':
568            case 'FILENAME':
569              $part->filename = $parameter->value;
570              break;
571            // put every thing else in the attributes array;
572            default:
573              $part->attributes[$parameter->attribute] = $parameter->value;
574          }
575        }
576      }
577    
578      // Retrieve part  convert MIME encoding to UTF-8
579      if(!$part->data = imap_fetchbody($stream, $msg_number, $part_number)) {
580        drupal_set_message("imap_fetchbody($stream, $msg_number, $part_number)");
581        watchdog('mailhandler', 'No Data!!', WATCHDOG_ERROR);
582        return $parts;
583      }
584    
585      // convert text attachment to UTF-8.
586      if ($structure->type == TYPETEXT) {
587        $part->data = imap_utf8($part->data);
588      }
589      else {
590        // If not text then decode as necessary
591        if ($structure->encoding == ENCBASE64) {
592          $part->data = imap_base64($part->data);
593        }
594        else if ($structure->encoding == ENCQUOTEDPRINTABLE) {
595          $part->data = quoted_printable_decode($part->data);
596        }
597      }
598    
599      //always return an array to satisfy array_merge in recursion catch, and array return value.
600      $parts[] = $part;
601      return $parts;
602    }
603    
604  /**  /**
605   * Retrieve MIME type of the message structure.   * Retrieve MIME type of the message structure.
606   */   */
# Line 427  function mailhandler_get_mime_type(&$str Line 615  function mailhandler_get_mime_type(&$str
615    
616  /**  /**
617   * Implementation of hook_user().   * Implementation of hook_user().
618   */   *
619     * Commented out because mailhandler cannot assume that this mailbox will
620     * accept blog entries from users.
621    */
622    /*
623  function mailhandler_user($type, &$edit, &$account, $category = NULL) {  function mailhandler_user($type, &$edit, &$account, $category = NULL) {
624    if ($type == 'view') {    if ($type == 'view') {
625      // @TODO: We may add a new option in mailboxes to choose which roles can post.      // @TODO: We may add a new option in mailboxes to choose which roles can post.
# Line 452  function mailhandler_user($type, &$edit, Line 644  function mailhandler_user($type, &$edit,
644      }      }
645    }    }
646  }  }
647    */
648    
649  /**  /**
650   * Implementation of hook_cron(). Process msgs from all enabled mailboxes.   * Implementation of hook_cron(). Process msgs from all enabled mailboxes.
# Line 484  function mailhandler_menu($may_cache) { Line 677  function mailhandler_menu($may_cache) {
677    if ($may_cache) {    if ($may_cache) {
678      $items[] = array('path' => 'admin/content/mailhandler', 'title' => t('Mailhandler'),      $items[] = array('path' => 'admin/content/mailhandler', 'title' => t('Mailhandler'),
679        'callback' => 'mailhandler_admin',        'callback' => 'mailhandler_admin',
680          'description' => t('Manage mailboxes and retrieve messages.'),
681        'access' => $admin_access);        'access' => $admin_access);
682      $items[] = array('path' => 'admin/content/mailhandler/retrieve', 'title' => t('Retrieve'),      $items[] = array('path' => 'admin/content/mailhandler/retrieve', 'title' => t('Retrieve'),
683        'callback' => 'mailhandler_admin_retrieve',        'callback' => 'mailhandler_admin_retrieve',
# Line 590  function mailhandler_form($edit = array( Line 784  function mailhandler_form($edit = array(
784    $form['mailto'] = array('#type' => 'textfield', '#title' => t('Second E-mail address'), '#default_value' => $edit['mailto'], '#description' => t('Optional. The e-mail address to which modules should send generated content.'));    $form['mailto'] = array('#type' => 'textfield', '#title' => t('Second E-mail address'), '#default_value' => $edit['mailto'], '#description' => t('Optional. The e-mail address to which modules should send generated content.'));
785    $form['folder'] = array('#type' => 'textfield', '#title' => t('Folder'), '#default_value' => $edit['folder'], '#description' => t('Optional. The folder where the mail is stored. If you want this mailbox to read from a local folder, give the full path. Leave domain, port, name, and pass empty below. Remember to set the folder to readable and writable by the webserver.'));    $form['folder'] = array('#type' => 'textfield', '#title' => t('Folder'), '#default_value' => $edit['folder'], '#description' => t('Optional. The folder where the mail is stored. If you want this mailbox to read from a local folder, give the full path. Leave domain, port, name, and pass empty below. Remember to set the folder to readable and writable by the webserver.'));
786    $form['imap'] = array('#type' => 'select', '#title' => t('POP3 or IMAP Mailbox'), '#options' => array('POP3', 'IMAP'), '#default_value' => $edit['imap'], '#description' => t('If you wish to retrieve mail from a POP3 or IMAP mailbox instead of a Folder, select POP3 or IMAP. Also, complete the Mailbox items below.'));    $form['imap'] = array('#type' => 'select', '#title' => t('POP3 or IMAP Mailbox'), '#options' => array('POP3', 'IMAP'), '#default_value' => $edit['imap'], '#description' => t('If you wish to retrieve mail from a POP3 or IMAP mailbox instead of a Folder, select POP3 or IMAP. Also, complete the Mailbox items below.'));
787    $form['domain'] = array('#type' => 'textfield', '#title' => t('Mailbox domain'), '#default_value' => $edit['domain'], '#description' => t('The domain of the server used to collect mail.'), '#required' => TRUE);    $form['domain'] = array('#type' => 'textfield', '#title' => t('Mailbox domain'), '#default_value' => $edit['domain'], '#description' => t('The domain of the server used to collect mail.'));
788    $form['port'] = array('#type' => 'textfield', '#title' => t('Mailbox port'), '#size' => 5, '#maxlength' => 5, '#default_value' => $edit['port'], '#description' => t('The port of the mailbox used to collect mail (usually 110 for POP3, 143 for IMAP).'));    $form['port'] = array('#type' => 'textfield', '#title' => t('Mailbox port'), '#size' => 5, '#maxlength' => 5, '#default_value' => $edit['port'], '#description' => t('The port of the mailbox used to collect mail (usually 110 for POP3, 143 for IMAP).'));
789    $form['name'] = array('#type' => 'textfield', '#title' => t('Mailbox username'), '#default_value' => $edit['name'], '#description' => t('This username is used while logging into this mailbox during mail retrieval.'));    $form['name'] = array('#type' => 'textfield', '#title' => t('Mailbox username'), '#default_value' => $edit['name'], '#description' => t('This username is used while logging into this mailbox during mail retrieval.'));
790    $form['pass'] = array('#type' => 'textfield', '#title' => t('Mailbox password'), '#default_value' => $edit['pass'], '#description' => t('The password corresponding to the username above. Consider using a non-vital password, since this field is stored without encryption in the database.'));    $form['pass'] = array('#type' => 'textfield', '#title' => t('Mailbox password'), '#default_value' => $edit['pass'], '#description' => t('The password corresponding to the username above. Consider using a non-vital password, since this field is stored without encryption in the database.'));
# Line 601  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 681  function mailhandler_admin_delete_confir Line 875  function mailhandler_admin_delete_confir
875  function mailhandler_admin_delete_confirm_submit($form_id, $form_values) {  function mailhandler_admin_delete_confirm_submit($form_id, $form_values) {
876    $info = db_fetch_object(db_query("SELECT mid, mail FROM {mailhandler} WHERE mid = %d", $form_values['mid']));    $info = db_fetch_object(db_query("SELECT mid, mail FROM {mailhandler} WHERE mid = %d", $form_values['mid']));
877    db_query("DELETE FROM {mailhandler} WHERE mid = %d", $form_values['mid']);    db_query("DELETE FROM {mailhandler} WHERE mid = %d", $form_values['mid']);
878    watchdog('special', t('Mailhandler: Mailbox %mailbox deleted', array('%mailbox' => $info->mail)));    watchdog('mailhandler', t('Mailhandler: Mailbox %mailbox deleted', array('%mailbox' => $info->mail)), WATCHDOG_NOTICE);
879    drupal_set_message(t('Mailbox %mailbox deleted', array('%mailbox' => $info->mail)));    drupal_set_message(t('Mailbox %mailbox deleted', array('%mailbox' => $info->mail)));
880    drupal_goto('admin/content/mailhandler');    drupal_goto('admin/content/mailhandler');
881  }  }
# Line 693  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 705  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  
changed lines
  Added in v.1.87.2.15

  ViewVC Help
Powered by ViewVC 1.1.2