You are here

function mailhandler_add_edit_mailbox in Mailhandler 7

Same name and namespace in other branches
  1. 6 mailhandler.admin.inc \mailhandler_add_edit_mailbox()

Return a form for editing or creating an individual mailbox.

1 string reference to 'mailhandler_add_edit_mailbox'
mailhandler_menu in ./mailhandler.module
Implementation of hook_menu().

File

./mailhandler.admin.inc, line 6

Code

function mailhandler_add_edit_mailbox($form_state, $mid, $clone = FALSE) {
  module_load_include('inc', 'mailhandler', 'mailhandler.retrieve');
  $edit = $mid ? mailhandler_get_mailbox($mid) : array(
    'mail' => '',
    'mailto' => '',
    'imap' => 0,
    'domain' => '',
    'port' => '',
    'name' => '',
    'pass' => '',
    'extraimap' => '',
    'mime' => 'TEXT/HTML,TEXT/PLAIN',
    'security' => 0,
    'replies' => 1,
    'fromheader' => '',
    'commands' => '',
    'sigseparator' => '',
    'delete_after_read' => 1,
    'enabled' => 1,
    'format' => FILTER_FORMAT_DEFAULT,
    'authentication',
  );
  if ($clone) {
    unset($mid);
  }
  if (empty($edit['folder'])) {
    $edit['folder'] = 'INBOX';
  }
  $form['mail'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail address'),
    '#default_value' => $edit['mail'],
    '#description' => t('The e-mail address to which users should send their submissions.'),
    '#required' => TRUE,
  );
  $form['mailto'] = array(
    '#type' => 'textfield',
    '#title' => t('Second E-mail address'),
    '#default_value' => $edit['mailto'],
    '#description' => t('Optional. The e-mail address to which modules should send generated content.'),
  );
  $form['folder'] = array(
    '#type' => 'textfield',
    '#title' => t('Folder'),
    '#default_value' => $edit['folder'],
    '#description' => t('Optional. The folder where the mail is stored. If you want this mailbox to read from a local folder, give the full path. Leave domain, port, name, and pass empty below. Remember to set the folder to readable and writable by the webserver.'),
  );
  $form['imap'] = array(
    '#type' => 'select',
    '#title' => t('POP3 or IMAP Mailbox'),
    '#options' => array(
      'POP3',
      'IMAP',
    ),
    '#default_value' => $edit['imap'],
    '#description' => t('If you wish to retrieve mail from a POP3 or IMAP mailbox instead of a Folder, select POP3 or IMAP. Also, complete the Mailbox items below.'),
  );
  $form['domain'] = array(
    '#type' => 'textfield',
    '#title' => t('Mailbox domain'),
    '#default_value' => $edit['domain'],
    '#description' => t('The domain of the server used to collect mail.'),
  );
  $form['port'] = array(
    '#type' => 'textfield',
    '#title' => t('Mailbox port'),
    '#size' => 5,
    '#maxlength' => 5,
    '#default_value' => $edit['port'],
    '#description' => t('The port of the mailbox used to collect mail (usually 110 for POP3, 143 for IMAP).'),
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Mailbox username'),
    '#default_value' => $edit['name'],
    '#description' => t('This username is used while logging into this mailbox during mail retrieval.'),
  );
  $form['pass'] = array(
    '#type' => 'textfield',
    '#title' => t('Mailbox password'),
    '#default_value' => $edit['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.'),
  );

  // Allow administrators to configure the mailbox with extra IMAP commands (notls, novalidate-cert etc.)
  $form['extraimap'] = array(
    '#type' => 'textfield',
    '#title' => t('Extra commands'),
    '#default_value' => $edit['extraimap'],
    '#description' => t('Optional. 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="http://php.net/imap_open">imap_open</a>. Begin the string with a "/", separating each subsequent command with another "/".'),
  );
  $form['mime'] = array(
    '#type' => 'select',
    '#title' => t('MIME preference'),
    '#options' => array(
      'TEXT/HTML,TEXT/PLAIN' => 'HTML',
      'TEXT/PLAIN,TEXT/HTML' => t('Plain text'),
    ),
    '#default_value' => $edit['mime'],
    '#description' => t('When a user sends an e-mail containing both HTML and plain text parts, use this part as the node body.'),
  );
  $form['security'] = array(
    '#type' => 'radios',
    '#title' => t('Security'),
    '#options' => array(
      t('Disabled'),
      t('Require password'),
    ),
    '#default_value' => isset($edit['security']) ? $edit['security'] : 0,
    '#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['replies'] = array(
    '#type' => 'radios',
    '#title' => t('Send error replies'),
    '#options' => array(
      t('Disabled'),
      t('Enabled'),
    ),
    '#default_value' => $edit['replies'],
    '#description' => t('Send helpful replies to all unsuccessful e-mail submissions. Consider disabling when a listserv posts to this mailbox.'),
  );
  $form['fromheader'] = array(
    '#type' => 'textfield',
    '#title' => t('From header'),
    '#default_value' => $edit['fromheader'],
    '#description' => t('Use this e-mail header to determine the author of the resulting node. Admins usually leave this field blank (thus using the <strong>From</strong> header), but <strong>Sender</strong> is also useful when working with listservs.'),
  );
  $form['commands'] = array(
    '#type' => 'textarea',
    '#title' => t('Default commands'),
    '#default_value' => $edit['commands'],
    '#description' => t('A set of commands which are added to each message. One command per line. See <a href="@link">Commands</a>.', array(
      '@link' => url('admin/help/mailhandler/#commands'),
    )),
  );
  $form['sigseparator'] = array(
    '#type' => 'textfield',
    '#title' => t('Signature separator'),
    '#default_value' => $edit['sigseparator'],
    '#description' => t('All text after this string will be discarded. A typical value is <strong>"-- "</strong> that is two dashes followed by a blank in an otherwise empty line. Leave blank to include signature text in nodes.'),
  );
  $form['delete_after_read'] = array(
    '#type' => 'checkbox',
    '#title' => t('Delete messages after they are processed?'),
    '#default_value' => $edit['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['enabled'] = array(
    '#type' => 'radios',
    '#title' => t('Cron processing'),
    '#options' => array(
      t('Disabled'),
      t('Enabled'),
    ),
    '#default_value' => $edit['enabled'],
    '#description' => t('Select disable to temporarily stop cron processing for this mailbox.'),
  );

  // Allow administrators to select the format of saved nodes/comments
  $form['format'] = filter_form($edit['format']);
  $options = array();
  $descriptions = '';
  $options[0] = t('Choose method');
  $methods = mailhandler_mailhandler_authenticate('info');
  foreach ($methods as $method) {
    foreach ($method as $name => $info) {
      $options[$name] = t($info['title']);

      // TODO: theme function
      $descriptions .= t($info['title']) . ": " . t($info['description']) . "\n";
    }
  }
  $form['authentication'] = array(
    '#type' => 'select',
    '#title' => t('Message authentication method'),
    '#options' => $options,
    '#description' => t('Following is the name and description of each available authentication method') . "\n\n" . $descriptions,
    '#default_value' => $edit['authentication'],
  );
  $form['actions'] = array(
    '#prefix' => '<p><div class="confirmation container-inline">',
    '#suffix' => '</div></p>',
  );
  $form['mid'] = array(
    '#type' => 'hidden',
    '#value' => $mid,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save mailbox'),
  );
  $form['actions']['test'] = array(
    '#type' => 'submit',
    '#value' => t('Test connection'),
  );
  if ($mid) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete mailbox'),
      '#submit' => array(
        'mailhandler_delete_mailbox_submit',
      ),
      '#validate' => array(),
    );
  }
  $form['actions']['cancel'] = array(
    '#value' => l(t('Cancel'), 'admin/content/mailhandler'),
  );
  return $form;
}