--- orig/simplenews.module	2005-08-19 01:02:51.000000000 +0200
+++ simplenews.module	2007-02-05 13:27:29.000000000 +0100
@@ -698,7 +698,6 @@
   $name_default = variable_get('site_name', 'drupal');
   $node->from_address = variable_get('simplenews_from_address', $address_default);
   $node->from_name = variable_get('simplenews_from_name', $name_default);
-  $node->encode = '';
   return $node;
 }
 
@@ -769,7 +768,6 @@
 */
 function sn_mail_confirm($email, $message, $newsletter, $snid = NULL, $tid = NULL, $op = NULL) {
   $mail->s_format = 'plain';
-  $mail->encode = '';
   $mail->priority = 'none';
   $address_default = variable_get('site_mail', ini_get('sendmail_from'));
   $name_default = variable_get('site_name', 'drupal');
@@ -799,13 +797,25 @@
 * Mail engine
 */
 function sn_mail_send($mail) {
+  $content_transfer = '8Bit';
+  if ($mail->s_format == 'html' && variable_get('simplenews_base64_encode', 0)) {
+    $body = split("\n", $mail->message);
+    foreach ($body as $line) {
+      if (strlen($line) > 998) {
+        $content_transfer = 'base64';
+      }
+    }
+    if ($content_transfer == 'base64') {
+      $mail->message = rtrim(chunk_split(base64_encode($mail->message)));
+    }
+  }
   $mail->to = trim($mail->to);
   require_once('activeMailLib.php');
   $email = new activeMailLib($mail->s_format);
   $email->From($mail->from_address, $mail->from_name);
   $email->To($mail->to);
   $email->Subject($mail->title);
-  $email->Message($mail->message, 'UTF-8', $mail->encode);
+  $email->Message($mail->message, 'UTF-8', $content_transfer);
   $email->priority($mail->priority);
   if ($mail->receipt) {
     $email->Receipt($mail->from_address);
@@ -1278,6 +1288,7 @@
       variable_set('simplenews_test_address', $edit['test_address']);
       variable_set('simplenews_time', $edit['time']);
       variable_set('simplenews_from_name', $edit['from_name']);
+      variable_set('simplenews_base64_encode', $edit['base64_encode']);
       //valid_email_address() allows empty address, so check this first
       if ($edit['from_address'] == '') {
         drupal_set_message(t("You have to supply a sender's e-mail address."), 'error');
@@ -1315,6 +1326,8 @@
     }
     $group = form_select(t('Seconds'), 'time', variable_get('simplenews_time', 2), drupal_map_assoc($max_time));
     $output .= form_group(t('Maximum send time'), $group, t('Sets the maximum time in seconds during which newsletters are sent. If not all recipients have been mailed within this time, sending is further handled as a cronjob.').' <br /> '.t('The highest value in the dropdown list is based on max_execution_time in your php.ini file. Note that if not all previous newletters have been sent to all recipients yet, these are sent first.'));
+    $group = form_radios(t('Base64-encode html e-mail'), 'base64_encode', variable_get('simplenews_base64_encode', 0), array(0 => t('Never'), 1 => t('If necessary')));
+    $output .= form_group(t('Html e-mail encoding'), $group, t('If you select %necessary, html e-mail will be base64-encoded if there is at least one line which is longer than 998 characters. You can use this setting if you experience problems with question marks being inserted into your mail because of too long lines', array('%necessary' => theme('placeholder', t('If necessary')))));
   }
   $output .= form_submit(t('Submit'));
   return form($output);
@@ -1487,4 +1500,4 @@
   }
 } 
 
