From 3790508c2003255c179b6f4d309d5feeaa2b6299 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 10 Apr 2008 07:58:55 -0400
Subject: [PATCH] - removed lines wrapping

---
 program/steps/mail/sendmail.inc |   73 +++++++++++++++++++++++++++++-------
 1 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 6f4744d..5466d71 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -10,7 +10,7 @@
  |                                                                       |
  | PURPOSE:                                                              |
  |   Compose a new mail message with all headers and attachments         |
- |   and send it using IlohaMail's SMTP methods or with PHP mail()       |
+ |   and send it using the PEAR::Net_SMTP class or with PHP mail()       |
  |                                                                       |
  +-----------------------------------------------------------------------+
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
@@ -129,7 +129,7 @@
 /****** check submission and compose message ********/
 
 
-if (!$savedraft && empty($_POST['_to']) && empty($_POST['_subject']) && $_POST['_message'])
+if (!$savedraft && empty($_POST['_to']) && empty($_POST['_cc']) && empty($_POST['_bcc']) && empty($_POST['_subject']) && $_POST['_message'])
   {
   $OUTPUT->show_message("sendingfailed", 'error');
   $OUTPUT->send('iframe');
@@ -146,13 +146,19 @@
 
 // replace new lines and strip ending ', '
 $mailto = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset));
+$mailcc = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset));
+$mailbcc = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset));
 
-// decode address strings
-$to_address_arr = $IMAP->decode_address_list($mailto);
+if (empty($mailto) && !empty($mailcc)) {
+  $mailto = $mailcc;
+  $mailcc = null;
+}
+else if (empty($mailto))
+  $mailto = 'undisclosed-recipients:;';
+
+// get sender name and address
 $identity_arr = rcmail_get_identity(get_input_value('_from', RCUBE_INPUT_POST));
-
 $from = $identity_arr['mailto'];
-$first_to = is_array($to_address_arr[0]) ? $to_address_arr[0]['mailto'] : $mailto;
 
 if (empty($identity_arr['string']))
   $identity_arr['string'] = $from;
@@ -163,11 +169,11 @@
                  'To'   => $mailto);
 
 // additional recipients
-if (!empty($_POST['_cc']))
-  $headers['Cc'] = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset));
+if (!empty($mailcc))
+  $headers['Cc'] = $mailcc;
 
-if (!empty($_POST['_bcc']))
-  $headers['Bcc'] = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset));
+if (!empty($mailbcc))
+  $headers['Bcc'] = $mailbcc;
   
 if (!empty($identity_arr['bcc']))
   $headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc'];
@@ -204,6 +210,16 @@
   }
 
 // additional headers
+if ($CONFIG['http_received_header'])
+{
+  $nldlm = rcmail_header_delm() . "\t";
+  $headers['Received'] =  wordwrap('from ' . (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ?
+      gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']).' ['.$_SERVER['HTTP_X_FORWARDED_FOR'].']'.$nldlm.' via ' : '') .
+    gethostbyaddr($_SERVER['REMOTE_ADDR']).' ['.$_SERVER['REMOTE_ADDR'].']'.$nldlm.'with ' .
+    $_SERVER['SERVER_PROTOCOL'].' ('.$_SERVER['REQUEST_METHOD'].'); ' . date('r'),
+    69, $nldlm);
+}
+
 $headers['Message-ID'] = $message_id;
 $headers['X-Sender'] = $from;
 
@@ -233,7 +249,12 @@
   // add a plain text version of the e-mail as an alternative part.
   $h2t = new html2text($message_body);
   $plainTextPart = wordwrap($h2t->get_text(), 998, "\r\n", true);
-  $MAIL_MIME->setTXTBody($plainTextPart);
+  if (!strlen($plainTextPart)) 
+    { 
+    // empty message body breaks attachment handling in drafts 
+    $plainTextPart = "\r\n"; 
+    }
+  $MAIL_MIME->setTXTBody(html_entity_decode($plainTextPart, ENT_COMPAT, 'utf-8'));
 
   // look for "emoticon" images from TinyMCE and copy into message as attachments
   rcmail_attach_emoticons($MAIL_MIME);
@@ -242,14 +263,39 @@
   {
   $message_body = wordwrap($message_body, 75, "\r\n");
   $message_body = wordwrap($message_body, 998, "\r\n", true);
+  if (!strlen($message_body))  
+    { 
+    // empty message body breaks attachment handling in drafts 
+    $message_body = "\r\n"; 
+    } 
   $MAIL_MIME->setTXTBody($message_body, FALSE, TRUE);
   }
 
 
 // add stored attachments, if any
 if (is_array($_SESSION['compose']['attachments']))
-  foreach ($_SESSION['compose']['attachments'] as $attachment)
-    $MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], true, 'base64', 'attachment', $message_charset);
+  foreach ($_SESSION['compose']['attachments'] as $id => $attachment)
+  {
+    $dispurl = '/\ssrc\s*=\s*[\'"]?\S+display-attachment\S+file=rcmfile' . $id . '[\'"]?/';
+    $match = preg_match($dispurl, $message_body);
+    if ($isHtml && ($match > 0))
+    {
+      $message_body = preg_replace($dispurl, ' src="'.$attachment['name'].'"', $message_body);
+      $MAIL_MIME->setHTMLBody($message_body);
+      $MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name']);
+    }
+    else
+    {
+      /*
+        We need to replace mime_content_type in a later release because the function
+        is deprecated in favour of File_Info
+      */
+      $MAIL_MIME->addAttachment($attachment['path'],
+        rc_mime_content_type($attachment['path'], $attachment['mimetype']),
+        $attachment['name'], true, 'base64',
+        'attachment', $message_charset);
+    }
+  }
 
 // add submitted attachments
 if (is_array($_FILES['_attachments']['tmp_name']))
@@ -381,6 +427,5 @@
   $OUTPUT->command('sent_successfully', rcube_label('messagesent'));
   $OUTPUT->send('iframe');
   }
-
 
 ?>

--
Gitblit v1.9.1