--- mailhandler.module.orig 2009-02-21 18:53:59.000000000 -0500 +++ mailhandler.module 2009-02-22 20:25:52.000000000 -0500 @@ -79,6 +79,15 @@ } } + if(empty($node->type)) { + // the default for this mailbox is not to submit nodes + // if no handlers have set the node type, and no handlers + // have set the have overridden this option, so we should not proceed + $msg = t('Mailhandler: node type is not set, not processing this message. Consider setting the default node type for this mailbox'); + watchdog('mailhandler', $msg); + return $msg; + } + if ($node) { if ($node->type == 'comment') { mailhandler_comment_submit($node, $header, $mailbox, $origbody); @@ -136,15 +145,14 @@ /** * Create the node. */ - // handle defaults for node creation (e.g. comment | promote | moderate | sticky fields) - $node_blog_default = variable_get('node_options_blog', array('status', 'promote')); - $node->status = in_array('status', $node_blog_default); - $node->promote = in_array('promote', $node_blog_default); - $node->moderate = in_array('moderate', $node_blog_default); - $node->revision = in_array('revision', $node_blog_default); - $node->comment = variable_get('comment_blog', 2); - function mailhandler_node_submit($node, $header, $mailbox, $origbody) { + // handle defaults for node creation (e.g. comment | promote | moderate | sticky fields) + $node_params_defaults = variable_get('node_options_' . $node->type, array('status', 'promote')); + $node->status = in_array('status', $node_params_defaults); + $node->promote = in_array('promote', $node_params_defaults); + $node->moderate = in_array('moderate', $node_params_defaults); + $node->revision = in_array('revision', $node_params_defaults); + $node->comment = variable_get('comment_' . $node->type, 2); list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox); @@ -260,7 +268,7 @@ } // We set the type now, because we need it in the next block - if (!$node->type) $node->type = 'blog'; + if (!$node->type) $node->type = $mailbox['default_node_type']; // Reset $node->taxonomy $node->taxonomy = array(); @@ -745,6 +753,10 @@ if (empty($edit['folder'])) { $edit['folder'] = 'INBOX'; } + // preserve backward compatability + if (empty($edit['default_node_type'])) { + $edit['default_node_type'] = 'blog'; + } $form['mail'] = array('#type' => 'textfield', '#title' => t('E-mail address'), '#default_value' => $edit['mail'], '#description' => t('The e-mail address to which users should send their submissions.'), '#required' => TRUE); $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.')); @@ -758,6 +770,7 @@ // Allow administrators to configure the mailbox with extra IMAP commands (notls, novalidate-cert etc.) $form['extraimap'] = array('#type' => 'textfield', '#title' => t('Extra commands'), '#default_value' => $edit['extraimap'], '#description' => t('Optional. In some circumstances you need to issue extra commands to connect to your mail server (e.g. "/notls", "/novalidate-cert" etc.). See documentation for imap_open. Begin the string with a "/", separating each subsequent command with another "/".')); $form['mime'] = array('#type' => 'select', '#title' => t('Mime preference'), '#options' => array('TEXT/HTML,TEXT/PLAIN' => 'HTML', 'TEXT/PLAIN,TEXT/HTML' => t('Plain text')), '#default_value' => $edit['mime'], '#description' => t('When a user sends an e-mail containing both HTML and plain text parts, use this part as the node body.')); + $form['default_node_type'] = array('#type' => 'select', '#title' => t('Default node type'), '#options' => mailhandler_get_node_type_options(), '#default_value' => $edit['default_node_type'], '#description' => t('When a message is processed and no mailhandler modules have set the node type, what node type should be used to create the node?')); $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['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['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 From header), but Sender is also useful when working with listservs.')); @@ -780,6 +793,15 @@ return $form; } +function mailhandler_get_node_type_options() { + $ret = array('' => t("Don't create node if no handler sets node type")); + $types = node_get_types(); + while(list(,$type) = each($types)) { + $ret[$type->type] = $type->name; + } + return $ret; +} + /** * Verify that the Mailbox is valid, and save it to the database. */ @@ -809,13 +831,13 @@ if ($edit['mid']) { // Includes fields to allow administrators to add extra IMAP commands, // and select the format of saved nodes/comments - db_query("UPDATE {mailhandler} SET mail = '%s', mailto = '%s', domain = '%s', port = %d, folder = '%s', name = '%s', pass = '%s', extraimap = '%s', mime = '%s', imap = '%s', security = %d, replies = %d, fromheader = '%s', commands = '%s', sigseparator = '%s', enabled = %d, delete_after_read = %d, format = %d WHERE mid = %d", $edit['mail'], $edit['mailto'], $edit['domain'], $edit['port'], $edit['folder'], $edit['name'], $edit['pass'], $edit['extraimap'], $edit['mime'], $edit['imap'], $edit['security'], $edit['replies'], $edit['fromheader'], $edit['commands'], $edit['sigseparator'], $edit['enabled'], $edit['delete_after_read'], $edit['format'], $edit['mid']); + db_query("UPDATE {mailhandler} SET mail = '%s', mailto = '%s', domain = '%s', port = %d, folder = '%s', name = '%s', pass = '%s', extraimap = '%s', mime = '%s', imap = '%s', security = %d, replies = %d, fromheader = '%s', commands = '%s', sigseparator = '%s', enabled = %d, delete_after_read = %d, format = %d, default_node_type = '%s' WHERE mid = %d", $edit['mail'], $edit['mailto'], $edit['domain'], $edit['port'], $edit['folder'], $edit['name'], $edit['pass'], $edit['extraimap'], $edit['mime'], $edit['imap'], $edit['security'], $edit['replies'], $edit['fromheader'], $edit['commands'], $edit['sigseparator'], $edit['enabled'], $edit['delete_after_read'], $edit['format'], $edit['default_node_type'], $edit['mid']); drupal_set_message(t('Mailbox updated')); } else { // Includes fields to allow administrators to add extra IMAP commands, // and select the format of saved nodes/comments - db_query("INSERT INTO {mailhandler} (mail, mailto, domain, port, folder, name, pass, extraimap, mime, imap, security, replies, fromheader, commands, sigseparator, enabled, delete_after_read, format) VALUES ('%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', %d, %d, %d)", $edit['mail'], $edit['mailto'], $edit['domain'], $edit['port'], $edit['folder'], $edit['name'], $edit['pass'], $edit['extraimap'], $edit['mime'], $edit['imap'], $edit['security'], $edit['replies'], $edit['fromheader'], $edit['commands'], $edit['sigseparator'], $edit['enabled'], $edit['delete_after_read'], $edit['format']); + db_query("INSERT INTO {mailhandler} (mail, mailto, domain, port, folder, name, pass, extraimap, mime, imap, security, replies, fromheader, commands, sigseparator, enabled, delete_after_read, format) VALUES ('%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s')", $edit['mail'], $edit['mailto'], $edit['domain'], $edit['port'], $edit['folder'], $edit['name'], $edit['pass'], $edit['extraimap'], $edit['mime'], $edit['imap'], $edit['security'], $edit['replies'], $edit['fromheader'], $edit['commands'], $edit['sigseparator'], $edit['enabled'], $edit['delete_after_read'], $edit['format'], $edit['default_node_type']); drupal_set_message(t('Mailbox added')); } return 'admin/content/mailhandler';