[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 if (!defined('e107_INIT')) { exit; } 3 // $Id: pop3_class.php,v 1.3 2006/07/12 07:41:44 e107coders Exp $ 4 // Main ReciveMail Class File - Version 1.0 (01-03-2006) 5 /* 6 * File: recivemail.class.php 7 * Description: Reciving mail With Attechment 8 * Version: 1.0 9 * Created: 01-03-2006 10 * Author: Mitul Koradia 11 * Email: mitulkoradia@gmail.com 12 * Cell : +91 9879697592 13 14 Modified by CaMer0n (www.e107coders.org) 15 16 */ 17 class receiveMail 18 { 19 var $server=''; 20 var $username=''; 21 var $password=''; 22 23 var $marubox=''; 24 25 var $email=''; 26 27 function receiveMail($username,$password,$EmailAddress,$mailserver='localhost',$servertype='pop',$port='110') //Constructure 28 { 29 if($servertype=='imap') 30 { 31 if($port=='') $port='143'; 32 $strConnect='{'.$mailserver.':'.$port. '}INBOX'; 33 } 34 else 35 { 36 $strConnect='{'.$mailserver.':'.$port. '/pop3}INBOX'; 37 } 38 $this->server = $strConnect; 39 $this->username = $username; 40 $this->password = $password; 41 $this->email = $EmailAddress; 42 } 43 function connect() //Connect To the Mail Box 44 { 45 $this->marubox=imap_open($this->server,$this->username,$this->password); 46 } 47 48 function getHeaders($mid) // Get Header info 49 { 50 $mail_header=imap_header($this->marubox,$mid); 51 $sender=$mail_header->from[0]; 52 $sender_replyto=$mail_header->reply_to[0]; 53 $stat = (strtolower($sender->mailbox)!='mailer-daemon' && strtolower($sender->mailbox)!='postmaster') ? FALSE : TRUE; 54 if(strpos($mail_header->subject,"delayed")){ 55 $stat = FALSE; 56 } 57 $mail_details=array( 58 'from'=>strtolower($sender->mailbox).'@'.$sender->host, 59 'fromName'=>$sender->personal, 60 'toOth'=>strtolower($sender_replyto->mailbox).'@'.$sender_replyto->host, 61 'toNameOth'=>$sender_replyto->personal, 62 'subject'=>$mail_header->subject, 63 'to'=>strtolower($mail_header->toaddress), 64 'bounce'=>$stat, 65 'date'=>$mail_header->date 66 ); 67 68 return $mail_details; 69 } 70 function get_mime_type(&$structure) //Get Mime type Internal Private Use 71 { 72 $primary_mime_type = array("TEXT", "MULTIPART", "MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER"); 73 74 if($structure->subtype) { 75 return $primary_mime_type[(int) $structure->type] . '/' . $structure->subtype; 76 } 77 return "TEXT/PLAIN"; 78 } 79 function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false) //Get Part Of Message Internal Private Use 80 { 81 if(!$structure) { 82 $structure = imap_fetchstructure($stream, $msg_number); 83 } 84 if($structure) { 85 if($mime_type == $this->get_mime_type($structure)) 86 { 87 if(!$part_number) 88 { 89 $part_number = "1"; 90 } 91 $text = imap_fetchbody($stream, $msg_number, $part_number); 92 if($structure->encoding == 3) 93 { 94 return imap_base64($text); 95 } 96 else if($structure->encoding == 4) 97 { 98 return imap_qprint($text); 99 } 100 else 101 { 102 return $text; 103 } 104 } 105 if($structure->type == 1) /* multipart */ 106 { 107 while(list($index, $sub_structure) = each($structure->parts)) 108 { 109 if($part_number) 110 { 111 $prefix = $part_number . '.'; 112 } 113 $data = $this->get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1)); 114 if($data) 115 { 116 return $data; 117 } 118 } 119 } 120 } 121 return false; 122 } 123 function getTotalMails() //Get Total Number off Unread Email In Mailbox 124 { 125 $headers=imap_headers($this->marubox); 126 return count($headers); 127 } 128 function GetAttach($mid,$path) // Get Atteced File from Mail 129 { 130 $struckture = imap_fetchstructure($this->marubox,$mid); 131 $ar=""; 132 foreach($struckture->parts as $key => $value) 133 { 134 $enc=$struckture->parts[$key]->encoding; 135 if($struckture->parts[$key]->ifdparameters) 136 { 137 $name=$struckture->parts[$key]->dparameters[0]->value; 138 $message = imap_fetchbody($this->marubox,$mid,$key+1); 139 if ($enc == 0) 140 $message = imap_8bit($message); 141 if ($enc == 1) 142 $message = imap_8bit ($message); 143 if ($enc == 2) 144 $message = imap_binary ($message); 145 if ($enc == 3) 146 $message = imap_base64 ($message); 147 if ($enc == 4) 148 $message = quoted_printable_decode($message); 149 if ($enc == 5) 150 $message = $message; 151 $fp=fopen($path.$name,"w"); 152 fwrite($fp,$message); 153 fclose($fp); 154 $ar=$ar.$name.","; 155 } 156 } 157 $ar=substr($ar,0,(strlen($ar)-1)); 158 return $ar; 159 } 160 function getBody($mid,$mode="") // Get Message Body 161 { 162 if($mode != "plain") 163 { 164 $body = $this->get_part($this->marubox, $mid, "TEXT/HTML"); 165 } 166 if (($body == "") || $mode == 'plain') 167 $body = $this->get_part($this->marubox, $mid, "TEXT/PLAIN"); 168 if ($body == "") { 169 return ""; 170 } 171 return $body; 172 } 173 function deleteMails($mid) // Delete That Mail 174 { 175 imap_delete($this->marubox,$mid); 176 } 177 function close_mailbox() //Close Mail Box 178 { 179 imap_close($this->marubox,CL_EXPUNGE); 180 } 181 } 182 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |