You are here

function mailmime_init in Mail MIME 7.2

Same name and namespace in other branches
  1. 8.2 mailmime.module \mailmime_init()
  2. 6.2 mailmime.module \mailmime_init()
  3. 6 mailmime.module \mailmime_init()
  4. 7 mailmime.module \mailmime_init()

Implements hook_init().

Ensures that required PEAR modules are available, or else disables the Mail MIME module to avoid conflicts.

File

./mailmime.module, line 14
Ensures that required files are available.

Code

function mailmime_init() {
  if (function_exists('drush_main')) {

    // Prevent module from disabling itself during drush execution;
    // module has all needed requirements during normal execution
    // but was still disabling itself (#2427405).
    return;
  }

  // This only needs to succeed once.
  if (cache_get('mailmime_installed', 'cache_bootstrap')) {
    return;
  }
  if (mailmime_check_requirements()) {
    cache_set('mailmime_installed', TRUE, 'cache_bootstrap');
    return;
  }

  // Requirements check failed; disable module and issue an error message.
  module_disable(array(
    'mailmime',
  ));
  $args = array(
    '!include' => url('admin/modules', array(
      'fragment' => 'edit-modules-other-include-enable',
    )),
    '!include_path' => url('http://php.net/set_include_path'),
    '!module' => url('admin/modules', array(
      'fragment' => 'edit-modules-mail-mailmime-enable',
    )),
    '!modules' => url('admin/modules'),
    '!mime' => url('http://pear.php.net/package/Mail_Mime'),
    '!mimedecode' => url('http://pear.php.net/package/Mail_mimeDecode'),
    '!mimepart' => url('http://pear.php.net/manual/package.mail.mail-mimepart.mail-mimepart.php'),
    '!pear' => url('http://pear.php.net'),
    '!pearerror' => url('http://pear.php.net/manual/core.pear.pear-error.pear-error.php'),
    '!readme' => url(drupal_get_path('module', 'mailmime') . '/README.html', array(
      'fragment' => 'requirements',
    )),
  );
  drupal_set_message(t('One or more of the required <a href="!pear">PEAR</a> classes could not be loaded:<ul><li><a href="!mime">Mail_Mime</a></li><li><a href="!mimedecode">Mail_mimeDecode</a></li><li><a href="!mimepart">Mail_mimePart</a></li><li><a href="!pearerror">PEAR_Error</a></li></ul> The <a href="!module">Mail MIME</a> module has been disabled to avoid further errors. Please satisfy the module requirements listed in the <a href="!readme">documentation</a>, then visit your <a href="!modules">Modules</a> page to re-enable the <a href="!module">Mail MIME</a> module.', $args), 'error');
  if (module_exists('include')) {
    drupal_set_message(t('The <a href="!include">Include</a> module tried to automatically download the required files, but the attempt failed. You may retry the download by re-enabling the <a href="!module">Mail MIME</a> module.  If your hosting provider has disabled the <a href="!include_path"><code>set_include_path</code></a> directive, the files must be manually installed.', $args), 'error');
  }
  else {
    drupal_set_message(t('If installed, the <a href="!include">Include</a> module can attempt to automatically download the required files for you.', $args), 'status');
  }
  watchdog('mailmime', 'The <a href="!module">Mail MIME</a> module has disabled itself.', $args, WATCHDOG_CRITICAL);
}