diff --git a/mail2og.module b/mail2og.module index c8ba36c..1f8d1b2 100644 --- a/mail2og.module +++ b/mail2og.module @@ -194,7 +194,7 @@ function mail2og_find_email_address($email, $cck_field = null) { // get the relevant database information for this field $db_info = content_database_info($field); // look for this email address in the correct col - $result = db_result(db_query('SELECT field.nid FROM '. $db_info['table'] .' field WHERE '. $db_info['columns']['value']['column'] .' = "%s"', $email)); + $result = db_result(db_query('SELECT field.nid FROM %s field WHERE %s = "%s"', $db_info['table'], $db_info['columns']['value']['column'], $email)); if ($result) { return node_load($result); } @@ -215,7 +215,7 @@ function mail2og_administration_form() { '#type' => 'select', '#multiple' => true, '#title' => t('Enable mail2og on'), - '#options' => array_merge(array(0 => t('No groups'), 1 => t('All groups')), og_all_groups_options()), + '#options' => array(0 => t('No groups'), 1 => t('All groups')) + og_all_groups_options(), '#default_value' => variable_get('mail2og_enabled_groups', 0), '#description' => t('Select the groups you want to enable mail2og on. Default is all') ); @@ -350,13 +350,38 @@ function mail2og_block_info() { * group. This uses the to address (to@domain.com) */ function mail2og_mailhandler(&$node, $result, $i, $header, $mailbox) { + + $email = $header->to[0]->mailbox . '@' . $header->to[0]->host; + + // Check if mailcomment exists + if (module_exists('mailcomment')) { + + // Cache the mailbox variables. I don't know if this is needed or not. + static $mailcomment_mailboxes = array(); + static $mailbox_list = array(); + // Set the variables if they haven't been set yet. + if (!isset($mailbox_list[0])) { + $mailcomment_mailboxes = variable_get('mailcomment_mailboxes', ''); + $mailbox_list = mailcomment_mailbox_list(); + } + + // Check whether the email matches any of the mailcomment mailboxes. + foreach ($mailcomment_mailboxes as $key) { + if ($email == $mailbox_list[$key]) { + // Return the unmodified email so that mailcomment can use it. + return $node; + } + } + } + + // If no groups are enabled, exit if (in_array(0, variable_get('mail2og_enabled_groups', array()))) { return; } // now we need to look for the emailbox name to see if it belongs to a group - if (! $group = mail2og_find_email_address($header->toaddress) ) { + if (! $group = mail2og_find_email_address($email) ) { return; } @@ -735,4 +760,4 @@ function theme_mail2og_block_display_email_info($group, $email) { $html = array(); $html[] = t('You can post to this group by sending an email to %email', array('%email' => $email)); return implode('
', $html); -} \ No newline at end of file +}