Reply composition support pre-filled answers.
[banana.git] / banana / banana.inc.php.in
1 <?php
2 /********************************************************************************
3 * banana/banana.inc.php : banana main file
4 * --------------------------
5 *
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
9
10 require_once dirname(__FILE__) . '/text.func.inc.php';
11
12 class Banana
13 {
14
15 #######
16 # Configuration variables
17 #######
18
19 ### General ###
20 static public $profile = Array( 'signature' => '',
21 'headers' => array('From' => 'Anonymous <anonymouse@example.com>'),
22 'display' => 0,
23 'lastnews' => 0,
24 'locale' => 'fr_FR.UTF-8',
25 'subscribe' => array(),
26 'autoup' => 1);
27 static public $boxpattern;
28 static public $withtabs = true;
29 static public $baseurl = null;
30 static public $mimeparts = array();
31
32 ### Spool ###
33 static public $spool_root = '/var/spool/banana';
34 static public $spool_max = 3000;
35 static public $spool_tbefore = 5;
36 static public $spool_tcontext= 10;
37 static public $spool_tmax = 10;
38 static public $spool_boxlist = true;
39
40 ### Tree options ###
41 static public $tree_read = 'dg';
42 static public $tree_unread = 'b';
43
44 ### Message processing ###
45 static public $msgparse_headers = array('content-disposition', 'content-transfer-encoding',
46 'content-type', 'content-id', 'date', 'followup-to',
47 'from', 'message-id', 'newsgroups', 'organization',
48 'references', 'subject', 'x-face', 'in-reply-to',
49 'to', 'cc', 'reply-to');
50
51 ### Message display ###
52 static public $msgshow_headers = array('from', 'newsgroups', 'followup-to', 'to', 'cc', 'reply-to',
53 'organization', 'date');
54 static public $msgshow_mimeparts = array('multipart/report', 'multipart/mixed',
55 'text/html', 'text/plain', 'text/enriched', 'text', 'message');
56 static public $msgshow_xface = true;
57 static public $msgshow_wrap = 80;
58 static public $msgshow_externalimages = false;
59 static public $msgshow_hasextimages = false;
60 static public $msgshow_withthread = true;
61 static public $msgshow_javascript = true;
62
63 static public $msgshow_pgpcheck = true;
64 static public $msgshow_pgppath = 'gpg';
65 static public $msgshow_pgpoptions = '';
66
67 /** Match an url
68 * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/ui")
69 * If it matches, return 3 main parts :
70 * \\1 and \\3 are delimiters
71 * \\2 is the url
72 *
73 * eg : preg_match("!$url_regexp!i", "[http://www.polytechnique.org]", $matches);
74 * $matches[1] = "["
75 * $matches[2] = "http://www.polytechnique.org"
76 * $matches[3] = "]"
77 */
78 static public $msgshow_url = '(["\[\<])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!\:]*[a-z\@0-9~%$£µ&i#\-+=_\/\?]+)+)(["\]\>])?';
79
80 ### Message edition ###
81 static public $msgedit_canattach = true;
82 static public $msgedit_maxfilesize = 100000;
83 /** Global headers to use for messages
84 */
85 static public $msgedit_headers = array('Mime-Version' => '1.0', 'User-Agent' => 'Banana @VERSION@');
86 /** Mime type order for quoting
87 */
88 static public $msgedit_mimeparts = array('multipart/report', 'multipart/mixed', 'text/plain', 'text/enriched', 'text/html', 'text', 'message');
89
90 ### Feed configuration ###
91 static public $feed_active = true;
92 static public $feed_format = 'rss2';
93 static public $feed_updateOnDemand = false; // Update the feed each time sbd check it
94 static public $feed_copyright = null; // Global copyright informations
95 static public $feed_generator = 'Banana @VERSION@'; // Feed generator
96 static public $feed_email = null; // Admin e-mail
97 static public $feed_namePrefix = 'Banana :: ';
98 static public $feed_size = 15; // Number of messages in the feed
99
100 ### Protocole ###
101 /** News serveur to use
102 */
103 static public $nntp_host = 'news://localhost:119/';
104
105 static public $mbox_path = '/var/mail';
106 static public $mbox_helper = './mbox-helper';
107
108 ### Debug ###
109 static public $debug_nntp = false;
110 static public $debug_mbox = false;
111 static public $debug_smarty = false;
112
113
114 #######
115 # Constants
116 #######
117
118 // Actions
119 const ACTION_BOX_NEEDED = 1; // mask
120 const ACTION_BOX_LIST = 2;
121 const ACTION_BOX_SUBS = 4;
122 const ACTION_BOX_FEED = 8;
123 const ACTION_MSG_LIST = 3;
124 const ACTION_MSG_READ = 5;
125 const ACTION_MSG_NEW = 9;
126 const ACTION_MSG_CANCEL = 17;
127 const ACTION_MSG_IMAGES = 33;
128
129 // Box list view
130 const BOXES_ALL = 0;
131 const BOXES_SUB = 1;
132 const BOXES_NEW = 2;
133
134 // Spool view mode
135 const SPOOL_ALL = 0;
136 const SPOOL_UNREAD = 1;
137
138
139 #######
140 # Runtime variables
141 #######
142
143 static public $protocole = null;
144 static public $spool = null;
145 static public $message = null;
146 static public $page = null;
147
148 static public $group = null;
149 static public $artid = null;
150 static public $action = null;
151 static public $part = null;
152 static public $first = null;
153
154 /** Class parameters storage
155 */
156 public $params;
157
158
159 #######
160 # Banana Implementation
161 #######
162
163 /** Build the instance of Banana
164 * This constructor only call \ref loadParams, connect to the server, and build the Smarty page
165 * @param protocole Protocole to use
166 */
167 public function __construct($params = null, $protocole = 'NNTP', $pageclass = 'BananaPage')
168 {
169 if (is_null($params)) {
170 $this->params = $_GET;
171 } else {
172 $this->params = $params;
173 }
174 $this->loadParams();
175
176 // connect to protocole handler
177 $classname = 'Banana' . $protocole;
178 if (!class_exists($classname)) {
179 Banana::load($protocole);
180 }
181 Banana::$protocole = new $classname(Banana::$group);
182
183 // build the page
184 if ($pageclass == 'BananaPage') {
185 Banana::load('page');
186 }
187 Banana::$page = new $pageclass;
188 $types = array('multipart/report' => _b_('Rapport d\'erreur'),
189 'multipart/mixed' => _b_('Composition'),
190 'text/html' => _b_('Texte formaté'),
191 'text/plain' => _b_('Texte brut'),
192 'text/enriched' => _b_('Texte enrichi'),
193 'text' => _b_('Texte'),
194 'message/rfc822' => _b_('Mail'),
195 'message' => _b_('Message'),
196 'source' => _b_('Source'));
197 Banana::$mimeparts = array_merge($types, Banana::$mimeparts);
198 }
199
200 /** Fill state vars (Banana::$group, Banana::$artid, Banana::$action, Banana;:$part, Banana::$first)
201 */
202 protected function loadParams()
203 {
204 foreach ($this->params as &$value) {
205 if ($value === "") {
206 $value = null;
207 }
208 }
209 Banana::$group = isset($this->params['group']) ? $this->params['group'] : null;
210 Banana::$artid = isset($this->params['artid']) ? $this->params['artid'] : null;
211 Banana::$first = isset($this->params['first']) ? $this->params['first'] : null;
212 Banana::$part = isset($this->params['part']) ? $this->params['part'] : 'text';
213
214 $action = @$this->params['action'];
215 if ($action == 'rss' || $action == 'rss2' || $action == 'atom') {
216 if ($action == 'rss') {
217 $action = 'rss2';
218 }
219 Banana::$feed_format = $action;
220 Banana::$action = Banana::ACTION_BOX_FEED;
221 return;
222 }
223
224 // Look for the action to execute
225 if (is_null(Banana::$group)) {
226 if ($action == 'subscribe') {
227 Banana::$action = Banana::ACTION_BOX_SUBS;
228 } else {
229 Banana::$action = Banana::ACTION_BOX_LIST;
230 }
231 return;
232 }
233
234 if (is_null(Banana::$artid)) {
235 if ($action == 'new') {
236 Banana::$action = Banana::ACTION_MSG_NEW;
237 } else {
238 Banana::$action = Banana::ACTION_MSG_LIST;
239 }
240 return;
241 }
242 switch ($action) {
243 case 'new':
244 Banana::$action = Banana::ACTION_MSG_NEW;
245 return;
246 case 'cancel':
247 Banana::$action = Banana::ACTION_MSG_CANCEL;
248 return;
249 case 'showext':
250 Banana::$action = Banana::ACTION_MSG_IMAGES;
251 return;
252 default:
253 Banana::$action = Banana::ACTION_MSG_READ;
254 }
255 }
256
257 /** Run Banana
258 * This function need user profile to be initialised
259 */
260 public function run()
261 {
262 // Configure locales
263 setlocale(LC_ALL, Banana::$profile['locale']);
264
265 // Check if the state is valid
266 if (Banana::$protocole->lastErrNo()) {
267 return Banana::$page->kill(_b_('Une erreur a été rencontrée lors de la connexion au serveur') . '<br />'
268 . Banana::$protocole->lastError());
269 }
270 if (!Banana::$protocole->isValid()) {
271 return Banana::$page->kill(_b_('Connexion non-valide'));
272 }
273 if (Banana::$action & Banana::ACTION_BOX_NEEDED) {
274 if(Banana::$boxpattern && !preg_match('/' . Banana::$boxpattern . '/i', Banana::$group)) {
275 Banana::$page->setPage('group');
276 return Banana::$page->kill(_b_("Ce newsgroup n'existe pas ou vous n'avez pas l'autorisation d'y accéder"));
277 }
278 }
279
280 // Dispatch to the action handlers
281 switch (Banana::$action) {
282 case Banana::ACTION_BOX_SUBS:
283 $error = $this->action_subscribe();
284 break;
285 case Banana::ACTION_BOX_LIST:
286 $error = $this->action_listBoxes();
287 break;
288 case Banana::ACTION_BOX_FEED:
289 $this->action_feed(); // generate its own xml
290 break;
291 case Banana::ACTION_MSG_LIST:
292 $error = $this->action_showThread(Banana::$group, Banana::$first);
293 break;
294 case Banana::ACTION_MSG_IMAGES:
295 Banana::$msgshow_externalimages = true;
296 case Banana::ACTION_MSG_READ:
297 $error = $this->action_showMessage(Banana::$group, Banana::$artid, Banana::$part);
298 break;
299 case Banana::ACTION_MSG_NEW:
300 $error = $this->action_newMessage(Banana::$group, Banana::$artid);
301 break;
302 case Banana::ACTION_MSG_CANCEL:
303 $error = $this->action_cancelMessage(Banana::$group, Banana::$artid);
304 break;
305 default:
306 $error = _b_("L'action demandée n'est pas supportée par Banana");
307 }
308
309 // Generate the page
310 if (is_string($error)) {
311 return Banana::$page->kill($error);
312 }
313 return Banana::$page->run();
314 }
315
316 /** Build and post a new message
317 * @return postid (or -1 if the message has not been found)
318 */
319 public function post($dest, $reply, $subject, $body)
320 {
321 $hdrs = Banana::$protocole->requestedHeaders();
322 $headers = Banana::$profile['headers'];
323 $headers[$hdrs['dest']] = $dest;
324 if ($reply) {
325 $headers[$hdrs['reply']] = $reply;
326 }
327 $headers['Subject'] = $subject;
328 $msg = BananaMessage::newMessage($headers, $body);
329 if (Banana::$protocole->send($msg)) {
330 Banana::$group = ($reply ? $reply : $dest);
331 $this->loadSpool(Banana::$group);
332 return Banana::$spool->getPostId($subject);
333 }
334 return -1;
335 }
336
337 /** Return the CSS code to include in the headers
338 */
339 public function css()
340 {
341 return Banana::$page->css;
342 }
343
344 /** Return the Link to the feed of the page
345 */
346 public function feed()
347 {
348 if (!Banana::$feed_active) {
349 return null;
350 }
351 return Banana::$page->makeURL(array('group' => Banana::$group, 'action' => Banana::$feed_format));
352 }
353
354 /** Return the execution backtrace of the current BananaProtocole
355 */
356 public function backtrace()
357 {
358 if (Banana::$protocole) {
359 return Banana::$protocole->backtrace();
360 }
361 return null;
362 }
363
364 /**************************************************************************/
365 /* actions */
366 /**************************************************************************/
367 protected function action_saveSubs($groups)
368 {
369 Banana::$profile['subscribe'] = $groups;
370 return true;
371 }
372
373 protected function action_subscribe()
374 {
375 Banana::$page->setPage('subscribe');
376 if (isset($_POST['validsubs'])) {
377 $this->action_saveSubs(array_keys($_POST['subscribe']));
378 Banana::$page->redirect();
379 }
380 $groups = Banana::$protocole->getBoxList(Banana::BOXES_ALL);
381 Banana::$page->assign('groups', $groups);
382 return true;
383 }
384
385 protected function action_listBoxes()
386 {
387 Banana::$page->setPage('forums');
388 $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
389 Banana::$page->assign('groups', $groups);
390 if (empty(Banana::$profile['subscribe']) || Banana::$profile['lastnews']) {
391 $newgroups = Banana::$protocole->getBoxList(Banana::BOXES_NEW, Banana::$profile['lastnews'], true);
392 Banana::$page->assign('newgroups', $newgroups);
393 }
394 return true;
395 }
396
397 protected function action_feed()
398 {
399 Banana::load('feed');
400 if (Banana::$group) {
401 if (Banana::$feed_updateOnDemand) {
402 $this->loadSpool(Banana::$group);
403 }
404 $feed =& BananaFeed::getFeed();
405 $feed->toXML();
406 }
407 if (Banana::$profile['subscribe']) {
408 $subfeed = null;
409 foreach (Banana::$profile['subscribe'] as $group) {
410 Banana::$group = $group;
411 if (Banana::$feed_updateOnDemand) {
412 $this->loadSpool($group);
413 }
414 $feed =& BananaFeed::getFeed();
415 $subfeed =& BananaFeed::merge($subfeed, $feed, _b_('Abonnements'), _b_('Mes abonnements Banana'));
416 }
417 $subfeed->toXML();
418 }
419 Banana::$page->feed();
420 }
421
422 protected function action_showThread($group, $first)
423 {
424 Banana::$page->setPage('thread');
425 if (!$this->loadSpool($group)) {
426 return _b_('Impossible charger la liste des messages de ') . $group;
427 }
428 if (Banana::$spool_boxlist) {
429 $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
430 Banana::$page->assign('groups', $groups);
431 }
432 Banana::$page->assign('msgbypage', Banana::$spool_tmax);
433 return true;
434 }
435
436 protected function action_showMessage($group, $artid, $partid = 'text')
437 {
438 Banana::$page->setPage('message');
439 $istext = $partid == 'text' || $partid == 'source'
440 || preg_match('!^[-a-z0-9_]+/[-a-z0-9_]+$!', $partid);
441 if ($istext) {
442 $this->loadSpool($group);
443 }
444 $msg =& $this->loadMessage($group, $artid);
445 if (is_null($msg)) {
446 $this->loadSpool($group);
447 $this->removeMessage($group, $artid);
448 return _b_('Le message demandé n\'existe pas. Il est possible qu\'il ait été annulé');
449 }
450 if ($partid == 'xface') {
451 $msg->getXFace();
452 exit;
453 } elseif (!$istext) {
454 $part = $msg->getPartById($partid);
455 if (!is_null($part)) {
456 $part->send(true);
457 }
458 $part = $msg->getFile($partid);
459 if (!is_null($part)) {
460 $part->send();
461 }
462 exit;
463 } elseif ($partid == 'text') {
464 $partid = null;
465 Banana::$page->assign('body', $msg->getFormattedBody($partid));
466 } elseif ($partid == 'source') {
467 $text = Banana::$protocole->getMessageSource($artid);
468 if (!is_utf8($text)) {
469 $text = utf8_encode($text);
470 }
471 Banana::$page->assign('body', '<pre>' . banana_htmlentities($text) . '</pre>');
472 } else {
473 Banana::$page->assign('body', $msg->getFormattedBody($partid));
474 }
475
476 if (Banana::$profile['autoup']) {
477 Banana::$spool->markAsRead($artid);
478 }
479 if (Banana::$spool_boxlist) {
480 $groups = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
481 Banana::$page->assign('groups', $groups);
482 }
483 if (function_exists('hook_markAsRead')) {
484 hook_markAsRead($group, $artid, $msg);
485 }
486 Banana::$page->assign_by_ref('message', $msg);
487 Banana::$page->assign('extimages', Banana::$msgshow_hasextimages);
488 Banana::$page->assign('headers', Banana::$msgshow_headers);
489 Banana::$page->assign('type', $partid);
490 return true;
491 }
492
493 protected function action_newMessage($group, $artid)
494 {
495 Banana::$page->setPage('new');
496 if (!Banana::$protocole->canSend()) {
497 return _b_('Vous n\'avez pas le droit de poster');
498 }
499 $hdrs = Banana::$protocole->requestedHeaders();
500 $headers = array();
501 foreach ($hdrs as $header) {
502 $headers[$header] = array('name' => BananaMessage::translateHeaderName($header));
503 if (isset(Banana::$profile['headers'][$header])) {
504 $headers[$header]['fixed'] = Banana::$profile['headers'][$header];
505 }
506 }
507 if (isset($_POST['sendmessage'])) {
508 $hdr_values = array();
509 foreach ($hdrs as $header) {
510 $hdr_values[$header] = isset($headers[$header]['fixed']) ? $headers[$header]['fixed'] : @$_POST[$header];
511 if (!is_utf8($hdr_values[$header])) {
512 $hdr_values[$header] = utf8_encode($hdr_values[$header]);
513 }
514 }
515 $values = preg_split('/[,; ]/', $hdr_values[$hdrs['dest']]);
516 $hdr_values[$hdrs['dest']] = preg_replace('/,+/', ',', implode(',', $values));
517 if (!is_null($artid)) {
518 $old =& $this->loadMessage($group, $artid);
519 $hdr_values['References'] = $old->getHeaderValue('references') . ' ' . $old->getHeaderValue('message-id');
520 }
521 $msg = null;
522 if (isset($_POST['body']) && !is_utf8($_POST['body'])) {
523 $_POST['body'] = utf8_encode($_POST['body']);
524 }
525 if (empty($hdr_values['Subject'])) {
526 Banana::$page->trig(_b_('Le message doit avoir un sujet'));
527 } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment']) && $_FILES['attachment']['name']) {
528 $uploaded =& $_FILES['attachment'];
529 if (!is_uploaded_file($uploaded['tmp_name'])) {
530 Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier'));
531 } else {
532 $msg = BananaMessage::newMessage($hdr_values, $_POST['body'], $uploaded);
533 }
534 } else {
535 $msg = BananaMessage::newMessage($hdr_values, $_POST['body']);
536 }
537 if (!is_null($msg)) {
538 if (Banana::$protocole->send($msg)) {
539 $this->loadSpool($group);
540 $newid = Banana::$spool->updateUnread(Banana::$profile['lastnews']);
541 Banana::$page->redirect(array('group' => $group, 'artid' => $newid ? $newid : $artid));
542 } else {
543 Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />'
544 . Banana::$protocole->lastError());
545 $body = $_POST['body'];
546 }
547 }
548 } else {
549 if (!is_null($artid)) {
550 $msg =& $this->loadMessage($group, $artid);
551 $body = $msg->quote();
552
553 if (isset($_POST['reply'])) {
554 $body = explode("\n", $body);
555 $replies = $_POST['reply'];
556 krsort($replies);
557 foreach ($replies as $line => $text) {
558 $text = explode("\n", "\n" . $text . "\n");
559 array_splice($body, $line + 1, 0, $text);
560 }
561 $body = implode("\n", $body);
562 }
563 $body = $msg->getSender() . _b_(' a écrit :') . "\n" . $body;
564
565 $subject = $msg->getHeaderValue('subject');
566 $headers['Subject']['user'] = 'Re: ' . preg_replace("/^re\s*:\s*/i", '', $subject);
567 $target = $msg->getHeaderValue($hdrs['reply']);
568 if (empty($target)) {
569 $target = $group;
570 }
571 $headers[$hdrs['dest']]['user'] =& $target;
572 } else {
573 $body = '';
574 $headers[$hdrs['dest']]['user'] = $group;
575 }
576 if (Banana::$profile['signature']) {
577 $body .= "\n\n-- \n" . Banana::$profile['signature'];
578 }
579 }
580 Banana::$page->assign('body', $body);
581
582 Banana::$page->assign('maxfilesize', Banana::$msgedit_maxfilesize);
583 Banana::$page->assign('can_attach', Banana::$msgedit_canattach);
584 Banana::$page->assign('headers', $headers);
585 return true;
586 }
587
588 protected function action_cancelMessage($group, $artid)
589 {
590 Banana::$page->setPage('cancel');
591 $msg =& $this->loadMessage($group, $artid);
592 if (!$msg->canCancel()) {
593 return _b_('Vous n\'avez pas les droits suffisants pour supprimer ce message');
594 }
595 if (isset($_POST['cancel'])) {
596 $this->loadSpool($group);
597 if (!Banana::$protocole->cancel($msg)) {
598 return _b_('Une erreur s\'est produite lors de l\'annulation du message :') . '<br />'
599 . Banana::$protocole->lastError();
600 }
601 $this->removeMessage($group, $artid);
602 Banana::$page->redirect(Array('group' => $group));
603 }
604
605 Banana::$page->assign_by_ref('message', $msg);
606 Banana::$page->assign('body', $msg->getFormattedBody());
607 Banana::$page->assign('headers', Banana::$msgshow_headers);
608 return true;
609 }
610
611 /**************************************************************************/
612 /* Spoolgen functions */
613 /**************************************************************************/
614
615 private function checkErrors()
616 {
617 if (Banana::$protocole->lastErrno()) {
618 echo "\nL'erreur suivante s'est produite : "
619 . Banana::$protocole->lastErrno() . " "
620 . Banana::$protocole->lastError() . "\n";
621 return false;
622 }
623 return true;
624 }
625
626 static public function createAllSpool(array $protos)
627 {
628 foreach ($protos as $proto) {
629 $banana = new Banana(array(), $proto);
630
631 if (!$banana->checkErrors()) {
632 continue;
633 }
634 $groups = Banana::$protocole->getBoxList();
635 if (!$banana->checkErrors()) {
636 continue;
637 }
638
639 print "** $proto **\n";
640 foreach (array_keys($groups) as $g) {
641 print "Generating spool for $g: ";
642 Banana::$group = $g;
643 $spool = $banana->loadSpool($g);
644 if (!$banana->checkErrors()) {
645 break;
646 }
647 print "done.\n";
648 unset($spool);
649 Banana::$spool = null;
650 }
651 print "\n";
652 }
653 }
654
655 static public function refreshAllFeeds(array $protos)
656 {
657 Banana::load('feed');
658 Banana::$feed_updateOnDemand = true; // In order to force update
659 foreach ($protos as $proto) {
660 $banana = new Banana(array(), $proto);
661
662 if (!$banana->checkErrors()) {
663 continue;
664 }
665 $groups = Banana::$protocole->getBoxList();
666 if (!$banana->checkErrors()) {
667 continue;
668 }
669
670 print "** $proto **\n";
671 foreach (array_keys($groups) as $g) {
672 print "Generating feed cache for $g: ";
673 Banana::$group = $g;
674 $spool = $banana->loadSpool($g);
675 if (!$banana->checkErrors()) {
676 break;
677 }
678 $feed =& BananaFeed::getFeed();
679 print "done.\n";
680 unset($feed);
681 unset($spool);
682 Banana::$spool = null;
683 }
684 print "\n";
685 }
686 }
687
688 /**************************************************************************/
689 /* Private functions */
690 /**************************************************************************/
691
692 protected function loadSpool($group)
693 {
694 Banana::load('spool');
695 if (!Banana::$spool || Banana::$spool->group != $group) {
696 BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup']);
697 Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
698 }
699 return true;
700 }
701
702 protected function &loadMessage($group, $artid)
703 {
704 Banana::load('message');
705 if ($group == @$_SESSION['banana_group'] && $artid == @$_SESSION['banana_artid']
706 && isset($_SESSION['banana_message'])) {
707 $message = unserialize($_SESSION['banana_message']);
708 Banana::$msgshow_headers = $_SESSION['banana_showhdr'];
709 } else {
710 $message = Banana::$protocole->getMessage($artid);
711 $_SESSION['banana_group'] = $group;
712 $_SESSION['banana_artid'] = $artid;
713 $_SESSION['banana_message'] = serialize($message);
714 $_SESSION['banana_showhdr'] = Banana::$msgshow_headers;
715 }
716 Banana::$message =& $message;
717 return $message;
718 }
719
720 protected function removeMessage($group, $artid)
721 {
722 Banana::$spool->delId($artid);
723 if ($group == $_SESSION['banana_group']) {
724 if (!Banana::$profile['display']) {
725 $_SESSION['banana_spool'] = serialize(Banana::$spool);
726 }
727 if ($artid == $_SESSION['banana_artid']) {
728 unset($_SESSION['banana_message']);
729 unset($_SESSION['banana_showhdr']);
730 unset($_SESSION['banana_artid']);
731 }
732 }
733 $this->loadSpool($group);
734 return true;
735 }
736
737 static public function load($file)
738 {
739 $file = strtolower($file) . '.inc.php';
740 if (!@include_once dirname(__FILE__) . "/$file") {
741 require_once $file;
742 }
743 }
744 }
745
746 // vim:set et sw=4 sts=4 ts=4 enc=utf-8:
747 ?>