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 |
13 | class NNTPPost { |
e785d91c |
14 | /** headers */ |
15 | var $headers; |
16 | /** body */ |
17 | var $body; |
1eed39ee |
18 | |
e785d91c |
19 | /** constructor |
20 | * @param $_nntp RESOURCE handle to NNTP socket |
21 | * @param $_id STRING MSGNUM or MSGID (a group should be selected in this case) |
22 | */ |
23 | function NNTPPost(&$_nntp, $_id) { |
24 | $this->headers = new headers($_nntp, $_id); |
25 | if (!$this->headers) { |
26 | $this = null; |
27 | return false; |
28 | } |
29 | $this->body = join("\n", $_nntp->body($_id)); |
30 | if (isset($this->headers->contentencoding) && preg_match("/base64/", $this->headers->contentencoding)) { |
31 | $this->body = base64_decode($this->body); |
32 | } |
33 | if (isset($this->headers->contentencoding) && preg_match("/quoted-printable/", $this->headers->contentencoding)) { |
34 | $this->body = quoted_printable_decode($this->body); |
35 | } |
36 | if (preg_match('!charset=([^;]*);!', $this->headers->contenttype, $matches)) { |
37 | $this->body = iconv($matches[1], 'iso-8859-1', $this->body); |
38 | } |
1eed39ee |
39 | } |
1eed39ee |
40 | } |
41 | |
42 | /** class for headers |
43 | */ |
44 | |
45 | class Headers { |
e785d91c |
46 | /** MSGNUM : *local* spool id */ |
47 | var $nb; // numéro du post |
48 | /** MSGID : Message-ID */ |
49 | var $msgid; // Message-ID |
50 | /** From header */ |
51 | var $from; // From |
52 | /** Name (if present in From header) */ |
53 | var $name; |
54 | /** Mail (in From header) */ |
55 | var $mail; |
56 | /** Subject header */ |
57 | var $subject; // Subject |
58 | /** Newsgroup¨ header */ |
59 | var $newsgroups; // Newsgroups |
60 | /** Followup-To header */ |
61 | var $followup; |
62 | /** Content-Type header */ |
63 | var $contenttype; |
64 | /** Content-Transfer-Encoding header */ |
65 | var $contentencoding; |
66 | /** Date header */ |
67 | var $date; |
68 | /** Organization header */ |
69 | var $organization; |
70 | /** References header */ |
71 | var $references; |
1eed39ee |
72 | |
e785d91c |
73 | /** constructor |
74 | * @param $_nntp RESOURCE handle to NNTP socket |
75 | * @param $_id STRING MSGNUM or MSGID |
76 | */ |
77 | |
78 | function headers(&$_nntp, $_id) { |
79 | global $news; |
80 | $hdrs = $_nntp->head($_id); |
81 | if (!$hdrs) { |
82 | $this = null; |
83 | return false; |
84 | } |
85 | // parse headers |
86 | foreach ($hdrs as $line) { |
87 | if (preg_match("/^[\t\r ]+/", $line)) { |
88 | $line = ($lasthdr=="X-Face"?"":" ").ltrim($line); |
89 | if (in_array($lasthdr, array_keys($news['head']))) { |
90 | $this->{$news['head'][$lasthdr]} .= $line; |
91 | } |
92 | } else { |
93 | list($hdr, $val) = split(":[ \t\r]*", $line, 2); |
94 | if (in_array($hdr, array_keys($news['head']))) { |
95 | $this->{$news['head'][$hdr]} = $val; |
96 | } |
97 | $lasthdr = $hdr; |
98 | } |
99 | } |
100 | // decode headers |
101 | foreach ($news['hdecode'] as $hdr) { |
102 | if (isset($this->$hdr)) { |
103 | $this->$hdr = headerDecode($this->$hdr); |
104 | } |
105 | } |
106 | // sets name and mail |
107 | $this->name = $this->from; |
108 | $this->mail = $this->from; |
109 | if (preg_match("/(.*)<(.*)@(.*)>/", $val, $match)) { |
110 | $this->name = str_replace("\"", "", trim($match[1])); |
111 | $this->mail = $match[2]."@".$match[3]; |
112 | } |
113 | if (preg_match("/([\w\.]+)@([\w\.]+) \((.*)\)/", $val, $match)) { |
114 | $this->name = trim($match[3]); |
115 | $this->mail = $match[1]."@".$match[2]; |
116 | } |
117 | $this->nb = $_id; |
118 | $retour->numerr = 0; |
1eed39ee |
119 | } |
1eed39ee |
120 | } |
121 | |
122 | ?> |