Class BLSEPOSTA
{
// Public $Host = '{mail.siteadi.com:995/pop3/ssl/novalidate-cert}';
Public $Host = '{mail.siteadi.com:993/imap/ssl/novalidate-cert}';
Static $Kullanici = "[email protected]";
Static $Sifre = "123456789";
Static $EpostaDurumKlasor = "INBOX";
Static $Klasor = "INBOX";
Static $PKutusu = "INBOX";
Public $Baglanti;
Private $Hata;
Private $Durum;
Private $DosyaKonumu = "./dosyalar/";
Private $ResimKonumu = "./resimler/";
Static function ayar( $gelen, $deger = null )
{
if( is_array( $gelen ) )
{
foreach( $gelen as $key => $deger )
{
self::ayar( $key, $deger );
}
}
else if( property_exists( __CLASS__, $gelen ) )
{
self::$$gelen = $deger;
}
}
function __construct(){
try{
// BAĞLANTI YAPILIYOR
$this->Baglanti = @imap_open($this->Host.self::$PKutusu, self::$Kullanici, self::$Sifre);
// BAĞLANTI YAPILAMAZSA EKRANA BİLGİ YAZDIRILIYOR
if(!$this->Baglanti){
throw new Exception ("<table style='padding: 2px; border: 1px solid darkred; background-color: #ffd0d0; font-family: Verdana; font-size: 10px;' align='center'><tr><td><b>E-Posta Bağlantı Hatası:</b> Bağlantı yapılamadı!
<br><center>".imap_last_error()."</center></td></tr></table>");
}
// ÜYESİ OLUNAN POSTA KUTULARI ÇEKİLİYOR
$klasor_modu = 0;
$Klasor = imap_listmailbox($this->Baglanti, $this->Host, "*");
if(1 === $this->VarsayilanKlasorleriOlustur($this->Baglanti,$Klasor)) {
$Klasor = imap_listmailbox($this->Baglanti, $this->Host, "*");
$klasor_modu = 1;
}
sort($Klasor);
$Klasor = str_replace($this->Host,'',$Klasor);
$this->Klasor = $Klasor;
// ÜYESİ OLUNAN POSTA KUTULARI ÇEKİLİYOR - SONU
}
// BAĞLANTI YAPILAMAZSA EKRANA BİLGİ YAZDIRILIYOR
catch (Exception $Hata){
die($Hata->getMessage());
exit();
}
}
// VARSAYILAN KLASÖRLER OLUŞTURULUYOR
private function VarsayilanKlasorleriOlustur($imap_baglantisi, $Klasor) {
$durum=0;
if(!in_array($this->Host.'INBOX.Trash',$Klasor)) {
@imap_createmailbox($imap_baglantisi, imap_utf7_encode($this->Host."INBOX.Trash"));
$durum=1;
}
if(!in_array($this->Host.'INBOX.Sent',$Klasor)) {
@imap_createmailbox($imap_baglantisi, imap_utf7_encode($this->Host."INBOX.Sent"));
$durum=1;
}
if(!in_array($this->Host.'INBOX.Drafts',$Klasor)) {
@imap_createmailbox($imap_baglantisi, imap_utf7_encode($this->Host."INBOX.Drafts"));
$durum=1;
}
if(!in_array($this->Host.'INBOX.Junk',$Klasor)) {
@imap_createmailbox($imap_baglantisi, imap_utf7_encode($this->Host."INBOX.Junk"));
$durum=1;
}
return $durum;
}
// VARSAYILAN KLASÖRLER OLUŞTURULUYOR - SONU
// KLASÖR, ÖRNEĞİN: INBOX
Public function EpostaDurum($PostaKutusu)
{
// BAĞLANTI YAPILIYOR
$this->Durum = imap_status($this->Baglanti, $this->Host.$PostaKutusu, SA_ALL);
try{
$EpostaDurum = array(
'ileti_sayisi' => $this->Durum->messages,
'yeni_gelenler' => $this->Durum->recent,
'okunmamislar' => $this->Durum->unseen,
'sonraki_kimlik' => $this->Durum->uidnext,
'kimlik_gecerlimi' => $this->Durum->uidvalidity
);
// BAĞLANTI YAPILAMAZSA EKRANA BİLGİ YAZDIRILIYOR
if(!$this->Durum){
throw new Exception ("<table style='padding: 2px; border: 1px solid darkred; background-color: #ffd0d0; font-family: Verdana; font-size: 10px;' align='center'><tr><td><b>E-Posta IMAP_STATUS Bağlantı Hatası:</b> Bağlantı yapılamadı!
<br><center>".imap_last_error()."</center></td></tr></table>");
}
return $EpostaDurum;
}
// BAĞLANTI YAPILAMAZSA EKRANA BİLGİ YAZDIRILIYOR
catch (Exception $Hata){
die($Hata->getMessage());
exit();
}
}
// KLASÖR, ÖRNEĞİN: INBOX
Public function EpostaAdet($PostaKutusu)
{
$this->Durum = @imap_status($this->Baglanti, $this->Host.$PostaKutusu, SA_ALL);
$EpostaDurum = ('('.$this->Durum->unseen.')');
if($EpostaDurum == '(0)') return '';
else return $EpostaDurum;
}
// POSTA KUTUSUNU KONTROL ET
public function PostaKutusuKontrol() {
return imap_check($this->Baglanti);
}
// POSTA KUTULARINDA ARAMA YAP
public function PostaKutusuArama($kriter = 'ALL') {
$postaNumaralari = imap_search($this->Baglanti, $kriter, SE_UID, "UTF-8");
return $postaNumaralari ? $postaNumaralari : array();
}
// POSTA KUTUSU SİL
public function PostaKutusuAdiDegistir($KutuAdi, $KutuYeniAdi) {
$KutuYeniAdi = imap_utf7_encode($this->Host.$KutuYeniAdi);
return imap_renamemailbox($this->Baglanti, $this->Host.$KutuAdi, $KutuYeniAdi);
}
// POSTA KUTUSU SİL
public function PostaKutusuSil($KutuAdi) {
return imap_deletemailbox($this->Baglanti, $this->Host.$KutuAdi);
}
// E-POSTAYI SİL
public function PostayiSil($postaNumarasi) {
return imap_delete($this->Baglanti, $postaNumarasi, FT_UID);
}
// E-POSTAYI TAŞI
public function PostaTasi($postaNumarasi, $postaKutusu) {
return imap_mail_move($this->Baglanti, $postaNumarasi, $postaKutusu, CP_UID) && $this->SilinenPostalariTemizle();
}
// SİLİNEN E-POSTALARI SUNUCUDAN TEMİZLE ( TAMAMEN SİL )
public function SilinenPostalariTemizle() {
return imap_expunge($this->Baglanti);
}
// E-POSTALARI OKUNMADI OLARAK İŞARETLE
public function PostalarOkunmadi(array $postaNumarasi) {
return $this->BayrakTemizle($postaNumarasi, '\\Seen');
}
// E-POSTALARI OKUNDU OLARAK İŞARETLE
public function PostalarOkundu(array $postaNumarasi) {
return $this->BayrakAyarla($postaNumarasi, '\\Seen');
}
// E-POSTALARI ÖNEMSİZ OLARAK İŞARETLE
public function OnemsizPostalar(array $postaNumarasi) {
return $this->BayrakTemizle($postaNumarasi, '\\Seen');
}
// E-POSTALARI ÖNEMLİ OLARAK İŞARETLE
public function OnemliPostalar(array $postaNumarasi) {
return $this->BayrakAyarla($postaNumarasi, '\\Flagged');
}
// BAYRAK AYARLA
public function BayrakAyarla(array $postaNumaralari, $bayrak) {
return imap_setflag_full($this->Baglanti, implode(',', $postaNumaralari), $bayrak, ST_UID);
}
// BAYRAK TEMİZLE
public function BayrakTemizle(array $postaNumaralari, $bayrak) {
return imap_clearflag_full($this->Baglanti, implode(',', $postaNumaralari), $bayrak, ST_UID);
}
// E-POSTA BİLGİLERİNİ AL
public function PostaBilgileriniAl(array $postaNumaralari) {
return imap_fetch_overview($this->Baglanti, implode(',', $postaNumaralari), FT_UID);
}
// POSTA KUTUSU BİLGİSİ
public function PostaKutusuBilgisi() {
return imap_mailboxmsginfo($this->Baglanti);
}
// E-POSTA SIRALA
public function EpostalariSirala($kriter = SORTARRIVAL, $tersten = true) {
return imap_sort($this->Baglanti, $kriter, $tersten, SE_UID);
}
// TOPLAM E-POSTA SAYISI
public function ToplamMail() {
return imap_num_msg($this->Baglanti);
}
// E-POSTA EŞSİZ NUMARASI
public function MailUid($iletino) {
return imap_uid($this->Baglanti,$iletino);
}
// E-POSTA EŞSİZ NUMARASI
public function MailMsgId($uidno) {
return imap_msgno($this->Baglanti,$uidno);
}
// E-POSTA ALANI
protected function EpostaAlani() {
return imap_get_quotaroot($this->Baglanti, 'INBOX');
}
// KULLANICIYA VERİLEN E-POSTA LİMİTİ
public function EpostaLimiti() {
$alan = $this->EpostaAlani();
if (is_array($alan)) {
$alan = $alan['STORAGE']['limit'];
}
return $alan;
}
// KULLANICININ KULLANDIĞI E-POSTA ALANI
public function KullanilanAlan() {
$alan = $this->EpostaAlani();
if (is_array($alan)) {
$alan = $alan['STORAGE']['usage'];
}
return $alan;
}
public function decodeMimeStr($string, $charset = 'UTF-8') {
$newString = '';
$elements = imap_mime_header_decode($string);
for($i = 0; $i < count($elements); $i++) {
if($elements[$i]->charset == 'default') {
$elements[$i]->charset = 'UTF-8';
}
$newString .= @iconv(strtoupper($elements[$i]->charset), $charset, $elements[$i]->text);
}
return $newString;
}
public function isUrlEncoded($string) {
$string = str_replace('%20', '+', $string);
$decoded = urldecode($string);
return $decoded != $string && urlencode($decoded) == $string;
}
public function decodeRFC2231($string, $charset = 'UTF-8') {
if(preg_match("/^(.*?)'.*?'(.*?)$/", $string, $matches)) {
$encoding = $matches[1];
$data = $matches[2];
if($this->isUrlEncoded($data)) {
$string = @iconv(strtoupper($encoding), $charset, urldecode($data));
}
}
return $string;
}
// ZARARLI VERİLER TEMİZLENİYOR
public function TakCevirici($metin)
{
$bul = array('>', '<', '{', '}');
$cevir = array('>', '<', '{', '}');
$donen = @str_replace($bul, $cevir, $metin);
return $donen;
}
public function YaziDuzelt($gelen)
{
$degistir = array(); $bul = array(); $bul2 = array();
$degistir[] = "À"; $bul[] = "À"; $bul2[] = "À";
$degistir[] = "Á"; $bul[] = "Á"; $bul2[] = "Á";
$degistir[] = "Â"; $bul[] = "Â"; $bul2[] = "Â";
$degistir[] = "Ã"; $bul[] = "Ã"; $bul2[] = "Ã";
$degistir[] = "Ä"; $bul[] = "Ä"; $bul2[] = "Ä";
$degistir[] = "Å"; $bul[] = "Å"; $bul2[] = "Å";
$degistir[] = "Æ"; $bul[] = "Æ"; $bul2[] = "Æ";
$degistir[] = "Ç"; $bul[] = "Ç"; $bul2[] = "Ç";
$degistir[] = "È"; $bul[] = "È"; $bul2[] = "È";
$degistir[] = "É"; $bul[] = "É"; $bul2[] = "É";
$degistir[] = "Ê"; $bul[] = "Ê"; $bul2[] = "Ê";
$degistir[] = "Ë"; $bul[] = "Ë"; $bul2[] = "Ë";
$degistir[] = "Ì"; $bul[] = "Ì"; $bul2[] = "Ì";
$degistir[] = "Í"; $bul[] = "Í"; $bul2[] = "Í";
$degistir[] = "Î"; $bul[] = "Î"; $bul2[] = "Î";
$degistir[] = "Ï"; $bul[] = "Ï"; $bul2[] = "Ï";
$degistir[] = "Ñ"; $bul[] = "Ñ"; $bul2[] = "Ñ";
$degistir[] = "Ò"; $bul[] = "Ò"; $bul2[] = "Ò";
$degistir[] = "Ó"; $bul[] = "Ó"; $bul2[] = "Ó";
$degistir[] = "Ô"; $bul[] = "Ô"; $bul2[] = "Ô";
$degistir[] = "Õ"; $bul[] = "Õ"; $bul2[] = "Õ";
$degistir[] = "Ö"; $bul[] = "Ö"; $bul2[] = "Ö";
$degistir[] = "Ø"; $bul[] = "Ø"; $bul2[] = "Ø";
$degistir[] = "Ù"; $bul[] = "Ù"; $bul2[] = "Ù";
$degistir[] = "Ú"; $bul[] = "Ú"; $bul2[] = "Ú";
$degistir[] = "Û"; $bul[] = "Û"; $bul2[] = "Û";
$degistir[] = "Ü"; $bul[] = "Ü"; $bul2[] = "Ü";
$degistir[] = "ß"; $bul[] = "ß"; $bul2[] = "ß";
$degistir[] = "à"; $bul[] = "à"; $bul2[] = "à";
$degistir[] = "á"; $bul[] = "á"; $bul2[] = "á";
$degistir[] = "â"; $bul[] = "â"; $bul2[] = "â";
$degistir[] = "ã"; $bul[] = "ã"; $bul2[] = "ã";
$degistir[] = "ä"; $bul[] = "ä"; $bul2[] = "ä";
$degistir[] = "å"; $bul[] = "å"; $bul2[] = "å";
$degistir[] = "æ"; $bul[] = "æ"; $bul2[] = "æ";
$degistir[] = "ç"; $bul[] = "ç"; $bul2[] = "ç";
$degistir[] = "è"; $bul[] = "è"; $bul2[] = "è";
$degistir[] = "é"; $bul[] = "é"; $bul2[] = "é";
$degistir[] = "ê"; $bul[] = "ê"; $bul2[] = "ê";
$degistir[] = "ë"; $bul[] = "ë"; $bul2[] = "ë";
$degistir[] = "ì"; $bul[] = "ì"; $bul2[] = "ì";
$degistir[] = "í"; $bul[] = "í"; $bul2[] = "í";
$degistir[] = "î"; $bul[] = "î"; $bul2[] = "î";
$degistir[] = "ï"; $bul[] = "ï"; $bul2[] = "ï";
$degistir[] = "ñ"; $bul[] = "ñ"; $bul2[] = "ñ";
$degistir[] = "ò"; $bul[] = "ò"; $bul2[] = "ò";
$degistir[] = "ó"; $bul[] = "ó"; $bul2[] = "ó";
$degistir[] = "ô"; $bul[] = "ô"; $bul2[] = "ô";
$degistir[] = "õ"; $bul[] = "õ"; $bul2[] = "õ";
$degistir[] = "ö"; $bul[] = "ö"; $bul2[] = "ö";
$degistir[] = "ø"; $bul[] = "ø"; $bul2[] = "ø";
$degistir[] = "ù"; $bul[] = "ù"; $bul2[] = "ù";
$degistir[] = "ú"; $bul[] = "ú"; $bul2[] = "ú";
$degistir[] = "û"; $bul[] = "û"; $bul2[] = "û";
$degistir[] = "ü"; $bul[] = "ü"; $bul2[] = "ü";
$degistir[] = "ÿ"; $bul[] = "ÿ"; $bul2[] = "ÿ";
$degistir[] = '"'; $bul[] = "”"; $bul2[] = "”";
$degistir[] = "
<br>"; $bul[] = "\n";
$degistir[] = "
<br>"; $bul[] = "\r";
$degistir[] = "
<br>"; $bul[] = "\r\n";
$degistir[] = "
<br>"; $bul[] = "
";
$cikti = str_replace($bul, $degistir, $gelen);
$cikti = str_replace($bul2, $degistir, $cikti);
return trim($cikti);
}
// E-POSTA BAŞLIKLARI OKUNUYOR
Public function EpostaBaslik($sabit=0,$ilk=0,$son=10)
{
$EpostaBaslik = imap_headers($this->Baglanti);
// $EpostaBaslik = imap_sort($this->Baglanti, SORTARRIVAL, 1, SE_NOPREFETCH);
$EpostaBaslik = imap_sort($this->Baglanti, SORTDATE, 1);
$EpostaBaslikSayi = $this->ToplamMail();
$okunmus=0;
$EpostaBaslikListe = array();
foreach ($EpostaBaslik as $id => $icerik)
{
if($sabit <= $id)
{
if($ilk < $son)
{
$header = (imap_headerinfo($this->Baglanti, $icerik, 80, 80));
if($header->Unseen == 'U') $okunmus = '1';
else $okunmus = '0';
// DÖNÜŞTÜRME YAPILIYOR
$dnm[] = $header;
$EpostaBaslikListe[$icerik]['no'] = $icerik;
$EpostaBaslikListe[$icerik]['okunma'] = $okunmus;
$EpostaBaslikListe[$icerik]['tarih'] = MailTarih('+2', strtotime((!empty($header->Date) ? $header->Date : ((!empty($header->date) ? $header->date: (!empty($header->MailDate) ? $header->MailDate : ''))))));
$EpostaBaslikListe[$icerik]['baslik'] = (!empty($header->Subject) ? $this->decodeMimeStr($header->Subject) : (!empty($header->subject) ? $this->decodeMimeStr($header->subject) : (!empty($header->fetchsubject) ? $this->decodeMimeStr($header->fetchsubject) : 'Konu belirtilmemiş')));
}
$ilk++;
}
}
return $EpostaBaslikListe;
}
// E-POSTA BAŞLIKLARI OKUNUYOR
public function EpostaBaslikOku($Id)
{
try{
$header=imap_header($this->Baglanti, $Id, 80,80);
$NTGMail["personal"] = (@$header->from[0]->personal ? $this->TakCevirici($this->decodeMimeStr(@$header->from[0]->personal)) : 'Personal bilgisi alınamadı');
$NTGMail["fromaddress"] = (@$header->fromaddress ? $this->TakCevirici($this->decodeMimeStr(@$header->fromaddress)) : 'Fromaddress bilgisi alınamadı');
$NTGMail["fetchfrom"] = (@$header->fetchfrom ? $this->TakCevirici($this->decodeMimeStr(@$header->fetchfrom)) : 'Fetchfrom bilgisi alınamadı');
$NTGMail["senderaddress"] = (@$header->senderaddress ? $this->TakCevirici($this->decodeMimeStr(@$header->senderaddress)) : 'Senderaddress bilgisi alınamadı');
$NTGMail["reply_toaddress"] = (@$header->reply_toaddress ? $this->TakCevirici($this->decodeMimeStr(@$header->reply_toaddress)) : 'Reply To Address bilgisi alınamadı');
$NTGMail["reply_to_personal"] = (@$header->reply_to[0]->personal ? $this->TakCevirici($this->decodeMimeStr(@$header->reply_to[0]->personal)) : 'Reply To Personel bilgisi alınamadı');
$NTGMail["Recent"] = (@$header->Recent ? @$header->Recent : '');
$NTGMail["Unseen"] = (@$header->Unseen ? @$header->Unseen : '');
$NTGMail["Flagged"] = (@$header->Flagged ? @$header->Flagged : '');
$NTGMail["Answered"] = (@$header->Answered ? @$header->Answered : '');
$NTGMail["Deleted"] = (@$header->Deleted ? @$header->Deleted : '');
$NTGMail["Draft"] = (@$header->Draft ? @$header->Draft : '');
$NTGMail["Msgno"] = (@$header->Msgno ? @$header->Msgno : 'Mesaj no alınamadı');
$NTGMail["Size"] = (@$header->Size ? @$header->Size : 'E-Posta boyutu alınamadı');
$NTGMail["to_mailbox_host"] = (@$header->to[0]->mailbox ? @$header->to[0]->mailbox."@"[email protected]$header->to[0]->host : 'Adres alınamadı');
$NTGMail["toaddress"] = (@$header->toaddress ? @$header->toaddress : 'Adres alınamadı');
$NTGMail["from_mailbox_host"] = (@$header->from[0]->mailbox ? @$header->from[0]->mailbox."@"[email protected]$header->from[0]->host : 'Gönderen bilgisi yok');
$NTGMail["sender_mailbox_host"] = (@$header->sender[0]->mailbox ? @$header->sender[0]->mailbox."@"[email protected]$header->sender[0]->host : 'Gönderen bilgisi yok');
$NTGMail["reply_to_mailbox_host"] = (@$header->reply_to[0]->mailbox ? @$header->reply_to[0]->mailbox."@"[email protected]$header->reply_to[0]->host : 'Yanıt adresi yok');
$NTGMail["fetchsubject"] = (@$header->fetchsubject ? $this->decodeMimeStr(@$header->fetchsubject) : 'Konu belirtilmemiş');
$NTGMail["subject"] = (@$header->subject ? $this->decodeMimeStr(@$header->subject) : 'Konu belirtilmemiş');
$NTGMail["Subject"] = (@$header->Subject ? $this->decodeMimeStr(@$header->Subject) : 'Konu belirtilmemiş');
$NTGMail["message_id"] = (@$header->message_id ? @$header->message_id : 'Mesaj ID bulunamadı');
$NTGMail["date"] = (@$header->date ? @$header->date : 'Tarih belirsiz');
$NTGMail["Date"] = (@$header->Date ? @$header->Date : 'Tarih belirsiz');
$NTGMail["MailDate"] = (@$header->MailDate ? @$header->MailDate : 'Tarih belirsiz');
$NTGMail["udate"] = Date("F j, Y, g:i a", @$header->udate);
// BAĞLANTI YAPILAMAZSA EKRANA BİLGİ YAZDIRILIYOR
if(!$header){
throw new Exception ("<table style='padding: 2px; border: 1px solid darkred; background-color: #ffd0d0; font-family: Verdana; font-size: 10px;' align='center'><tr><td><b>HEADER Okunamadı:</b>
<br><center>".imap_last_error()."</center></td></tr></table>");
}
return $NTGMail;
}
// BAĞLANTI YAPILAMAZSA EKRANA BİLGİ YAZDIRILIYOR
catch (Exception $Hata){
die($Hata->getMessage());
exit();
}
}
// DİZİ DEĞİŞKENLER TARANIP ANLAŞILIR HALE GETİRİLİYOR
public function DiziDegiskenAra($array, $key){
if(is_object($array))
$array = (array)$array;
// search for the key
$result = array();
foreach ($array as $k => $value) {
if(is_array($value) || is_object($value)){
$r = $this->DiziDegiskenAra($value, $key);
if(!is_null($r))
array_push($result,$r);
}
}
if(array_key_exists($key, $array))
array_push($result,$array[$key]);
if(count($result) > 0){
// resolve nested arrays
$result_plain = array();
foreach ($result as $k => $value) {
if(is_array($value))
$result_plain = array_merge($result_plain,$value);
else
array_push($result_plain,$value);
}
return $result_plain;
}
return NULL;
}
// RESIMLER AYIKLANIYOR
public function cidDonustur($veri) {
return preg_match_all('/=["\'](ci?d:(.*?))["\']/i', $veri, $sonuc) ? array_combine($sonuc[2], $sonuc[1]) : array();
}
// E-POSTA GÖVDESİ OKUNUYOR
Public function EpostaGovde($gelenId)
{
$Veriler = $this->TumVeriler($gelenId);
$html = $this->DiziDegiskenAra($Veriler, "html");
$rfc822 = $this->DiziDegiskenAra($Veriler, "rfc822");
$plain = $this->DiziDegiskenAra($Veriler, "plain");
$alternative = $this->DiziDegiskenAra($Veriler, "alternative");
$resim = $this->DiziDegiskenAra($Veriler, "resim");
$dosya = $this->DiziDegiskenAra($Veriler, "dosya");
$text = $this->DiziDegiskenAra($Veriler, "text");
$EpostaGovdeSayi = $this->ToplamMail();
$VerilerDosya='';
// E-POSTA GÖVDESİ VARSA OKUNUYOR
if( $EpostaGovdeSayi > 0 )
{
$EpostaGovdeAktar="";
if(isset($html))
{
// DÖNÜŞTÜRME YAPILIYOR
if((!empty($html['kodlama'])) and ($html['kodlama'] != 'UTF-8')) {
$html['icerik'] = iconv($html['kodlama'], "UTF-8//TRANSLIT//IGNORE", $html['icerik']);
}
$EpostaGovdeAktar .= $html['icerik'];
}
else if(isset($text))
{
// DÖNÜŞTÜRME YAPILIYOR
if((!empty($text['kodlama'])) and ($text['kodlama'] != 'UTF-8')) {
$text['icerik'] = iconv($text['kodlama'], "UTF-8//TRANSLIT//IGNORE", $text['icerik']);
}
$EpostaGovdeAktar .= '<div>'.$text['icerik'].'</div>';
}
else if(isset($plain))
{
// DÖNÜŞTÜRME YAPILIYOR
if((!empty($plain['kodlama'])) and ($plain['kodlama'] != 'UTF-8')) {
$plain['icerik'] = iconv($plain['kodlama'], "UTF-8//TRANSLIT//IGNORE", $plain['icerik']);
}
// PLAİN PARÇALARA BÖLÜNÜYOR
$aktarimArrayPlain = explode("\n\r",$plain['icerik']);
$aktarimArrayPlainSon = array();
$plain_resimno='';
// DİZİ DÖNDÜRÜLÜYOR
for($i=0; $i < count($aktarimArrayPlain); $i++)
{
if(preg_match('/base64/',$aktarimArrayPlain[$i])) $plain_resimno = ($i+1);
// İÇİNDE RESİM OLMAYAN VE -- İLE BAŞLAMAYAN SATIRLAR ALINIYOR
if(($i) != $plain_resimno)
{
if(!preg_match('/--/',$aktarimArrayPlain[$i])) {
$aktarimArrayPlain[$i] = preg_replace('|\-\-(.*?)\-\-|si','',$aktarimArrayPlain[$i]);
$aktarimArrayPlainSon[] = $aktarimArrayPlain[$i];
}
}
}
// RESİM ALINIYOR
if($plain_resimno != '') {
$aktarimArrayPlain[$plain_resimno] = preg_replace('|\-\-(.*?)\-\-|si','',$aktarimArrayPlain[$plain_resimno]);
$Plain_resim = '<img src="data:image/png;base64,'.$aktarimArrayPlain[$plain_resimno].'">';
}
// EKRAN ÇIKTISI HAZIRLANIYOR
$tamamla = '<div class="bls_class_tamamla"><div>';
$PlainTemizle = $aktarimArrayPlainSon;
for($i=0; $i < count($PlainTemizle); $i++)
{
// RESİM VE BAŞLIK OLMAYAN YAZILAR ALT ALTA EKLENİYOR
if((!preg_match('/Received:/',$PlainTemizle[$i])) and (!preg_match('/\<\/html\>/',$PlainTemizle[$i]))) {
$tamamla .= '
<p>'.$PlainTemizle[$i].'</p>';
}
}
$tamamla .= '</div>';
// RESİM EKLENİYOR
if((isset($Plain_resim)) and ($Plain_resim != ''))
$tamamla .= '<div class="bls_class_tamamla_devam">'.$Plain_resim.'</div>';
$EpostaGovdeAktar .= $tamamla;
}
else if(isset($alternative))
{
// DÖNÜŞTÜRME YAPILIYOR
if((!empty($alternative['kodlama'])) and ($alternative['kodlama'] != 'UTF-8')) {
$alternative['icerik'] = iconv($alternative['kodlama'], "UTF-8//TRANSLIT//IGNORE", $alternative['icerik']);
}
$EpostaGovdeAktar .= '<div>'.$alternative['icerik'].'</div>';
}
if(isset($rfc822))
{
// DÖNÜŞTÜRME YAPILIYOR
if((!empty($rfc822['kodlama'])) and ($rfc822['kodlama'] != 'UTF-8')) {
$rfc822['icerik'] = iconv($rfc822['kodlama'], "UTF-8//TRANSLIT//IGNORE", $rfc822['icerik']);
}
// MULTİPART RFC822 MAİL PARÇALARA BÖLÜNÜYOR
$aktarimArray = explode("\n\r",$rfc822['icerik']);
$aktarimArrayRFC822Son = array();
$RFC822_resimno='';
// DİZİ DÖNDÜRÜLÜYOR
for($i=0; $i < count($aktarimArray); $i++)
{
if(preg_match('/base64/',$aktarimArray[$i])) $RFC822_resimno = ($i+1);
// İÇİNDE RESİM OLMAYAN VE -- İLE BAŞLAMAYAN SATIRLAR ALINIYOR
if(($i) != $RFC822_resimno)
{
if(!preg_match('/--/',$aktarimArray[$i])) {
$aktarimArray[$i] = preg_replace('|\-\-(.*?)\-\-|si','',$aktarimArray[$i]);
$aktarimArrayRFC822Son[] = $aktarimArray[$i];
}
}
}
// RESİM ALINIYOR
if($RFC822_resimno != '') {
$aktarimArray[$RFC822_resimno] = preg_replace('|\-\-(.*?)\-\-|si','',$aktarimArray[$RFC822_resimno]);
$RFC822_resim = '<img src="data:image/png;base64,'.$aktarimArray[$RFC822_resimno].'">';
}
// EKRAN ÇIKTISI HAZIRLANIYOR
$tamamla = '';
// RESİM EKLENİYOR
if((isset($RFC822_resim)) and ($RFC822_resim != ''))
$tamamla .= '<div class="bls_class_tamamla_devam">'.$RFC822_resim.'</div>';
$tamamla .= '<div class="bls_class_tamamla">';
$RFC822Temizle = $aktarimArrayRFC822Son;
for($i=0; $i < count($RFC822Temizle); $i++)
{
// RESİM VE BAŞLIK OLMAYAN YAZILAR ALT ALTA EKLENİYOR
if((!preg_match('/Received:/',$RFC822Temizle[$i])) and (!preg_match('/\<\/html\>/',$RFC822Temizle[$i]))) {
$tamamla .= '
<p>'.$RFC822Temizle[$i].'</p>';
}
}
$tamamla .= '</div>';
$EpostaGovdeAktar .= $tamamla;
}
$EpostaGovdeAktar = str_replace('<div class="bls_class_tamamla_devam"></div>','',$EpostaGovdeAktar);
// HTML E-POSTA İÇERİSİNDEKİ RESİM BULUNUP DÜZELTİLİYOR
if(isset($resim))
{
$cidCikti = $this->cidDonustur($EpostaGovdeAktar);
foreach($resim as $format => $deger){
foreach($deger as $cid => $isim){
// $EpostaGovdeAktar = @str_replace($cidCikti[$cid], 'data:image/'.$format.';base64,'.$isim, $EpostaGovdeAktar);
$EpostaGovdeAktar = @str_replace($cidCikti[$cid], $isim, $EpostaGovdeAktar);
}
}
}
// DOSYA AKTARIMI
if(isset($dosya))
{
$VerilerDosya = $dosya;
}
// RESİM İSİMLERİ NETLEŞTİRİLİYOR
// FONKSİYON SONLANDIRILIP DİZİ DEĞİŞKEN HALİNE GETİRİLİYOR
return array('EpostaGovdeSayi' => $EpostaGovdeSayi, 'EpostaGovde' => $EpostaGovdeAktar, 'EpostaDosyalar' => $VerilerDosya);
}
else return false;
}
// E-POSTA GÖVDESİ OKUNUYOR
// IMAP DECODE 7BİT
public function decode7Bit($text)
{
$lines = explode("\r\n", $text);
$first_line_words = explode(' ', $lines[0]);
if ($first_line_words[0] == $lines[0]) {
$text = base64_decode($text);
}
$characters = array(
'=20' => ' ', // space.
'=2C' => ',', // comma.
'=E2=80=99' => "'", // single quote.
'=0A' => "\r\n", // line break.
'=0D' => "\r\n", // carriage return.
'=A0' => ' ', // non-breaking space.
'=B9' => '$sup1', // 1 superscript.
'=C2=A0' => ' ', // non-breaking space.
"=\r\n" => '', // joined line.
'=E2=80=A6' => '…', // ellipsis.
'=E2=80=A2' => '•', // bullet.
'=E2=80=93' => '–', // en dash.
'=E2=80=94' => '—', // em dash.
);
foreach ($characters as $key => $value) {
$text = str_replace($key, $value, $text);
}
return $text;
}
// VERİLER AYIKLANIYOR
// RESİM VE DİĞER BİLGİLER ÇEKİLİYOR
public function TumVeriler($mid)
{
// VERİ PARTLARA BÖLÜNÜYOR
function TumPartlar($Baglanti,$uid)
{
global $mime,$AnaDizi,$enc;
$mime = array("text","multipart","message","application","audio",
"image","video","other","unknow");
$struct = imap_fetchstructure($Baglanti,$uid, FT_UID);
$AnaDizi = array();
function scan($struct,$subkey){
global $mime,$enc,$AnaDizi;
foreach($struct as $key => $value){
if($subkey!=0){
$pid = $subkey.".".($key+1); }
else { $pid = ($key+1); }
$AnaDizi[]['part'] = $pid;
$AnaDizi[key($AnaDizi)]['type'] = $mime["$value->type"];
$AnaDizi[key($AnaDizi)]['tip'] = $value->encoding;
if(isset($value->id)) $AnaDizi[key($AnaDizi)]['id'] = $value->id;
else $AnaDizi[key($AnaDizi)]['id'] = "";
$AnaDizi[key($AnaDizi)]['ifid'] = $value->ifid;
if(array_key_exists('0', $value->parameters)) $AnaDizi[key($AnaDizi)]['adi'] = $value->parameters[0]->value;
else $AnaDizi[key($AnaDizi)]['adi'] = "";
$AnaDizi[key($AnaDizi)]['cesit'] = strtolower($value->subtype);
if(array_key_exists('0', $value->parameters) and (strtolower($value->parameters[0]->attribute) == 'charset'))
$AnaDizi[key($AnaDizi)]['kodlama'] = strtolower($value->parameters[0]->value);
else $AnaDizi[key($AnaDizi)]['kodlama'] = "";
next($AnaDizi);
if(((isset($value->parts)) and ($value->parts)!= null)) {scan($value->parts,$pid); }
}
}
if(isset($struct->parts))
{
if(!is_null($struct->parts))
{
scan($struct->parts,0);
}
}
else
{
$AnaDizi[]['part'] = "partyok";
$AnaDizi[key($AnaDizi)]['type'] = $mime["$struct->type"];
$AnaDizi[key($AnaDizi)]['tip'] = $struct->encoding;
if(isset($struct->id)) $AnaDizi[key($AnaDizi)]['id'] = $struct->id;
else $AnaDizi[key($AnaDizi)]['id'] = "";
$AnaDizi[key($AnaDizi)]['ifid'] = $struct->ifid;
$AnaDizi[key($AnaDizi)]['adi'] = $struct->parameters[0]->value;
$AnaDizi[key($AnaDizi)]['cesit'] = strtolower($struct->subtype);
if(strtolower($struct->parameters[0]->attribute) == 'charset')
$AnaDizi[key($AnaDizi)]['kodlama'] = strtolower($struct->parameters[0]->value);
else $AnaDizi[key($AnaDizi)]['kodlama'] = "";
}
return $AnaDizi;
}
$Kullanici = explode('@',self::$Kullanici);
$AnaDizi = TumPartlar($this->Baglanti,$mid);
$isim = array();
// GELEN VERİLER AYIKLANIYOR
foreach($AnaDizi as $anahtar => $deger)
{
// if (($deger['tip'] == 3) and ($deger['ifid'] == 0)) $veri="";
// else
// {
if($deger['part'] == 'partyok') $veri = imap_body($this->Baglanti, $mid, FT_UID);
else $veri = imap_fetchbody($this->Baglanti,$mid,$deger['part'],FT_UID);
// }
if ($deger['tip'] == 0)
$veri = quoted_printable_decode(imap_8bit($veri));
if ($deger['tip'] == 1)
$veri = quoted_printable_decode(imap_8bit ($veri));
if ($deger['tip'] == 2)
$veri = imap_binary($veri);
if ($deger['tip'] == 3)
$veri = imap_base64($veri);
if ($deger['tip'] == 4)
$veri = quoted_printable_decode(imap_qprint($veri));
if ($deger['tip'] == 5)
$veri = $veri;
if($veri != '')
{
$isim[$deger['cesit']]['icerik'] = $veri;
$isim[$deger['cesit']]['kodlama'] = $deger['kodlama'];
}
if($deger['tip'] == 3)
{
if($deger['ifid'] == 1)
{
$rsmId = $deger['ifid'] ? trim($deger['id'], " <>") : (isset($deger['adi']) ? mt_rand() . mt_rand() : null);
if(strtolower($deger['cesit']) != 'zip')
{
// DOSYA ADI BELİRLENİYOR
$dosyaadi = ("bylegens_".$Kullanici[0]."_".$mid."_".substr(md5($deger['adi'].$deger['cesit'].$rsmId),0,20)."_.".strtolower($deger['cesit']));
// DOSYA YAZILIYOR
$fp=fopen("./resimler/".$dosyaadi,"w");
fwrite($fp,$veri);
fclose($fp);
// İSİM DİZİ DEĞİŞKENE AKTARILIYOR
// $isim['resim'][strtolower($deger['cesit'])][$rsmId] = base64_encode($veri); // BASE64 RESİM Görüntüleme
$isim['resim'][strtolower($deger['cesit'])][$rsmId] ="./resimler/$dosyaadi";
}
}
else
{
$adi = BLSEPOSTA::decodeMimeStr($deger['adi']);
$adi = BLSEPOSTA::decodeRFC2231($deger['adi']);
$replace = array(
'/\s/' => '_',
'/[^0-9a-zA-Z_\.]/' => '',
'/_+/' => '_',
'/(^_)|(_$)/' => '',
);
// DOSYA ADI BELİRLENİYOR
if(strtolower($deger['type']) != 'text')
{
if(strtolower($deger['cesit']) == 'zip')
$dosyaadi = preg_replace('~[\\\\/]~', '', ("bylegens_".$Kullanici[0]."_".$mid."_".substr(md5($adi.$deger['cesit'].$mid),0,20)."_".preg_replace(array_keys($replace), $replace, $adi).".zip"));
else
$dosyaadi = preg_replace('~[\\\\/]~', '', ("bylegens_".$Kullanici[0]."_".$mid."_".substr(md5($adi.$deger['cesit'].$mid),0,20)."_".preg_replace(array_keys($replace), $replace, $adi)));
// DOSYA YAZILIYOR
// $fp=fopen("./dosyalar/".$dosyaadi,"w");
// fwrite($fp,$veri);
// fclose($fp);
// İSİM DİZİ DEĞİŞKENE AKTARILIYOR
if(isset($deger['part'])) $partno = $deger['part'];
else $partno = "";
$isim['dosya'][strtolower($deger['cesit'])][$dosyaadi] = $partno;
// $isim['dosya'][] = $dosyaadi;
}
}
}
}
return $isim;
}
// RESİM VE DİĞER BİLGİLER ÇEKİLİYOR - SONU
// VERİLER AYIKLANIYOR - SONU
Public function sifrele($deger)
{
return @base64_encode($deger);
}
Public function BaglantiKapat()
{
return @imap_close($this->Baglanti);
}
}