old header were to complicated for nothin. drop class Header, and treat it from Post
[banana.git] / include / post.inc.php
CommitLineData
1eed39ee 1<?php
1eed39ee 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
4ee663c5 13class NNTPPost {
01681efd 14 var $nb;
e785d91c 15 /** headers */
16 var $headers;
17 /** body */
18 var $body;
01681efd 19 /** poster name */
20 var $name;
1eed39ee 21
e785d91c 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) {
01681efd 27 $this->nb = $_id;
28 $this->_header($_nntp);
29
e785d91c 30 $this->body = join("\n", $_nntp->body($_id));
01681efd 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 }
e785d91c 38 }
01681efd 39
40 if (preg_match('!charset=([^;]*);!', $this->headers['content-type'], $matches)) {
e785d91c 41 $this->body = iconv($matches[1], 'iso-8859-1', $this->body);
42 }
1eed39ee 43 }
1eed39ee 44
01681efd 45 function _header(&$_nntp)
46 {
e785d91c 47 global $news;
01681efd 48 $hdrs = $_nntp->head($this->nb);
e785d91c 49 if (!$hdrs) {
50 $this = null;
51 return false;
52 }
01681efd 53
54 $this->nb = $_id;
e785d91c 55 // parse headers
56 foreach ($hdrs as $line) {
57 if (preg_match("/^[\t\r ]+/", $line)) {
01681efd 58 $line = ($hdr=="X-Face"?"":" ").ltrim($line);
59 if (in_array($hdr, $news['head'])) {
60 $this->headers[$hdr] .= $line;
e785d91c 61 }
62 } else {
63 list($hdr, $val) = split(":[ \t\r]*", $line, 2);
01681efd 64 $hdr = strtolower($hdr);
65 if (in_array($hdr, $news['head'])) {
66 $this->headers[$hdr] = $val;
e785d91c 67 }
e785d91c 68 }
69 }
70 // decode headers
71 foreach ($news['hdecode'] as $hdr) {
01681efd 72 if (isset($this->headers[$hdr])) {
73 $this->headers[$hdr] = headerDecode($this->headers[$hdr]);
e785d91c 74 }
75 }
01681efd 76
77 $this->name = $this->headers['from'];
78 $this->name = preg_replace('/<[^ ]*>/', '', $this->name);
79 $this->name = trim($this->name);
1eed39ee 80 }
1eed39ee 81}
82
83?>