<?php

/**
 * @file
 * The installation instructions for the SMTP Authentication Support.
 */

/**
 * Implements hook_install().
 */
 function smtp_install() {
   variable_set('smtp_on', 0);
 }

/**
 * Implements hook_uninstall().
 */
function smtp_uninstall() {
  variable_del('smtp_allowhtml');
  variable_del('smtp_from');
  variable_del('smtp_fromname');
  variable_del('smtp_host');
  variable_del('smtp_hostbackup');
  variable_del('smtp_on');
  variable_del('smtp_password');
  variable_del('smtp_port');
  variable_del('smtp_protocol');
  variable_del('smtp_queue');
  variable_del('smtp_queue_fail');
  variable_del('smtp_test_address');
  variable_del('smtp_username');
  variable_del('smtp_debugging');
  variable_del('smtp_client_hostname');
  variable_del('smtp_client_helo');
  variable_del('smtp_deliver');
}

/**
 * Implements hook_disable().
 */
function smtp_disable() {
  $mail_modes = variable_get('mail_system');
  $mail_modes['default-system'] = 'DefaultMailSystem';
  variable_set('mail_system', $mail_modes);
}

/**
 * Implements hook_update_N().
 *
 * Upgrade to Drupal 7.x
 */
function smtp_update_7000() {
  if (variable_get('smtp_on', 0) != 0) {
    variable_set('mail_system', array('default-system' => 'SmtpMailSystem'));
  }
  // Not used any more in D7.
  variable_del('smtp_library');
}

/**
 * Implements hook_update_N().
 *
 * Back to default mail system if the status flag is off.
 */
function smtp_update_7100() {
  $mail_modes = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
  if ($mail_modes['default-system'] == 'SmtpMailSystem' && !variable_get('smtp_on', FALSE)) {
    $mail_modes['default-system'] = 'DefaultMailSystem';
    variable_set('mail_system', $mail_modes);
  }
}

/**
 * Implements hook_update_N().
 *
 * Updating variable value now that new SMTP logging behavior has been
 * implemented.
 */
function smtp_update_7101() {
  $old_debugging_value = variable_get('smtp_debugging', 0);

  $logging = SMTP_LOGGING_NONE;

  if ($old_debugging_value == 1) {
    $logging = SMTP_LOGGING_ERRORS;
  }

  variable_set('smtp_debugging', $logging);
}

/**
 * Remove the unused 'smtp_library' variable.
 */
function smtp_update_7102() {
  variable_del('smtp_library');
}
