X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fbanana.inc.php.in;h=8e9d3a700ca642639306e3c8a5e93667a6dfabc6;hb=2a5dba9927b2f16a8ba4250856765ec6fcd85adc;hp=c564a0c3d042a43631f3c9a8e761c55b509ecf93;hpb=ded3974d74b5eacf42932990eed9ba79ef5d2240;p=banana.git diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index c564a0c..8e9d3a7 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -7,45 +7,55 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ +require_once dirname(__FILE__) . '/text.func.inc.php'; + class Banana { - static public $maxspool = 3000; - static public $parse_hdr = array('content-disposition', 'content-transfer-encoding', +####### +# Configuration variables +####### + +### General ### + static public $profile = Array( 'signature' => '', + 'headers' => array('From' => 'Anonymous '), + 'display' => 0, + 'lastnews' => 0, + 'locale' => 'fr_FR.UTF-8', + 'subscribe' => array(), + 'autoup' => 1); + static public $boxpattern; + static public $withtabs = true; + static public $mimeparts = array(); + +### Spool ### + static public $spool_root = '/var/spool/banana'; + static public $spool_max = 3000; + static public $spool_tbefore = 5; + static public $spool_tafter = 5; + static public $spool_tmax = 50; + static public $spool_boxlist = true; + +### Message processing ### + static public $msgparse_headers = array('content-disposition', 'content-transfer-encoding', 'content-type', 'content-id', 'date', 'followup-to', 'from', 'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face', 'in-reply-to', 'to', 'cc', 'reply-to'); - static public $show_hdr = array('from', 'newsgroups', 'followup-to', 'to', 'cc', 'reply-to', - 'organization', 'date', 'references', 'in-reply-to'); - - /** Favorites MIMEtypes to use, by order for reading multipart messages - */ - static public $body_mime = array('text/html', 'text/plain', 'text/enriched', 'text', 'message'); - - /** Indicate wether posting attachment is allowed - */ - static public $can_attach = true; - /** Maximum allowed file size for attachment - */ - static public $maxfilesize = 100000; - /** Indicate wether x-face should be skinned as specials data or not - */ - static public $formatxface = true; - - /** Regexp for selecting newsgroups to show (if empty, match all newsgroups) - * ex : '^xorg\..*' for xorg.* - */ - static public $grp_pattern = null; - static public $tbefore = 5; - static public $tafter = 5; - static public $tmax = 50; +### Message display ### + static public $msgshow_headers = array('from', 'newsgroups', 'followup-to', 'to', 'cc', 'reply-to', + 'organization', 'date', 'references', 'in-reply-to'); + static public $msgshow_mimeparts = array('multipart/report', 'multipart/mixed', + 'text/html', 'text/plain', 'text/enriched', 'text', 'message'); + static public $msgshow_xface = true; + static public $msgshow_wrap = 78; + static public $msgshow_externalimages = false; + static public $msgshow_hasextimages = false; + static public $msgshow_withthread = true; - static public $wrap = 78; - /** Match an url - * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/i") + * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/ui") * If it matches, return 3 main parts : * \\1 and \\3 are delimiters * \\2 is the url @@ -55,37 +65,34 @@ class Banana * $matches[2] = "http://www.polytechnique.org" * $matches[3] = "]" */ - static public $url_regexp = '(["\[])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!]*[a-z\@0-9~%$£µ&i#\-+=_\/\?]+)+)(["\]])?'; + static public $msgshow_url = '(["\[])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!\:]*[a-z\@0-9~%$&i#\-+=_\/\?]+)+)(["\]])?'; +### Message edition ### + static public $msgedit_canattach = true; + static public $msgedit_maxfilesize = 100000; /** Global headers to use for messages */ - static public $custom_hdr = array('Mime-Version' => '1.0', 'User-Agent' => 'Banana @VERSION@'); - - /** News serveur to use + static public $msgedit_headers = array('Mime-Version' => '1.0', 'User-Agent' => 'Banana @VERSION@'); + /** Mime type order for quoting */ - static public $host = 'news://localhost:119/'; + static public $msgedit_mimeparts = array('multipart/report', 'multipart/mixed', 'text/plain', 'text/enriched', 'text/html', 'text', 'message'); - /** User profile +### Protocole ### + /** News serveur to use */ - static public $profile = Array( 'From' => 'Anonymous ', 'sig' => '', - 'Organization' => '', 'custom_hdr' => array(), 'display' => 0, - 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array()); - - static public $protocole = null; - static public $spool = null; - static public $message = null; - static public $page = null; + static public $nntp_host = 'news://localhost:119/'; - static public $group = null; - static public $artid = null; - static public $action = null; - static public $part = null; - static public $first = null; + static public $mbox_path = '/var/mail'; +### Debug ### static public $debug_nntp = false; static public $debug_smarty = false; +####### +# Constants +####### + // Actions const ACTION_BOX_NEEDED = 1; // mask const ACTION_BOX_LIST = 2; @@ -94,6 +101,7 @@ class Banana const ACTION_MSG_READ = 5; const ACTION_MSG_NEW = 9; const ACTION_MSG_CANCEL = 17; + const ACTION_MSG_IMAGES = 33; // Box list view const BOXES_ALL = 0; @@ -104,17 +112,37 @@ class Banana const SPOOL_ALL = 0; const SPOOL_UNREAD = 1; + +####### +# Runtime variables +####### + + static public $protocole = null; + static public $spool = null; + static public $message = null; + static public $page = null; + + static public $group = null; + static public $artid = null; + static public $action = null; + static public $part = null; + static public $first = null; + /** Class parameters storage */ public $params; + +####### +# Banana Implementation +####### + /** Build the instance of Banana * This constructor only call \ref loadParams, connect to the server, and build the Smarty page * @param protocole Protocole to use */ public function __construct($params = null, $protocole = 'NNTP', $pageclass = 'BananaPage') { - Banana::load('text.func'); if (is_null($params)) { $this->params = $_GET; } else { @@ -123,8 +151,10 @@ class Banana $this->loadParams(); // connect to protocole handler - Banana::load($protocole); $classname = 'Banana' . $protocole; + if (!class_exists($classname)) { + Banana::load($protocole); + } Banana::$protocole = new $classname(Banana::$group); // build the page @@ -132,6 +162,16 @@ class Banana Banana::load('page'); } Banana::$page = new $pageclass; + $types = array('multipart/report' => _b_('Rapport d\'erreur'), + 'multipart/mixed' => _b_('Composition'), + 'text/html' => _b_('Texte formaté'), + 'text/plain' => _b_('Texte brut'), + 'text/enriched' => _b_('Texte enrichi'), + 'text' => _b_('Texte'), + 'message/rfc822' => _b_('Mail'), + 'message' => _b_('Message'), + 'source' => _b_('Source')); + Banana::$mimeparts = array_merge($types, Banana::$mimeparts); } /** Fill state vars (Banana::$group, Banana::$artid, Banana::$action, Banana;:$part, Banana::$first) @@ -168,6 +208,9 @@ class Banana case 'cancel': Banana::$action = Banana::ACTION_MSG_CANCEL; return; + case 'showext': + Banana::$action = Banana::ACTION_MSG_IMAGES; + return; default: Banana::$action = Banana::ACTION_MSG_READ; } @@ -183,16 +226,16 @@ class Banana // Check if the state is valid if (Banana::$protocole->lastErrNo()) { - return Banana::$page->kill(_b_('Une erreur a été rencontrée lors de la connexion au serveur') . '
' + return Banana::$page->kill(_b_('Une erreur a été rencontrée lors de la connexion au serveur') . '
' . Banana::$protocole->lastError()); } if (!Banana::$protocole->isValid()) { return Banana::$page->kill(_b_('Connexion non-valide')); } if (Banana::$action & Banana::ACTION_BOX_NEEDED) { - if(isset(Banana::$grp_pattern) && !preg_match('/' . Banana::$grp_pattern . '/', $group)) { + if(Banana::$boxpattern && !preg_match('/' . Banana::$boxpattern . '/i', $group)) { Banana::$page->setPage('group'); - return Banana::$page->kill(_b_("Ce newsgroup n'existe pas ou vous n'avez pas l'autorisation d'y accéder")); + return Banana::$page->kill(_b_("Ce newsgroup n'existe pas ou vous n'avez pas l'autorisation d'y accéder")); } } @@ -207,6 +250,8 @@ class Banana case Banana::ACTION_MSG_LIST: $error = $this->action_showThread(Banana::$group, Banana::$first); break; + case Banana::ACTION_MSG_IMAGES: + Banana::$msgshow_externalimages = true; case Banana::ACTION_MSG_READ: $error = $this->action_showMessage(Banana::$group, Banana::$artid, Banana::$part); break; @@ -217,7 +262,7 @@ class Banana $error = $this->action_cancelMessage(Banana::$group, Banana::$artid); break; default: - $error = _b_("L'action demandée n'est pas supportée par Banana"); + $error = _b_("L'action demandée n'est pas supportée par Banana"); } // Generate the page @@ -227,6 +272,13 @@ class Banana return Banana::$page->run(); } + /** Return the CSS code to include in the headers + */ + public function css() + { + return Banana::$page->css; + } + /**************************************************************************/ /* actions */ /**************************************************************************/ @@ -252,9 +304,11 @@ class Banana { Banana::$page->setPage('forums'); $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true); - $newgroups = Banana::$protocole->getBoxList(Banana::BOXES_NEW, Banana::$profile['lastnews'], true); Banana::$page->assign('groups', $groups); - Banana::$page->assign('newgroups', $newgroups); + if (empty(Banana::$profile['subscribe']) || Banana::$profile['lastnews']) { + $newgroups = Banana::$protocole->getBoxList(Banana::BOXES_NEW, Banana::$profile['lastnews'], true); + Banana::$page->assign('newgroups', $newgroups); + } return true; } @@ -264,28 +318,32 @@ class Banana if (!$this->loadSpool($group)) { return _b_('Impossible charger la liste des messages de ') . $group; } - $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true); - Banana::$page->assign('msgbypage', Banana::$tmax); - Banana::$page->assign('groups', $groups); + if (Banana::$spool_boxlist) { + $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true); + Banana::$page->assign('groups', $groups); + } + Banana::$page->assign('msgbypage', Banana::$spool_tmax); return true; } protected function action_showMessage($group, $artid, $partid = 'text') { Banana::$page->setPage('message'); - if ($partid == 'text') { + $istext = $partid == 'text' || $partid == 'source' + || preg_match('!^[-a-z0-9_]+/[-a-z0-9_]+$!', $partid); + if ($istext) { $this->loadSpool($group); } $msg =& $this->loadMessage($group, $artid); if (is_null($msg)) { $this->loadSpool($group); $this->removeMessage($group, $artid); - return _b_('Le message demandé n\'existe pas. Il est possible qu\'il ait été annulé'); + return _b_('Le message demandé n\'existe pas. Il est possible qu\'il ait été annulé'); } if ($partid == 'xface') { $msg->getXFace(); exit; - } elseif ($partid != 'text') { + } elseif (!$istext) { $part = $msg->getPartById($partid); if (!is_null($part)) { $part->send(true); @@ -295,11 +353,30 @@ class Banana $part->send(); } exit; + } elseif ($partid == 'text') { + $partid = null; + Banana::$page->assign('body', $msg->getFormattedBody($partid)); + } elseif ($partid == 'source') { + $text = Banana::$protocole->getMessageSource($artid); + if (!is_utf8($text)) { + $text = utf8_encode($text); + } + Banana::$page->assign('body', '
' . banana_htmlentities($text) . '
'); + } else { + Banana::$page->assign('body', $msg->getFormattedBody($partid)); } - $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true); - Banana::$page->assign('groups', $groups); + + if (Banana::$profile['autoup']) { + Banana::$spool->markAsRead($artid); + } + if (Banana::$spool_boxlist) { + $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true); + Banana::$page->assign('groups', $groups); + } Banana::$page->assign_by_ref('message', $msg); - Banana::$page->assign('headers', Banana::$show_hdr); + Banana::$page->assign('extimages', Banana::$msgshow_hasextimages); + Banana::$page->assign('headers', Banana::$msgshow_headers); + Banana::$page->assign('type', $partid); return true; } @@ -313,8 +390,8 @@ class Banana $headers = array(); foreach ($hdrs as $header) { $headers[$header] = array('name' => BananaMessage::translateHeaderName($header)); - if (isset(Banana::$profile[$header])) { - $headers[$header]['fixed'] = Banana::$profile[$header]; + if (isset(Banana::$profile['headers'][$header])) { + $headers[$header]['fixed'] = Banana::$profile['headers'][$header]; } } if (isset($_POST['sendmessage'])) { @@ -329,10 +406,10 @@ class Banana $msg = null; if (empty($hdr_values['Subject'])) { Banana::$page->trig(_b_('Le message doit avoir un sujet')); - } elseif (Banana::$can_attach && isset($_FILES['attachment'])) { + } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment'])) { $uploaded = $_FILES['attachment']; if (!is_uploaded_file($uploaded['tmp_name'])) { - Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier')); + Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier')); } else { $msg = BananaMessage::newMessage($hdr_values, $_POST['body'], $uploaded); } @@ -349,7 +426,7 @@ class Banana } else { if (!is_null($artid)) { $msg =& $this->loadMessage($group, $artid); - $body = $msg->getSender() . _b_(' a écrit :') . "\n" . $msg->quote(); + $body = $msg->getSender() . _b_(' a écrit :') . "\n" . $msg->quote(); $subject = $msg->getHeaderValue('subject'); $headers['Subject']['user'] = 'Re: ' . preg_replace("/^re\s*:\s*/i", '', $subject); $target = $msg->getHeaderValue($hdrs['reply']); @@ -361,14 +438,14 @@ class Banana $body = ''; $headers[$hdrs['dest']]['user'] = $group; } - if (Banana::$profile['sig']) { - $body .= "\n\n-- \n" . Banana::$profile['sig']; + if (Banana::$profile['signature']) { + $body .= "\n\n-- \n" . Banana::$profile['signature']; } Banana::$page->assign('body', $body); } - Banana::$page->assign('maxfilesize', Banana::$maxfilesize); - Banana::$page->assign('can_attach', Banana::$can_attach); + Banana::$page->assign('maxfilesize', Banana::$msgedit_maxfilesize); + Banana::$page->assign('can_attach', Banana::$msgedit_canattach); Banana::$page->assign('headers', $headers); return true; } @@ -393,8 +470,54 @@ class Banana $this->removeMessage($group, $artid); Banana::$page->redirect(Array('group' => $group, 'first' => $ndx)); } + Banana::$page->assign_by_ref('message', $msg); + Banana::$page->assign('body', $msg->getFormattedBody()); + Banana::$page->assign('headers', Banana::$msgshow_headers); + return true; + } + + /**************************************************************************/ + /* Spoolgen functions */ + /**************************************************************************/ + + private function checkErrors() + { + if (Banana::$protocole->lastErrno()) { + echo "\nL'erreur suivante s'est produite : " + . Banana::$protocole->lastErrno() . " " + . Banana::$protocole->lastError() . "\n"; + return false; + } return true; + } + + static public function createAllSpool(array $protos) + { + foreach ($protos as $proto) { + $banana = new Banana(array(), $proto); + + if (!$banana->checkErrors()) { + continue; + } + $groups = Banana::$protocole->getBoxList(); + if (!$banana->checkErrors()) { + continue; + } + + print "** $proto **\n"; + foreach (array_keys($groups) as $g) { + print "Generating spool for $g : "; + Banana::$group = $g; + $spool = $banana->loadSpool($g); + if (!$banana->checkErrors()) { + break; + } + print "done.\n"; + unset($spool); + } + print "\n"; + } } /**************************************************************************/ @@ -405,12 +528,14 @@ class Banana { Banana::load('spool'); if (!Banana::$spool || Banana::$spool->group != $group) { - if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) { - Banana::$spool = unserialize($_SESSION['banana_spool']); - } - BananaSpool::getSpool($group, Banana::$profile['lastnews']); + $clean = false; + if ($group != @$_SESSION['banana_group']) { + unset($_SESSION['banana_message']); + unset($_SESSION['banana_artid']); + unset($_SESSION['banana_showhdr']); + } + BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup'] || $clean); $_SESSION['banana_group'] = $group; - $_SESSION['banana_spool'] = serialize(Banana::$spool); Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL); } return true; @@ -422,13 +547,13 @@ class Banana if ($group == @$_SESSION['banana_group'] && $artid == @$_SESSION['banana_artid'] && isset($_SESSION['banana_message'])) { $message = unserialize($_SESSION['banana_message']); - Banana::$show_hdr = $_SESSION['banana_showhdr']; + Banana::$msgshow_headers = $_SESSION['banana_showhdr']; } else { $message = Banana::$protocole->getMessage($artid); $_SESSION['banana_group'] = $group; $_SESSION['banana_artid'] = $artid; $_SESSION['banana_message'] = serialize($message); - $_SESSION['banana_showhdr'] = Banana::$show_hdr; + $_SESSION['banana_showhdr'] = Banana::$msgshow_headers; } Banana::$message =& $message; return $message; @@ -437,13 +562,10 @@ class Banana protected function removeMessage($group, $artid) { Banana::$spool->delId($artid); - if ($group == $_SESSION['banana_group']) { - $_SESSION['banana_spool'] = serialize(Banana::$spool); - if ($artid == $_SESSION['banana_artid']) { - unset($_SESSION['banana_message']); - unset($_SESSION['banana_showhdr']); - unset($_SESSION['banana_artid']); - } + if ($group == $_SESSION['banana_group'] && $artid == $_SESSION['banana_artid']) { + unset($_SESSION['banana_message']); + unset($_SESSION['banana_showhdr']); + unset($_SESSION['banana_artid']); } return true; } @@ -457,5 +579,5 @@ class Banana } } -// vim:set et sw=4 sts=4 ts=4 +// vim:set et sw=4 sts=4 ts=4 enc=utf-8: ?>