old header were to complicated for nothin. drop class Header, and treat it from Post
[banana.git] / include / post.inc.php
1 <?php
2 /********************************************************************************
3 * include/posts.inc.php : class for posts
4 * -----------------------
5 *
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
9
10 /** class for posts
11 */
12
13 class NNTPPost {
14 var $nb;
15 /** headers */
16 var $headers;
17 /** body */
18 var $body;
19 /** poster name */
20 var $name;
21
22 /** constructor
23 * @param $_nntp RESOURCE handle to NNTP socket
24 * @param $_id STRING MSGNUM or MSGID (a group should be selected in this case)
25 */
26 function NNTPPost(&$_nntp, $_id) {
27 $this->nb = $_id;
28 $this->_header($_nntp);
29
30 $this->body = join("\n", $_nntp->body($_id));
31
32 if (isset($this->headers['content-transfer-encoding'])) {
33 if (preg_match("/base64/", $this->headers['content-transfer-encoding'])) {
34 $this->body = base64_decode($this->body);
35 } elseif (preg_match("/quoted-printable/", $this->headers['content-transfer-encoding'])) {
36 $this->body = quoted_printable_decode($this->body);
37 }
38 }
39
40 if (preg_match('!charset=([^;]*);!', $this->headers['content-type'], $matches)) {
41 $this->body = iconv($matches[1], 'iso-8859-1', $this->body);
42 }
43 }
44
45 function _header(&$_nntp)
46 {
47 global $news;
48 $hdrs = $_nntp->head($this->nb);
49 if (!$hdrs) {
50 $this = null;
51 return false;
52 }
53
54 $this->nb = $_id;
55 // parse headers
56 foreach ($hdrs as $line) {
57 if (preg_match("/^[\t\r ]+/", $line)) {
58 $line = ($hdr=="X-Face"?"":" ").ltrim($line);
59 if (in_array($hdr, $news['head'])) {
60 $this->headers[$hdr] .= $line;
61 }
62 } else {
63 list($hdr, $val) = split(":[ \t\r]*", $line, 2);
64 $hdr = strtolower($hdr);
65 if (in_array($hdr, $news['head'])) {
66 $this->headers[$hdr] = $val;
67 }
68 }
69 }
70 // decode headers
71 foreach ($news['hdecode'] as $hdr) {
72 if (isset($this->headers[$hdr])) {
73 $this->headers[$hdr] = headerDecode($this->headers[$hdr]);
74 }
75 }
76
77 $this->name = $this->headers['from'];
78 $this->name = preg_replace('/<[^ ]*>/', '', $this->name);
79 $this->name = trim($this->name);
80 }
81 }
82
83 ?>