You are here

public function mailhandler_mailbox_ui::edit_form in Mailhandler 7.2

Same name and namespace in other branches
  1. 6.2 plugins/ctools/export_ui/mailhandler_mailbox_ui.class.php \mailhandler_mailbox_ui::edit_form()

Implements ctools_export_ui::edit_form().

Overrides ctools_export_ui::edit_form

File

plugins/ctools/export_ui/mailhandler_mailbox_ui.class.php, line 19
Definition of mailhandler_mailbox_ui class.

Class

mailhandler_mailbox_ui

Code

public function edit_form(&$form, &$form_state) {
  parent::edit_form($form, $form_state);
  $retrieve_plugins = mailhandler_get_plugins('mailhandler', 'retrieve');
  if (count($retrieve_plugins) == 1) {
    mailhandler_report('warning', 'No retrieval plugins are available. Please <a href="@module-page">enable a module</a> providing a retrieval plugin, such as the Mailhandler PHP IMAP module.', array(
      '@module-page' => url('admin/modules'),
    ));
  }
  global $cookie_domain;
  extract($form_state['item']->settings);
  $form['info']['admin_title']['#description'] = t('Suggested, but not required, to be the email address of the mailbox.');
  $form['connection']['#tree'] = FALSE;
  $form['connection']['settings'] = array(
    '#type' => 'fieldset',
    '#title' => 'Mailbox connection settings',
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#after_build' => array(
      '_mailhandler_include_js',
    ),
  );
  $form['connection']['settings']['type'] = array(
    '#type' => 'select',
    '#title' => t('Protocol'),
    '#options' => array(
      'imap' => 'IMAP',
      'pop3' => 'POP3',
      'local' => 'Local mbox file',
    ),
    '#default_value' => $type,
    '#description' => t('You can use the IMAP/POP3 protocols, or retrieve from an mbox file on the local file system.'),
  );
  $ajax_settings = array(
    'callback' => '_mailhandler_mailbox_test',
    'wrapper' => 'mailhandler_test_results',
    'event' => 'change',
    'progress' => array(
      'type' => 'throbber',
      'message' => t('Please wait - testing connection settings...'),
    ),
  );
  $form['connection']['settings']['folder'] = array(
    '#type' => 'textfield',
    '#title' => t('Folder'),
    '#default_value' => $folder,
    '#description' => t('The folder where the mail is stored. If you want this mailbox to read from a local mbox file, give an absolute path or the path relative to the Drupal installation directory.'),
    '#ajax' => $ajax_settings,
  );
  $form['connection']['settings']['domain'] = array(
    '#type' => 'textfield',
    '#title' => t('Domain'),
    '#default_value' => $domain ? $domain : trim($cookie_domain, '.'),
    '#description' => t('The domain of the server used to collect mail.'),
    '#ajax' => $ajax_settings,
  );
  $form['connection']['settings']['port'] = array(
    '#type' => 'textfield',
    '#title' => t('Port'),
    '#size' => 5,
    '#maxlength' => 5,
    '#default_value' => $port,
    '#description' => t('The mailbox port number (usually 995 for POP3, 993 for IMAP).'),
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#ajax' => $ajax_settings,
  );
  $form['connection']['settings']['insecure'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow insecure connections'),
    '#default_value' => $insecure,
    '#description' => 'Check to allow the username and password to be sent in plain text.',
  );
  $form['connection']['settings']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Username'),
    '#default_value' => $name,
    '#description' => t('This username is used while logging into this mailbox during mail retrieval.'),
    '#ajax' => $ajax_settings,
  );
  $form['connection']['settings']['pass'] = array(
    '#type' => 'textfield',
    '#title' => t('Password'),
    '#default_value' => $pass,
    '#description' => t('The password corresponding to the username above. Consider using a non-vital password, since this field is stored without encryption in the database.'),
    '#ajax' => $ajax_settings,
  );

  // Allow administrators to configure the mailbox with extra IMAP commands (notls, novalidate-cert etc.)
  $form['connection']['settings']['extraimap'] = array(
    '#type' => 'textfield',
    '#title' => t('Extra commands'),
    '#default_value' => $extraimap,
    '#description' => t('In some circumstances you need to issue extra commands to connect to your mail server (e.g., "/notls" or "/novalidate-cert"). See documentation for <a href="@imap-open">imap_open</a>.', array(
      '@imap-open' => url('http://php.net/imap_open'),
    )),
    '#ajax' => $ajax_settings,
  );
  $form['connection']['settings']['results'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'id' => 'mailhandler_test_results',
    ),
  );
  $form['extra']['#tree'] = FALSE;
  $form['extra']['settings'] = array(
    '#type' => 'fieldset',
    '#title' => 'More settings',
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['extra']['settings']['limit'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum messages to retrieve'),
    '#size' => 5,
    '#maxlength' => 5,
    '#default_value' => $limit,
    '#description' => t('To prevent timeout errors from large mailboxes you can limit the maximum number of messages that will be retrieved during each cron run. Set to zero for no limit.'),
    '#element_validate' => array(
      'element_validate_integer',
    ),
  );
  $form['extra']['settings']['encoding'] = array(
    '#type' => 'textfield',
    '#title' => t('Default character encoding'),
    '#default_value' => $encoding,
    '#description' => t('The default character encoding to use when an incoming message does not define an encoding.'),
  );
  $form['extra']['settings']['flag_after_read'] = array(
    '#type' => 'checkbox',
    '#title' => t('Mark messages as seen/read after they are processed?'),
    '#default_value' => isset($flag_after_read) ? $flag_after_read : TRUE,
    '#description' => t('Note that messages cannot be marked as seen/read for POP3 accounts.'),
  );
  $form['extra']['settings']['delete_after_read'] = array(
    '#type' => 'checkbox',
    '#title' => t('Delete messages after they are processed?'),
    '#default_value' => $delete_after_read,
    '#description' => t('Uncheck this box to leave read messages in the mailbox. They will not be processed again unless they become marked as unread.  If you selected "POP3" as your mailbox type, you must check this box.'),
  );
  $form['extra']['settings']['fromheader'] = array(
    '#type' => 'textfield',
    '#title' => t('From header'),
    '#default_value' => $fromheader,
    '#description' => t('Use this e-mail header to determine the author of the resulting node. <strong>Sender</strong> is useful when working with listservs.'),
  );
  $form['extra']['settings']['security'] = array(
    '#type' => 'radios',
    '#title' => t('Security'),
    '#options' => array(
      t('Disabled'),
      t('Require password'),
    ),
    '#default_value' => $security,
    '#description' => t('Disable security if your site does not require a password in the Commands section of incoming e-mails. Note: Security=Enabled and MIME preference=HTML is an unsupported combination.'),
  );
  $form['extra']['settings']['replies'] = array(
    '#type' => 'radios',
    '#title' => t('Send error replies'),
    '#options' => array(
      t('Disabled'),
      t('Enabled'),
    ),
    '#default_value' => $replies,
    '#description' => t('Send helpful replies to all unsuccessful e-mail submissions. Consider disabling when a listserv posts to this mailbox.'),
  );
  $form['extra']['settings']['retrieve'] = array(
    '#type' => 'select',
    '#title' => t('Retrieval library'),
    '#options' => _mailhandler_build_options($retrieve_plugins),
    '#default_value' => $retrieve,
    '#description' => t('The library that will be used to retrieve messages.'),
    '#required' => TRUE,
  );
  $form['extra']['settings']['readonly'] = array(
    '#type' => 'checkbox',
    '#title' => t('Read-only access'),
    '#description' => t('Do not make changes to source mailbox. Currently only works for local mbox files.'),
    '#default_value' => $readonly,
  );
}