mimemail.admin.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * @file
  4. * Configuration settings page for sending MIME-encoded emails.
  5. */
  6. /**
  7. * Configuration form.
  8. */
  9. function mimemail_admin_settings() {
  10. // Check for the existence of a mail.css file in the default theme folder.
  11. $theme = variable_get('theme_default', NULL);
  12. $mailstyle = drupal_get_path('theme', $theme) . '/mail.css';
  13. // Disable site style sheets including option if found.
  14. if (is_file($mailstyle)) {
  15. variable_set('mimemail_sitestyle', 0);
  16. $disable_sitestyle = TRUE;
  17. }
  18. else {
  19. $disable_sitestyle = FALSE;
  20. }
  21. $form = array();
  22. $form['mimemail']['mimemail_name'] = array(
  23. '#type' => 'textfield',
  24. '#title' => t('Sender name'),
  25. '#default_value' => variable_get('mimemail_name', variable_get('site_name', 'Drupal')),
  26. '#size' => 60,
  27. '#maxlength' => 128,
  28. '#description' => t('The name that all site emails will be from when using default engine.'),
  29. );
  30. $form['mimemail']['mimemail_mail'] = array(
  31. '#type' => 'textfield',
  32. '#title' => t('Sender e-mail address'),
  33. '#default_value' => variable_get('mimemail_mail', variable_get('site_mail', ini_get('sendmail_from'))),
  34. '#size' => 60,
  35. '#maxlength' => 128,
  36. '#description' => t('The email address that all site e-mails will be from when using default engine.'),
  37. );
  38. $form['mimemail']['mimemail_simple_address'] = array(
  39. '#type' => 'checkbox',
  40. '#title' => t('Use simple address format'),
  41. '#default_value' => variable_get('mimemail_simple_address', FALSE),
  42. '#description' => t('Use the simple format of user@example.com for all recipient email addresses.'),
  43. );
  44. $form['mimemail']['mimemail_sitestyle'] = array(
  45. '#type' => 'checkbox',
  46. '#title' => t('Include site style sheets'),
  47. '#default_value' => variable_get('mimemail_sitestyle', TRUE),
  48. '#description' => t('Gather all style sheets when no mail.css found in the default theme directory.'),
  49. '#disabled' => $disable_sitestyle,
  50. );
  51. $form['mimemail']['mimemail_textonly'] = array(
  52. '#type' => 'checkbox',
  53. '#title' => t('Send plain text email only'),
  54. '#default_value' => variable_get('mimemail_textonly', FALSE),
  55. '#description' => t('This option disables the use of email messages with graphics and styles. All messages will be converted to plain text.'),
  56. );
  57. $form['mimemail']['mimemail_linkonly'] = array(
  58. '#type' => 'checkbox',
  59. '#title' => t('Link images only'),
  60. '#default_value' => variable_get('mimemail_linkonly', 0),
  61. '#description' => t('This option disables the embedding of images. All image will be available as external content. This can make email messages much smaller.'),
  62. );
  63. if (module_exists('mimemail_compress')) {
  64. $form['mimemail']['mimemail_preserve_class'] = array(
  65. '#type' => 'checkbox',
  66. '#title' => t('Preserve class attributes'),
  67. '#default_value' => variable_get('mimemail_preserve_class', 0),
  68. '#description' => t('This option disables the removing of class attributes from the message source. Useful for debugging the style of the message.'),
  69. );
  70. }
  71. // Get a list of all formats.
  72. $formats = filter_formats();
  73. foreach ($formats as $format) {
  74. $format_options[$format->format] = $format->name;
  75. }
  76. $form['mimemail']['mimemail_format'] = array(
  77. '#type' => 'select',
  78. '#title' => t('E-mail format'),
  79. '#options' => $format_options,
  80. '#default_value' => variable_get('mimemail_format', filter_fallback_format()),
  81. '#access' => count($formats) > 1,
  82. '#attributes' => array('class' => array('filter-list')),
  83. '#description' => t('The filter set that will be applied to the message body.
  84. If you are using Mime Mail as default mail system, make sure to enable
  85. "Convert line breaks into HTML" and "Convert URLs into links" with a long
  86. enough maximum length for e.g. password reset URLs!'),
  87. );
  88. $form['mimemail']['advanced'] = array(
  89. '#type' => 'fieldset',
  90. '#title' => t('Advanced settings'),
  91. '#collapsible' => TRUE,
  92. '#collapsed' => TRUE,
  93. );
  94. $form['mimemail']['advanced']['mimemail_incoming'] = array(
  95. '#type' => 'checkbox',
  96. '#title' => t('Process incoming messages posted to this site'),
  97. '#default_value' => variable_get('mimemail_incoming', FALSE),
  98. '#description' => t('This is an advanced setting that should not be enabled unless you know what you are doing.'),
  99. );
  100. $form['mimemail']['advanced']['mimemail_key'] = array(
  101. '#type' => 'textfield',
  102. '#title' => t('Message validation string'),
  103. '#default_value' => variable_get('mimemail_key', drupal_random_key()),
  104. '#required' => TRUE,
  105. '#description' => t('This string will be used to validate incoming messages. It can be anything, but must be used on both sides of the transfer.'),
  106. );
  107. // Get the available mail engines.
  108. $engines = mimemail_get_engines();
  109. foreach ($engines as $module => $engine) {
  110. $engine_options[$module] = $engine['name'] . ': ' . $engine['description'];
  111. }
  112. // Hide the settings if only 1 engine is available.
  113. if (count($engines) == 1) {
  114. reset($engines);
  115. variable_set('mimemail_engine', key($engines));
  116. $form['mimemail']['mimemail_engine'] = array(
  117. '#type' => 'hidden',
  118. '#value' => variable_get('mimemail_engine', 'mimemail'),
  119. );
  120. }
  121. else {
  122. $form['mimemail']['mimemail_engine'] = array(
  123. '#type' => 'select',
  124. '#title' => t('E-mail engine'),
  125. '#default_value' => variable_get('mimemail_engine', 'mimemail'),
  126. '#options' => $engine_options,
  127. '#description' => t('Choose an engine for sending mails from your site.'),
  128. );
  129. }
  130. if (variable_get('mimemail_engine', 'mail')) {
  131. $settings = module_invoke(variable_get('mimemail_engine', 'mimemail'), 'mailengine', 'settings');
  132. if ($settings) {
  133. $form['mimemail']['engine_settings'] = array(
  134. '#type' => 'fieldset',
  135. '#title' => t('Engine specific settings'),
  136. );
  137. foreach ($settings as $name => $value) {
  138. $form['mimemail']['engine_settings'][$name] = $value;
  139. }
  140. }
  141. }
  142. else {
  143. drupal_set_message(t('Please choose a mail engine.'), 'error');
  144. }
  145. return system_settings_form($form);
  146. }