settings = $mailbox->settings; $this->mail = $mailbox->mail; $this->mailbox_type = $mailbox->mailbox_type; $this->imap = $mailbox->settings['MailhandlerMailbox']['imap']; $this->domain = $mailbox->settings['MailhandlerMailbox']['domain']; $this->port = $mailbox->settings['MailhandlerMailbox']['port']; $this->extraimap = $mailbox->settings['MailhandlerMailbox']['extraimap']; $this->folder = $mailbox->settings['MailhandlerMailbox']['folder']; $this->name = $mailbox->settings['MailhandlerMailbox']['name']; $this->pass = $mailbox->settings['MailhandlerMailbox']['pass']; $this->limit = $mailbox->settings['MailhandlerMailbox']['limit']; $this->mime = $mailbox->settings['MailhandlerMailbox']['mime']; $this->delete_after_read = $mailbox->settings['MailhandlerMailbox']['delete_after_read']; $this->encoding = $mailbox->settings['MailhandlerMailbox']['encoding']; $this->fromheader = $mailbox->settings['MailhandlerMailbox']['fromheader']; $this->security = $mailbox->settings['MailhandlerMailbox']['security']; $this->replies = $mailbox->settings['MailhandlerMailbox']['replies']; $this->commandplugin = $mailbox->settings['MailhandlerMailbox']['commandplugin']; $this->authenticateplugin = $mailbox->settings['MailhandlerMailbox']['authenticateplugin']; } else { $this->mailbox_type = get_class($this); } } private function setInfo() { return array( 'title' => 'Basic mailbox', 'description' => 'Base settings for mailbox.', ); } public function getInfo() { return $this->setInfo(); } public function getSettings($setting = '', $object = FALSE) { if (!$setting) { return $this->settings; } else { return $this->settings[get_class($object)][$setting]; } } /** * Settings form */ public function form(&$form_state, $defaults) { $form = array(); $form['mailto'] = array( '#type' => 'textfield', '#title' => t('Second E-mail address'), '#default_value' => $defaults['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' => $defaults['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' => $defaults['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' => $defaults['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' => $defaults['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' => $defaults['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' => $defaults['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' => $defaults['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 imap_open. Begin the string with a "/", separating each subsequent command with another "/".'), ); $form['limit'] = array( '#type' => 'textfield', '#title' => t('Maximum messages to retrieve'), '#default_value' => $defaults['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. A value of zero means that no limit will be applied. Some trial and error may be needed to find the optimum setting.'), ); $form['encoding'] = array( '#type' => 'textfield', '#title' => t('Default character encoding'), '#default_value' => $defaults['encoding'], '#description' => t('The default character encoding to use when an incoming message does not define an encoding.') ); $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' => $defaults['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['delete_after_read'] = array( '#type' => 'checkbox', '#title' => t('Delete messages after they are processed?'), '#default_value' => $defaults['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['fromheader'] = array( '#type' => 'textfield', '#title' => t('From header'), '#default_value' => $defaults['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 From header), but Sender is also useful when working with listservs.') ); $form['security'] = array( '#type' => 'radios', '#title' => t('Security'), '#options' => array(t('Disabled'), t('Require password')), '#default_value' => isset($defaults['security']) ? $defaults['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' => $defaults['replies'], '#description' => t('Send helpful replies to all unsuccessful e-mail submissions. Consider disabling when a listserv posts to this mailbox.') ); ctools_include('plugins'); $options = array(); $plugins = mailhandler_get_plugins('mailhandler', 'commands_plugin'); foreach ($plugins as $key => $info) { $options[$key] = $info['name']; } $form['commandplugin'] = array( '#type' => 'select', '#title' => t('Command plugins'), '#description' => t('Choose the command plugins to use'), '#options' => $options, '#multiple' => TRUE, '#default_value' => $defaults['commandplugin'] ? $defaults['commandplugin'] : 'MailhandlerCommandsDefault', ); $options = array(); //$options[0] = t('None'); $plugins = mailhandler_get_plugins('mailhandler', 'authenticate_plugin'); foreach ($plugins as $key => $info) { $options[$key] = $info['name']; } $form['authenticateplugin'] = array( '#type' => 'select', '#title' => t('Authentication plugin'), '#description' => t('Choose an authentication plugin'), '#options' => $options, '#default_value' => $defaults['authenticateplugin'] ? $defaults['authenticateplugin'] : 'MailhandlerAuthenticateDefault', '#required' => FALSE, ); return $form; } function validate($form, &$form_state) { // Check whether valid email address. //@TODO don't validate local folders this way //if ($error = user_validate_mail($form_state['values']['mail'])) { // form_set_error('mail', $error); //} // Check whether email address already exists if ($form_state['op'] === 'add') { if ($result = db_result(db_query("SELECT 1 FROM {mailhandler} WHERE mail = '%s'", $form_state['values']['mail']))) { form_set_error('mail', t('Mailbox %mail already exists. Please use a unique mailbox name.', array('%mail' => $form_state['values']['mail']))); } } // Check whether mailto is valid. if ($form_state['values']['mailto'] && ($error = user_validate_mail($form_state['values']['mailto']))) { form_set_error('mailto', $error); } // Test POP/IMAP settings, and store result $mailbox_appears_ok = TRUE; if ($form_state['values']['domain'] && $form_state['values']['port'] && !is_numeric($form_state['values']['port'])) { // assume external mailbox form_set_error('port', t('Mailbox port must be an integer.')); $mailbox_appears_ok = FALSE; } if (!$form_state['values']['domain'] && !$form_state['values']['port'] && $form_state['values']['folder']) { // assume local folder // check read and write permission if (!is_readable($form_state['values']['folder']) || !is_writable($form_state['values']['folder'])) { form_set_error('port', t('The local folder has to be readable and writable by owner of the webserver process, e.g. nobody.')); $mailbox_appears_ok = FALSE; } } // @TODO get this working again. // // Test POP/IMAP settings are valid in all cases, and test connection if requested // if ($mailbox_appears_ok && $form_state['clicked_button']['#value'] == t('Test connection')) { // // Call the test function // mailhandler_test_mailbox($form_state); // // We don't want to save, so we set an 'invisible error' that means the form is not submitted // form_set_error('mailhandler'); // } // 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']['imap'] == 0 && $form_state['values']['delete_after_read'] == 0) { drupal_set_message(t('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.'), 'warning'); } } }