When the mailmime module is installed and drush is run mailmime_init is called which checks dependencies and always throws an error and deactivates the module even though all the dependencies are setup and working. This may be due to permissions and users, I am not sure. There is a super quick and easy fix though, preventing the module disabling code from running during drush:

//if not in drush
if (!function_exists('drush_main')) {

}

Comments

DrCord’s picture

I have made a patch, it is attached. The patch is only a 3 line addition, but due to formatting the code the if statement wraps with proper indenting, the patch looks more complicated than it is, like the entire file was changed...

salvis’s picture

Version: 7.x-2.18 » 7.x-2.x-dev
Status: Active » Needs review

Thank you for the analysis and patch!

Something is wrong with the patch -- it wants to replace the entire file, not just the if. Maybe it's because you changed the file mode?

diff --git a/mailmime.module b/mailmime.module
old mode 100644
new mode 100755

Let's see what the testbot says. Patches need to go against HEAD, i.e. the -dev version.

While you're at it, please make your comment conform to the coding guidelines (space, initial cap, ending dot).

Status: Needs review » Needs work
DrCord’s picture

Here is a new patch that I made sure the file permissions were the same, cleaned up my comment and such...I think the reason it is marking the file as having tons of replaced lines is the indentation from wrapping blocks the "if" statements...

salvis’s picture

Status: Needs work » Needs review

Please set NR to trigger the testbot.

salvis’s picture

Status: Needs review » Needs work

Now it passes, but this is one nasty patch. I don't want to lose the entire history of the file.

There is a super quick and easy fix though, preventing the module disabling code from running during drush

What exactly is happening that disables the module? Can't we be more precise?

(BTW, Drupal coding conventions require ending comments with a dot.)

salvis’s picture

Ah, I only saw the change in mailmime.inc...

But now that I'm seeing the part in mailmime.module, I'm wondering why the former is needed at all.

+++ b/mailmime.module
@@ -12,52 +12,56 @@
+  /* Prevent module from disabling itself during drush execution,
+  module has all needed requirements but was still disabling itself. */
+  if (!function_exists('drush_main')) {
+    // This only needs to succeed once.

Why not just something more reasonable like

+
+  /* Prevent module from disabling itself during drush execution,
+     module has all needed requirements but was still disabling itself. */
+  if (function_exists('drush_main')) {
+    return;
+  }
+
   // This only needs to succeed once.

?

(Note the white space.)

DrCord’s picture

that is a very reasonable solution. I will try and find time today to re-patch. Thanks for your help on this! :D

DrCord’s picture

Here is a patch with the suggested edit to the patch in mailmime.module, it makes it a much nicer patch. I looked at making a change to the patch in mailmime.inc, but it doesn't really lend itself to the same solution as it isn't a function to return from...

DrCord’s picture

Status: Needs work » Needs review
salvis’s picture

Why are you still nuking mailmime.inc?

DrCord’s picture

because it caused errors if I didn't. It tried to do the stuff in the file during drush and was very unhappy.

salvis’s picture

Please be more specific.

DrCord’s picture

The module would throw errors trying to load the classes that it couldn't due to the paths not being set by the init hook or something. I didn't save the errors at the time, just fixed them. Feel free to generate them and patch this yourself if my patch is unacceptable.

salvis’s picture

Status: Needs review » Needs work

The problem with this patch is that it's 58K because of indenting changes, and
a) it's impossible to find the actual changes and
b) Git will mark most everything as changed when it really isn't.

I'm just trying to help out here because the author/maintainer has vanished, and I don't want to commit a patch that destroys the history of the module.

salvis’s picture

Status: Needs work » Needs review
StatusFileSize
new1.4 KB

Here's a more reasonable version of #9 that does the same thing except for changing indentation.

You also tried to fix some ugly indentation and line wrapping issues, but we must never fix functionality and hide (!) unrelated cosmetics in the same patch. Except maybe adding an empty line or two...

  • salvis committed aa8ce5d on 7.x-2.x
    Issue #2427405 by DrCord, salvis: hook_init called during drush,...
salvis’s picture

Status: Needs review » Fixed
DrCord’s picture

You rock! Thanks for fixing this the right way.

Status: Fixed » Closed (fixed)

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

spuki’s picture

Status: Closed (fixed) » Needs work

I got the error, which does not appear when I remove this patch from code.

Fatal error: Call to undefined function url_to_realpath() in /var/www/avtoms/sites/all/modules/mailmime/mailmime.inc on line 393

spuki’s picture

spuki’s picture

Status: Needs work » Needs review
DrCord’s picture

all your patch (#22) does is remove the patched functionality, this is not a patch to use!

DrCord’s picture

Status: Needs review » Needs work
haggins’s picture

It should be

if (function_exists('drush_main')) {
  // Prevent module execution during drush execution (#2427405).
  return;
}

instead of

if (!function_exists('drush_main')) {
  // Prevent module execution during drush execution (#2427405).
  return;
}

Otherwhise it will..

  • not fix the Drush issue
  • break htmlmail module which expects the class MailMIME to exist
salvis’s picture

Status: Needs work » Needs review
StatusFileSize
new291 bytes

So, is this what we need?

haggins’s picture

After reading again the whole issue and thinking about it, I'd even say that patch from #22 is the correct one.

In #17 you committed a patch which checks for a drush instance in hook_init() as well as in mimemail.inc.

Since the original issue was just about the issue, that drush automatically disables mailmime due to hook_init() execution, I don't see a need to cancel execution in mimemail.inc. It can't hurt drush to have the MailMIME class available.

haggins’s picture

Indeed, I needed to apply patch #22 yesterday to make cron via drush working again. It's 100% save because the Drush condition in mailmime.inc makes absolutely no sense.

salvis’s picture

#22 does not apply to the HEAD of 7.x-2.x because the condition is reversed.

So, could this be what we need?

haggins’s picture

Yes, that's it! Thanks.

  • salvis committed 2eb0ff4 on 7.x-2.x
    Issue #2427405 salvis, spuki, haggins: hook_init called during drush,...
salvis’s picture

Status: Needs review » Fixed

Ok, I take this as RTBC...

Thanks!

Status: Fixed » Closed (fixed)

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