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