Post messages with format=flowed instead of format=fixed
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Fri, 4 May 2007 22:41:59 +0000 (22:41 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:40 +0000 (00:35 +0100)
Remove unused code and fix NNTPCore::getLine

 message.func.inc.php |   17 ++++++++++++++++-
 message.inc.php      |    2 +-
 mimepart.inc.php     |    5 ++++-
 nntpcore.inc.php     |   18 +++---------------
 4 files changed, 24 insertions(+), 18 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@245 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/message.func.inc.php
banana/message.inc.php
banana/mimepart.inc.php
banana/nntpcore.inc.php

index 863ed3a..70b45f9 100644 (file)
@@ -77,7 +77,6 @@ function banana_wordwrap($text, $quote_level = 0)
     if ($quote_level > 0) {
         $length = Banana::$msgshow_wrap - $quote_level - 1;
         return banana_quote(wordwrap($text, $length), $quote_level);
-    
     }
     return wordwrap($text, Banana::$msgshow_wrap);
 }
@@ -98,6 +97,22 @@ function banana_catchFormats($text)
     return preg_replace('/&&&urls&&&/e', 'array_shift($urls[0])', $text);
 }
 
+/** Build a flowed text from plain text
+ */
+function banana_flow($text)
+{
+    $lines = explode("\n", $text);
+    $text  = '';
+    while (!is_null($line = array_shift($lines))) {
+        if ($line != '-- ') {
+            $text .= rtrim(str_replace("\n", " \n", banana_wordwrap($line))) . "\n";
+        } else {
+            $text .= $line . "\n";
+        }
+    }
+    return $text;
+}
+
 // {{{ URL Catcher tools
 
 function banana__cutlink($link)
index 6d2eafe..8acd4a3 100644 (file)
@@ -36,7 +36,7 @@ final class BananaMessage extends BananaMimePart
     {
         $msg = new BananaMessage();
         $msg->msg_headers = $headers;
-        $msg->makeTextPart($body, 'text/plain', '8bits', 'UTF-8', 'fixed');
+        $msg->makeTextPart($body, 'text/plain', '8bits', 'UTF-8', 'flowed');
         if (!is_null($file)) {
             $msg->addAttachment($file);
         }
index 81a593a..e57cb6a 100644 (file)
@@ -362,7 +362,8 @@ class BananaMimePart
         $headers['Content-Type'] = $this->content_type . ";"
             . ($this->filename ? " name=\"{$this->filename}\";" : '')
             . ($this->charset ? " charset=\"{$this->charset}\";" : '')
-            . ($this->boundary ? " boundary=\"{$this->boundary}\";" : "");
+            . ($this->boundary ? " boundary=\"{$this->boundary}\";" : "")
+            . ($this->format ? " format={$this->format}" : "");
         if ($this->encoding) {
             $headers['Content-Transfer-Encoding'] = $this->encoding;
         }
@@ -401,6 +402,8 @@ class BananaMimePart
                 $content .= "\n--{$this->boundary}\n" . $part->get(true);
             }
             $content .= "\n--{$this->boundary}--";
+        } elseif ($this->isType('text', 'plain')) {
+            $content .= banana_flow($this->body);
         } else {
             $content .= banana_wordwrap($this->body);
         }
index 0a1f3c1..ff82ab8 100644 (file)
@@ -98,29 +98,17 @@ class BananaNNTPCore
      */
     private function getLine()
     {
-        return rtrim(@fgets($this->ns, 1200));
+        return rtrim(@fgets($this->ns, 1200), "\r\n");
     }
 
     /** fetch data (and on delimitor)
      * @param STRING $delim string indicating and of transmission
      */
-    private function fetchResult($callback = null)
+    private function fetchResult()
     {
         $array = Array();
         while (($result = $this->getLine()) != '.') {
-            if (!is_null($callback)) {
-                list($key, $result) = call_user_func($callback, $result);
-                if (is_null($result)) {
-                    continue;
-                }
-                if (is_null($key)) {
-                    $array[] = $result;
-                } else {
-                    $array[$key] = $result;
-                }
-            } else {
-                $array[] = $result;
-            }
+            $array[] = $result;
         }
         if ($this->debug && $this->bt) {
             $this->bt[count($this->bt) - 1]['response'] = count($array);