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