Add by-account monitoring
[platal.git] / include / banana / ml.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 require_once 'banana/banana.inc.php';
23 require_once 'banana/hooks.inc.php';
24
25 function hook_makeLink($params)
26 {
27 global $globals, $platal;
28 $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives/' . MLBanana::$listname;
29 $base = $base . hook_platalMessageLink($params);
30 if (@$params['action'] == 'showext') {
31 $base .= '?action=showext';
32 }
33 return $base;
34 }
35
36 class MLBanana extends Banana
37 {
38 static public $listname;
39 static public $domain;
40
41 function __construct($params = null)
42 {
43 global $globals;
44 Banana::$spool_root = $globals->banana->spool_root;
45 Banana::$spool_boxlist = false;
46 Banana::$msgedit_canattach = true;
47 Banana::$debug_mbox = ($globals->debug & 1);
48 Banana::$mbox_helper = $globals->banana->mbox_helper;
49 if (S::has_perms()) {
50 Banana::$msgshow_mimeparts[] = 'source';
51 }
52 array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
53
54 MLBanana::$listname = $params['listname'];
55 MLBanana::$domain = $params['domain'];
56 $params['group'] = $params['listname'] . '@' . $params['domain'];
57 parent::__construct($params, 'MLArchive');
58 }
59
60 public function run()
61 {
62 global $platal, $globals;
63
64 $nom = S::v('prenom') . ' ' . S::v('nom');
65 $mail = S::v('bestalias') . '@' . $globals->mail->domain;
66 $sig = $nom . ' (' . S::v('promo') . ')';
67 Banana::$msgedit_headers['X-Org-Mail'] = S::v('forlife') . '@' . $globals->mail->domain;
68
69 // Build user profile
70 Banana::$profile['headers']['From'] = "$nom <$mail>";
71 Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
72 Banana::$profile['signature'] = $sig;
73
74 // Page design
75 Banana::$page->killPage('forums');
76 Banana::$page->killPage('subscribe');
77
78 // Run Banana
79 return parent::run();
80 }
81 }
82
83 require_once('banana/mbox.inc.php');
84
85 class BananaMLArchive extends BananaMBox
86 {
87 public function name()
88 {
89 return 'MLArchives';
90 }
91
92 public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false)
93 {
94 global $globals;
95 $spool = $globals->lists->spool . '/';
96 $list = glob($spool . '*.mbox', GLOB_ONLYDIR);
97 if ($list === false) {
98 return array();
99 }
100 $groups = array();
101 foreach ($list as $path) {
102 $path = substr($path, strlen($spool));
103 $path = substr($path, 0, -5);
104 list($domain, $listname) = explode($globals->lists->vhost_sep, $path, 2);
105 $group = $listname . '@' . $domain;
106 $groups[$group] = array('desc' => null, 'msgnum' => null, 'unread' => null);
107 }
108 return $groups;
109 }
110
111 public function filename()
112 {
113 if (MLBanana::$listname) {
114 $listname = MLBanana::$listname;
115 $domain = MLBanana::$domain;
116 } else {
117 list($listname, $domain) = explode('@', Banana::$group);
118 }
119 return $domain . '_' . $listname;
120 }
121
122 protected function getFileName()
123 {
124 global $globals;
125 $base = $globals->lists->spool;
126 if (MLBanana::$listname) {
127 $listname = MLBanana::$listname;
128 $domain = MLBanana::$domain;
129 } else {
130 list($listname, $domain) = explode('@', Banana::$group);
131 }
132 $file = $domain . $globals->lists->vhost_sep . $listname . '.mbox';
133 return "$base/$file/$file";
134 }
135 }
136
137 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
138 ?>