mimemail.admin.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. );
  84. $form['mimemail']['advanced'] = array(
  85. '#type' => 'fieldset',
  86. '#title' => t('Advanced settings'),
  87. '#collapsible' => TRUE,
  88. '#collapsed' => TRUE,
  89. );
  90. $form['mimemail']['advanced']['mimemail_incoming'] = array(
  91. '#type' => 'checkbox',
  92. '#title' => t('Process incoming messages posted to this site'),
  93. '#default_value' => variable_get('mimemail_incoming', FALSE),
  94. '#description' => t('This is an advanced setting that should not be enabled unless you know what you are doing.'),
  95. );
  96. $form['mimemail']['advanced']['mimemail_key'] = array(
  97. '#type' => 'textfield',
  98. '#title' => t('Message validation string'),
  99. '#default_value' => variable_get('mimemail_key', drupal_random_key()),
  100. '#required' => TRUE,
  101. '#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.'),
  102. );
  103. // Get the available mail engines.
  104. $engines = mimemail_get_engines();
  105. foreach ($engines as $module => $engine) {
  106. $engine_options[$module] = $engine['name'] . ': ' . $engine['description'];
  107. }
  108. // Hide the settings if only 1 engine is available.
  109. if (count($engines) == 1) {
  110. reset($engines);
  111. variable_set('mimemail_engine', key($engines));
  112. $form['mimemail']['mimemail_engine'] = array(
  113. '#type' => 'hidden',
  114. '#value' => variable_get('mimemail_engine', 'mimemail'),
  115. );
  116. }
  117. else {
  118. $form['mimemail']['mimemail_engine'] = array(
  119. '#type' => 'select',
  120. '#title' => t('E-mail engine'),
  121. '#default_value' => variable_get('mimemail_engine', 'mimemail'),
  122. '#options' => $engine_options,
  123. '#description' => t('Choose an engine for sending mails from your site.'),
  124. );
  125. }
  126. if (variable_get('mimemail_engine', 'mail')) {
  127. $settings = module_invoke(variable_get('mimemail_engine', 'mimemail'), 'mailengine', 'settings');
  128. if ($settings) {
  129. $form['mimemail']['engine_settings'] = array(
  130. '#type' => 'fieldset',
  131. '#title' => t('Engine specific settings'),
  132. );
  133. foreach ($settings as $name => $value) {
  134. $form['mimemail']['engine_settings'][$name] = $value;
  135. }
  136. }
  137. }
  138. else {
  139. drupal_set_message(t('Please choose a mail engine.'), 'error');
  140. }
  141. return system_settings_form($form);
  142. }