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