ridiculous f**c**ng bugfix
[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
13class Post {
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 }
4491aea0 29 $this->body = join("\n",$_nntp->body($_id));
1eed39ee 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 }
1eed39ee 38 }
39}
40
41/** class for headers
42 */
43
44class Headers {
45 /** MSGNUM : *local* spool id */
46 var $nb; // numéro du post
47 /** MSGID : Message-ID */
48 var $msgid; // Message-ID
49 /** From header */
50 var $from; // From
51 /** Name (if present in From header) */
52 var $name;
53 /** Mail (in From header) */
54 var $mail;
55 /** Subject header */
56 var $subject; // Subject
57 /** Newsgroup¨ header */
58 var $newsgroups; // Newsgroups
59 /** Followup-To header */
60 var $followup;
61 /** Content-Type header */
62 var $contenttype;
63 /** Content-Transfer-Encoding header */
64 var $contentencoding;
65 /** Date header */
66 var $date;
67 /** Organization header */
68 var $organization;
69 /** References header */
70 var $references;
71
72 /** constructor
73 * @param $_nntp RESOURCE handle to NNTP socket
74 * @param $_id STRING MSGNUM or MSGID
75 */
76
77 function headers(&$_nntp,$_id) {
78 global $news;
79 $hdrs = $_nntp->head($_id);
80 if (!$hdrs) {
81 $this = false;
82 return false;
83 }
84 // parse headers
85 foreach ($hdrs as $line) {
86 if (preg_match("/^[\t\r ]+/",$line)) {
87 $line = ($lasthdr=="X-Face"?"":" ").ltrim($line);
88 if (in_array($lasthdr,array_keys($news['head'])))
89 $this->{$news['head'][$lasthdr]} .= $line;
90 } else {
91 list($hdr,$val) = split(":[ \t\r]*",$line,2);
92 if (in_array($hdr,array_keys($news['head'])))
93 $this->{$news['head'][$hdr]} = $val;
94 $lasthdr = $hdr;
95 }
96 }
97 // decode headers
98 foreach ($news['hdecode'] as $hdr) {
99 if (isset($this->$hdr)) {
100 $this->$hdr = headerDecode($this->$hdr);
101 }
102 }
103 // sets name and mail
104 $this->name = $this->from;
105 $this->mail = $this->from;
106 if (preg_match("/(.*)<(.*)@(.*)>/",$val,$match)) {
107 $this->name = str_replace("\"","",trim($match[1]));
108 $this->mail = $match[2]."@".$match[3];
109 }
110 if (preg_match("/([\w\.]+)@([\w\.]+) \((.*)\)/",$val,$match)) {
111 $this->name = trim($match[3]);
112 $this->mail = $match[1]."@".$match[2];
113 }
5c33c608 114 $this->nb=$_id;
1eed39ee 115 $retour->numerr=0;
116 }
117}
118
119?>