From 168e9acb2de6b838200ed647c055cdb423dfb353 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Fri, 4 May 2007 22:41:59 +0000 Subject: [PATCH] Post messages with format=flowed instead of format=fixed 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 | 17 ++++++++++++++++- banana/message.inc.php | 2 +- banana/mimepart.inc.php | 5 ++++- banana/nntpcore.inc.php | 18 +++--------------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/banana/message.func.inc.php b/banana/message.func.inc.php index 863ed3a..70b45f9 100644 --- a/banana/message.func.inc.php +++ b/banana/message.func.inc.php @@ -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) diff --git a/banana/message.inc.php b/banana/message.inc.php index 6d2eafe..8acd4a3 100644 --- a/banana/message.inc.php +++ b/banana/message.inc.php @@ -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); } diff --git a/banana/mimepart.inc.php b/banana/mimepart.inc.php index 81a593a..e57cb6a 100644 --- a/banana/mimepart.inc.php +++ b/banana/mimepart.inc.php @@ -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); } diff --git a/banana/nntpcore.inc.php b/banana/nntpcore.inc.php index 0a1f3c1..ff82ab8 100644 --- a/banana/nntpcore.inc.php +++ b/banana/nntpcore.inc.php @@ -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); -- 2.1.4