url = array(); $this->url['sendMail'] = "http://mail.alpha.orange-api.net/mail/sendMail.xml"; $this->url['getMailList'] = "http://mail.alpha.orange-api.net/mail/getMailList.xml"; $this->url['getMail'] = "http://mail.alpha.orange-api.net/mail/getMail.xml"; $this->url['deleteMail'] = "http://mail.alpha.orange-api.net/mail/deleteMail.xml"; $this->url['markMailRead'] = "http://mail.alpha.orange-api.net/mail/markMailRead.xml"; $this->url['markMailUnread'] = "http://mail.alpha.orange-api.net/mail/markMailUnread.xml"; $this->url['countMail'] = "http://mail.alpha.orange-api.net/mail/countMail.xml"; $this->id = $id; } /* * @access public * @return string * @param string $url * @param array $options */ public function make_url($url, $options) { if(function_exists("http_build_query")) { return $this->url[$url]."?".http_build_query($options); }else{ $args = implode("&", $options); return $this->url[$url]."?".$args; } } /* * @access public * @return string|int * @param array $val * @param bool $status */ public function send($val, $status = false) { $data = array(); if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } if(isset($val['from']) && !empty($val['from'])) { $options['from'] = $val['from']; } if(isset($val['to']) && !empty($val['to'])) { $options['to'] = $val['to']; } if(isset($val['subject']) && !empty($val['subject'])) { $options['subject'] = $val['subject']; } if(isset($val['body']) && !empty($val['body'])) { $options['body'] = $val['body']; } if(isset($val['cc']) && !empty($val['cc'])) { $options['cc'] = $val['cc']; } if(isset($val['bcc']) && !empty($val['bcc'])) { $options['bcc'] = $val['bcc']; } if(isset($val['replyto']) && !empty($val['replyto'])) { $options['replyto'] = $val['replyto']; } $result = file_get_contents($this->make_url('sendMail', $options)); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } /* * @access public * @return objet|string|int * @param bool $status */ public function getMailList($status = false) { if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } $result = file_get_contents($this->make_url('getMailList', $options)); //var_dump($result); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($xml->status->status_code == 200) { return $xml->list->message; }else{ if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } } /* * @access public * @return int|string * @param bool $status */ public function getSize($status = false) { $mailboxsize = 0; if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } $result = file_get_contents($this->make_url('getMailList', $options)); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($xml->status->status_code == 200) { foreach($xml->list->message as $m) { $mailboxsize += $m->size; } return($mailboxsize/1024); }else{ if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } } /* * @access public * @return objet|string|int * @param int $number * @param bool $status */ public function getMail($number, $status = false) { if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } if(!empty($number)) { $options['number'] = $number; } $result = file_get_contents($this->make_url('getMail', $options)); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($xml->status->status_code == 200) { return $xml->message; }else{ if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } } /* * @access public * @return string|int * @param int $number * @param bool $status */ public function deleteMail($number, $status = false) { if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } if(!empty($number)) { $options['number'] = $number; } $result = file_get_contents($this->make_url('deleteMail', $options)); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } /* * @access public * @return string|int * @param int $number * @param bool $status */ public function markMailRead($number, $status = false) { if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } if(!empty($number)) { $options['number'] = $number; } $result = file_get_contents($this->make_url('markMailRead', $options)); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } /* * @access public * @return string|int * @param int $number * @param bool $status */ public function markMailUnread($number, $status = false) { if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } if(!empty($number)) { $options['number'] = $number; } $result = file_get_contents($this->make_url('markMailUnread', $options)); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } /* * @access public * @return int|string * @param bool $status */ public function countMail($status = false) { if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } $result = file_get_contents($this->make_url('countMail', $options)); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($xml->status->status_code == 200) { return $xml->nbMsg; }else{ if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } } /* * @access public * @return int|string * @param bool $status */ public function countMailUnread($status = false) { if(!empty($this->id)) { $options['id'] = $this->id; }else{ throw new Zfe_Service_Orange_Exception("l'id est manquant"); } $result = file_get_contents($this->make_url('countMail', $options)); $xml = simplexml_load_string($result,'SimpleXMLElement', LIBXML_NOCDATA); if($xml->status->status_code == 200) { return $xml->nbUnreadMsg; }else{ if($status) { return $xml->status->status_code; }else{ return $this->status($xml->status->status_code); } } } /* * @access public * @return string * @param int $code */ public function status($code) { switch ($code) { case 200: return "ok"; break; case 400: return "l'id est manquant"; break; case 401: return "id non autorisé"; break; case 402: return "crédit insuffisant "; break; case 420: return "quota journalier dépassé"; break; case 430: return "parameter number is missing"; break; case 431: return "parameter from is missing"; break; case 432: return "parameter to is missing"; break; case 433: return "parameter subject is too long"; break; case 434: return "parameter body is too long"; break; case 440: return "parameter number is invalid"; break; case 441: return "parameter from is invalid"; break; case 442: return "parameter to,cc,bcc is invalid"; break; case 443: return "parameter subject is invalid"; break; case 444; return "parameter body is invalid"; break; case 500: return "erreur interne"; break; } } } ?>