You are here

class mailhandler_mailbox_ui in Mailhandler 6.2

Same name and namespace in other branches
  1. 7.2 plugins/ctools/export_ui/mailhandler_mailbox_ui.class.php \mailhandler_mailbox_ui

Represents an email mailbox (IMAP, POP3, etc...).

Intended to be used as a source for a Feeds Importer using the Mailhandler Fetcher.

Hierarchy

Expanded class hierarchy of mailhandler_mailbox_ui

1 string reference to 'mailhandler_mailbox_ui'
mailhandler.inc in plugins/ctools/export_ui/mailhandler.inc

File

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

View source
class mailhandler_mailbox_ui extends ctools_export_ui {

  /**
   * Implementation of ctools_export_ui::edit_form().
   */
  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'),
      ));
    }
    drupal_add_js(drupal_get_path('module', 'mailhandler') . '/mailhandler_mailbox_ui.js');
    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['info']['admin_title']['#attributes'] = array(
      'class' => 'mailbox-name',
    );
    $form['info']['mail']['#attributes'] = array(
      'class' => 'mailbox-id',
    );
    $form['connection']['#tree'] = FALSE;
    $form['connection']['settings'] = array(
      '#type' => 'fieldset',
      '#title' => 'Mailbox connection settings',
      '#tree' => TRUE,
      '#collapsible' => TRUE,
    );
    $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.'),
    );
    $ahah_settings = array(
      'path' => '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.'),
      '#ahah' => $ahah_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.'),
      '#ahah' => $ahah_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(
        '_mailhandler_element_validate_integer_positive',
      ),
      '#ahah' => $ahah_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.'),
      '#ahah' => $ahah_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.'),
      '#ahah' => $ahah_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", "/novalidate-cert" etc.). See documentation for <a href="@imap-open">imap_open</a>.', array(
        '@imap-open' => url('http://php.net/imap_open'),
      )),
      '#ahah' => $ahah_settings,
    );
    $form['connection']['settings']['results'] = array(
      '#value' => '<div id="mailhandler_test_results" class="form-wrapper"></div>',
    );
    $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(
        '_mailhandler_element_validate_integer_positive',
      ),
    );
    $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,
    );
  }

  /**
   * Implementation of ctools_export_ui::edit_form_validate().
   */
  function edit_form_validate(&$form, &$form_state) {
    parent::edit_form_validate($form, $form_state);

    // If POP3 mailbox is chosen, messages should be deleted after processing.
    // Do not set an actual error because this is helpful for testing purposes.
    if ($form_state['values']['settings']['type'] == 'pop3' && $form_state['values']['settings']['delete_after_read'] == 0) {
      mailhandler_report('warning', 'Unless you check off "Delete messages after they are processed" when using a POP3 mailbox, old emails will be re-imported each time the mailbox is processed. You can partially prevent this by mapping Message ID to a unique target in the processor configuration - see INSTALL.txt or advanced help for more information');
    }

    // Dummy library is only for testing.
    if ($form_state['values']['settings']['retrieve'] == 'MailhandlerRetrieveDummy') {
      mailhandler_report('warning', 'Because you selected the dummy retrieval library, Mailhandler will not import any messages. Please select another retrieval library, such as the PHP IMAP library.');
    }
  }
  function edit_form_submit(&$form, &$form_state) {
    parent::edit_form_submit($form, $form_state);
    if (module_exists('mailhandler_default')) {
      drupal_set_message(t("Now that you've created a mailbox, send it a test email and <a href='@import-page'>create a source node</a> to start importing messages.", array(
        '@import-page' => url('node/add/mailhandler-source'),
      )));
    }
    else {
      drupal_set_message(t("Now that you've created a mailbox, you'll need to <a href='@importer-add'>create a Feeds importer</a> or <a href='@import-page'>run an existing importer</a>. Consider <a href='@module-page'>enabling the Mailhandler quick-start</a> module.", array(
        '@importer-add' => url(MAILHANDLER_MENU_PREFIX . '/feeds/add'),
        '@import-page' => url('import'),
        '@module-page' => url(MAILHANDLER_MENU_PREFIX . '/modules'),
      )));
    }
  }
  function list_header($form_state) {
    if (isset($form_state['input']['test_result'])) {
      return $form_state['input']['test_result'];
    }
  }

  /**
   * Callback to test a mailbox connection.
   */
  function test_page($js, $input, $mailbox) {
    $input['test_result'] = _mailhandler_mailbox_test_output($mailbox);
    if (!$js) {
      drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
    }
    else {
      return $this
        ->list_page($js, $input);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ctools_export_ui::$name property
ctools_export_ui::$options property
ctools_export_ui::$plugin property
ctools_export_ui::access function Menu callback to determine if an operation is accessible. 1
ctools_export_ui::add_page function
ctools_export_ui::clone_page function Main entry point to clone an item.
ctools_export_ui::delete_page function Page callback to delete an exportable item.
ctools_export_ui::disable_page function Callback to disable a page.
ctools_export_ui::edit_cache_clear function Clear the object cache for the currently edited item.
ctools_export_ui::edit_cache_get function Retrieve the item currently being edited from the object cache.
ctools_export_ui::edit_cache_get_key function Figure out what the cache key is for this object.
ctools_export_ui::edit_cache_set function Cache the item currently currently being edited.
ctools_export_ui::edit_cache_set_key function
ctools_export_ui::edit_execute_form function Execute the form.
ctools_export_ui::edit_execute_form_standard function Execute the standard form for editing.
ctools_export_ui::edit_execute_form_wizard function Execute the wizard for editing.
ctools_export_ui::edit_finish_validate function Perform a final validation check before allowing the form to be finished.
ctools_export_ui::edit_form_import function Import form. Provides simple helptext instructions and textarea for pasting a export definition.
ctools_export_ui::edit_form_import_submit function Submit callback for import form.
ctools_export_ui::edit_form_import_validate function Import form validate handler.
ctools_export_ui::edit_page function Main entry point to edit an item.
ctools_export_ui::edit_save_form function Called to save the final product from the edit form.
ctools_export_ui::edit_wizard_back function Wizard 'back' callback when using a wizard to edit an item.
ctools_export_ui::edit_wizard_cancel function Wizard 'cancel' callback when using a wizard to edit an item.
ctools_export_ui::edit_wizard_finish function Wizard 'cancel' callback when using a wizard to edit an item. 1
ctools_export_ui::edit_wizard_next function Wizard 'next' callback when using a wizard to edit an item. 1
ctools_export_ui::enable_page function Callback to enable a page.
ctools_export_ui::export_page function Page callback to display export information for an exportable item.
ctools_export_ui::get_page_title function Get a page title for the current page from our plugin strings.
ctools_export_ui::get_wizard_info function Get the form info for the wizard. 1
ctools_export_ui::help_area function Add text on the top of the page.
ctools_export_ui::hook_menu function hook_menu() entry point.
ctools_export_ui::import_page function Page callback to import information for an exportable item.
ctools_export_ui::init function Fake constructor -- this is easier to deal with than the real constructor because we are retaining PHP4 compatibility, which would require all child classes to implement their own constructor. 1
ctools_export_ui::list_build_row function Build a row based on the item. 2
ctools_export_ui::list_css function Add listing CSS to the page.
ctools_export_ui::list_filter function Determine if a row should be filtered out. 2
ctools_export_ui::list_footer function Render a footer to go after thie list.
ctools_export_ui::list_form function Create the filter/sort form at the top of a list of exports. 2
ctools_export_ui::list_form_submit function Submit the filter/sort form.
ctools_export_ui::list_form_validate function Validate the filter/sort form.
ctools_export_ui::list_page function Master entry point for handling a list.
ctools_export_ui::list_render function Render all of the rows together.
ctools_export_ui::list_search_fields function Provide a list of fields to test against for the default "search" widget. 1
ctools_export_ui::list_sort_options function Provide a list of sort options. 2
ctools_export_ui::list_table_header function Provide the table header. 2
ctools_export_ui::set_item_state function Set an item's state to enabled or disabled and output to user.
mailhandler_mailbox_ui::edit_form function Implementation of ctools_export_ui::edit_form(). Overrides ctools_export_ui::edit_form
mailhandler_mailbox_ui::edit_form_submit function Handle the submission of the edit form. Overrides ctools_export_ui::edit_form_submit
mailhandler_mailbox_ui::edit_form_validate function Implementation of ctools_export_ui::edit_form_validate(). Overrides ctools_export_ui::edit_form_validate
mailhandler_mailbox_ui::list_header function Render a header to go before the list. Overrides ctools_export_ui::list_header
mailhandler_mailbox_ui::test_page function Callback to test a mailbox connection.