I get the error: Fatal error: [] operator not supported for strings on line 271, and here is a patch to avoid that.

Patch is against DRUPAL-6--1.

Comments

s.daniel’s picture

I'll test the patch as I have the same problem but not tonight so just tracking plus a link to what seems to be a dup: http://drupal.org/node/287613

s.daniel’s picture

Status: Needs review » Reviewed & tested by the community

Tested as working. Can't say much about what exactly the change does though only so much - it fixes the problem.

dries’s picture

Before I commit this patch, I'd like to understand how I can reproduce this and why $message['body'] is not always an array. Can you try to reproduce this problem and do some digging? Ideally, I'd want to write a test case for this.

s.daniel’s picture

Couldn't quickly reproduce the error.
I started with a fresh Acquia Drupal install on the same cheap hosting envoirenment at 1&1 activated Mollum and entered the same keys as on the site the error was appearing before the patch (Hope I was allowed to do so). I have a couple of contrib modules enabled on the site but not the time right now to test one by one (simpletest yeah! ;) - I'll do further tests over the weekend if neccecary, however if someone could point me to a module to test first that might save some time.

These are the modules I have Installed currently

AktuellOK
Backup and Migrate 6.x-1.0
Außerdem verfügbar: 6.x-2.x-dev (2008-Sep-29)

* Herunterladen
* Anmerkungen zur Veröffentlichung

Beinhaltet: Backup and Migrate
AktuellOK
CAPTCHA 6.x-1.0-rc2
Beinhaltet: CAPTCHA, Image CAPTCHA
AktuellOK
Devel 6.x-1.12
Beinhaltet: Devel, Devel node access
AktuellOK
Internationalization 6.x-1.0-beta6
Beinhaltet: Profile translation, String translation
AktuellOK
Javascript Tools 6.x-1.0
Beinhaltet: Javascript tools
AktuellOK
CAPTCHA Pack 6.x-1.0-beta2
Beinhaltet: Math CAPTCHA
AktuellOK
Menu block 6.x-2.1
Beinhaltet: Menu Block
AktuellOK
Rules 6.x-1.0-beta3
Beinhaltet: Rules, Rules Scheduler
AktuellOK
Simplenews 6.x-1.0-beta5
Beinhaltet: Simplenews, Simplenews action
Keine verfügbaren Veröffentlichungen gefundenWarnung
simplenews_register 6.x-1.x-dev (2008-Jul-15)
Beinhaltet: Simplenews on register
AktuellOK
jQuery UI Tabs 6.x-1.0
Beinhaltet: Tabs
Aktualisierung verfügbarWarnung
AJAX Forms 6.x-1.3
Empfohlene Version: 6.x-1.4 (2008-Dez-12)

* Herunterladen
* Anmerkungen zur Veröffentlichung

Beinhaltet: ZZZZ AJAX Forms
Powered by Drupal, einem Open-Source Content-Management-System.

edit: The error appeared when someone tryed to register a new user. The user was created but no email was sent.

kbahey’s picture

In my case it was regular community Drupal, and I think it was in conjunction with an older version of the comment_notify module (which had an overhaul since then) or the notify module (which I had uninstalled since then).

I think it was trying to send the email out that one of these modules sends.

dries’s picture

The Mollom module doesn't have tests for the contact form, I believe. A good starting point would be to help write tests for the contact form. Once we have the tests, we can run them on sites that have all these additional modules installed or that can reproduce the problem.

domesticat’s picture

One of my users is reporting getting this error when she posts a comment. I'm guessing it's the firing out of tokenized emails due to comment_subscribe, etc. I haven't applied the patch yet. Let me know what I can do to help test.

SimonVlc’s picture

Same problem here, I think that in combination with the comment subscribe module.

Testing the patch. Thanks for it, Simon ;).

domesticat’s picture

Patch works for me.

gondwanan’s picture

I'm getting this on registration with Mollom 6.x-1.6 and Drupal 6.8

- I don't have comment_notify installed.

fumbling’s picture

I just got this when posting a comment:

Fatal error: [] operator not supported for strings in /var/www/html/sites/all/modules/mollom/mollom.module on line 271

I had just made a few changes to the settings for the Notifications module, and I have no idea if that's a coincidence or if it's related. I'll try the patch as soon as I can. Thanks.

fumbling’s picture

As a quick follow up, is this patch still valid for Drupal 6.9 and Mollom 6.x-1.7? Forgive me if that's a newbie question...

dries’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

@fumbling, I don't know because I have not been able to reproduce this problem. I'm guessing that this is a bug in another module that negatively impacts Mollom. In absence of a bug report with clear steps as how to reproduce this problem starting from a clean Drupal 6 install, I'd appreciate any help debugging this. I'm marking this issue 'needs more info'.

aztechnetworks’s picture

I have the same issue when a user enters a comment.

I also have comment_subscribe module in use.

I will test the patch now.

Using latest versions of Mollom and comments_subscribe.

dries’s picture

I spent some time looking at the comment_subscribe module but they don't implement the mail_alter hook. It seems like that module is not to blame. Can you grep your site's source code tree for 'mail_alter' (or 'alter_mail')?

mactoph’s picture

I'm getting the same error:
Fatal error: [] operator not supported for strings in /home/.fret/nrcpadmin/nrcpara.org/sites/all/modules/mollom/mollom.module on line 271

I don't have comment_subscribe installed, but I do have Watcher. I did a search for 'mail_alter' and 'alter_mail' in all of the modules I have installed and didn't find anything?

dave reid’s picture

Version: 6.x-1.6 » 6.x-1.x-dev
Assigned: Unassigned » dave reid
Status: Postponed (maintainer needs more info) » Active

I'm pretty sure the problem at hand is that modules can either pass an array or a string as a mail 'body' to drupal_mail(). Watcher and comment_subscribe use a string instead of an array.

function _watcher_email_notifications_send_message($qmsg) {
...
  // Body
  $body = html_entity_decode(strip_tags(filter_xss($qmsg->message)), ENT_QUOTES);
...
  $params['body'] = $body;
...
  // Send email
  $message = drupal_mail('watcher', 'notification', $to, $language, $params, $from, true);

Note that the message body doesn't 'officially' become an array until after mail_alter calls are finished (see drupal_mail):

  // Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
  drupal_alter('mail', $message);

  // Concatenate and wrap the e-mail body.
  $message['body'] = is_array($message['body']) ? drupal_wrap_mail(implode("\n\n", $message['body'])) : drupal_wrap_mail($message['body']);

Since neither an array or a string is the 'official' way to send the mail body (although all core examples use arrays), we can just rework mollom_mail_alter to be a little more flexible.

mollom_mail_alter(&$message) {
  if (isset($GLOBALS['mollom_response']) && isset($GLOBALS['mollom_response']['session_id'])) {
    $report_link = t('Report as inappropriate: @link', array('@link' => url('mollom/contact/'. $GLOBALS['mollom_response']['session_id'], array('absolute' => TRUE))));
    if (is_array($message['body'])) {
      $message['body'][] = $report_link;
    }
    else {
      $message['body'] .= "\n\n". $report_link;
    }
  }
}
dave reid’s picture

Status: Active » Needs review
StatusFileSize
new1.05 KB
lastnico’s picture

This error could appear using the comment_subscribe module.

The patch from http://drupal.org/node/331960#comment-1428512 is valid and works for me. Please apply it.

dries’s picture

Looks good to me. Dave, could you add some code comments to explain that the hook takes book an array and a string. It is a bit awkward so I think it is worth documenting. Thanks!

dries’s picture

Status: Needs review » Needs work

Added a code comment myself and committed it to DRUPAL-6. Thanks!

I think we should fix this in Drupal 7 so I'm marking this 'needs work' until we created a core issue for it.

dave reid’s picture

Status: Needs work » Fixed

Created core issue #448908: Only allow $message['body'] to be an array in drupal_mail() / hook_mail_alter() for fixing this issue in core. Now marking this issue as fixed.

seaneffel’s picture

Status: Fixed » Needs review

I can turn up some more information. I'm using OG 6.x-1.3, Notifications 6.x-2.0 and Mollom 6.x-1.7 together.

I have a long chain of errors for each time a user submits content to an OG group. In my use case, users can only be subscribed to new content published in OG groups. The Drupal error log around the time of each of these postings started with these messages.

When a user submits a node, this is the sequence of log/client errors:

Ham: <p>This is the third test of the Mollom problem. Lets see if it breaks when I submit this blog.</p>
Column &#039;field_video_embed_0_value&#039; cannot be null query: INSERT INTO content_type_blog (vid, nid, field_video_embed_0_embed, field_video_embed_0_value, field_video_embed_0_provider, field_video_embed_0_data) VALUES (17626, 17625, NULL, NULL, NULL, &#039;N;&#039;) in /home/cctvcamb/public_html/sites/all/modules/cck/content.module on line 1207.

Then the node is submitted and this message is displayed to the user:

Fatal error: [] operator not supported for strings in /home/cctvcamb/public_html/sites/all/modules/mollom/mollom.module on line 271

The error log turns up this entry:

include_once(./sites/all/modules/mollom/mollom.module) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in /home/cctvcamb/public_html/includes/bootstrap.inc on line 611.

And then this one.

include_once() [<a href='function.include'>function.include</a>]: Failed opening './sites/all/modules/mollom/mollom.module' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cctvcamb/public_html/includes/bootstrap.inc on line 611.

Then then there is an error for each outgoing notification (one for each subscribed user):

array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The first argument should be either a string or an integer in /home/cctvcamb/public_html/sites/all/modules/notifications/notifications.module on line 761.
implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in /home/cctvcamb/public_html/sites/all/modules/notifications/notifications.module on line 1432.

The notifications do get delivered.

After running the patch above from Dave, at least the Mollom errors are not happening anymore. Does this patch need to consider any of the other details I listed from Notifications and CCK errors?

dave reid’s picture

Status: Needs review » Fixed

This has already been fixed in the latest 6.x-1.x-dev version of Mollom. The other bugs are only related to the other modules, so you'll want to file separate patches for those modules.

seaneffel’s picture

OK, so Dries committed the patch #18 but there isn't any newer version of the Mollom module. I'm confused, is the fix in the module or is the fix in core?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jwilson3’s picture

I've hit this bug also. Is there no way a stable release can be cut that includes this fix?

Or at least the final patch file provided here for those that don't want to move to dev branch?

Doh, me and my big mouth. I figured my code was uptodate but it wasnt... I upped to the latest version 6.x-1.9. sorry, i'll shutup now.