config.inc.php is now a REAL file of the package
[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
d4c19591 13class BananaPost
14{
01681efd 15 var $nb;
e785d91c 16 /** headers */
17 var $headers;
18 /** body */
19 var $body;
01681efd 20 /** poster name */
21 var $name;
1eed39ee 22
e785d91c 23 /** constructor
24 * @param $_nntp RESOURCE handle to NNTP socket
25 * @param $_id STRING MSGNUM or MSGID (a group should be selected in this case)
26 */
d4c19591 27 function BananaPost(&$_nntp, $_id)
28 {
01681efd 29 $this->nb = $_id;
30 $this->_header($_nntp);
31
e785d91c 32 $this->body = join("\n", $_nntp->body($_id));
01681efd 33
34 if (isset($this->headers['content-transfer-encoding'])) {
35 if (preg_match("/base64/", $this->headers['content-transfer-encoding'])) {
36 $this->body = base64_decode($this->body);
37 } elseif (preg_match("/quoted-printable/", $this->headers['content-transfer-encoding'])) {
38 $this->body = quoted_printable_decode($this->body);
39 }
e785d91c 40 }
01681efd 41
42 if (preg_match('!charset=([^;]*);!', $this->headers['content-type'], $matches)) {
e785d91c 43 $this->body = iconv($matches[1], 'iso-8859-1', $this->body);
44 }
1eed39ee 45 }
1eed39ee 46
01681efd 47 function _header(&$_nntp)
48 {
e785d91c 49 global $news;
01681efd 50 $hdrs = $_nntp->head($this->nb);
e785d91c 51 if (!$hdrs) {
52 $this = null;
53 return false;
54 }
01681efd 55
e785d91c 56 // parse headers
57 foreach ($hdrs as $line) {
58 if (preg_match("/^[\t\r ]+/", $line)) {
01681efd 59 $line = ($hdr=="X-Face"?"":" ").ltrim($line);
60 if (in_array($hdr, $news['head'])) {
61 $this->headers[$hdr] .= $line;
e785d91c 62 }
63 } else {
64 list($hdr, $val) = split(":[ \t\r]*", $line, 2);
01681efd 65 $hdr = strtolower($hdr);
66 if (in_array($hdr, $news['head'])) {
67 $this->headers[$hdr] = $val;
e785d91c 68 }
e785d91c 69 }
70 }
71 // decode headers
72 foreach ($news['hdecode'] as $hdr) {
01681efd 73 if (isset($this->headers[$hdr])) {
74 $this->headers[$hdr] = headerDecode($this->headers[$hdr]);
e785d91c 75 }
76 }
01681efd 77
78 $this->name = $this->headers['from'];
79 $this->name = preg_replace('/<[^ ]*>/', '', $this->name);
80 $this->name = trim($this->name);
1eed39ee 81 }
1eed39ee 82}
83
84?>