note 86685 modified in function.imap-fetchstructure by felipe

From: Date: Thu, 30 Oct 2008 01:03:32 +0000
Subject: note 86685 modified in function.imap-fetchstructure by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145955@lists.php.net to get a copy of this message
I'm programing an webmail program and trying to make the less code possible, so I've made this function to get all mail parts Hope it helps someone or if you manage to improve this function please post me. <?php $caixa_mail = @imap_open ("{localhost:143/notls}INBOX", $user, $password) or die ("It was not possible to establish the imap connection."); $uid_msg = 1; $partes_mensagem = obter_partes($caixa_mail, $uid_msg); function obter_partes($imap, $uid, $estrutura = false, $nparte = 1){ if (!$estrutura){ $estrutura = imap_fetchstructure($imap, $uid, FT_UID);} //This shows the headers part number (I need to work a little more on this part) if ($estrutura->parts > 0){ $decimas = explode(".", $nparte); $decimas[count($decimas)-1] -= 1; $np = implode(".", $decimas); } else { $np = $nparte; } //Its a possible message parte (plain or html) if ($estrutura->type == 0){ print "> mensagem: ";} print "$np - ".$estrutura->subtype."<br>"; if (count($estrutura->parts) > 0){ foreach ($estrutura->parts as $n => $parte){ if ($n >= 1){ $arr_decimas = explode(".", $nparte); $arr_decimas[count($arr_decimas)-1] += 1; $nparte = implode(".", $arr_decimas); } if ($parte->type != 1){ if ($parte->type == 0){ print "mensagem: ";} print "$nparte - ".$parte->subtype."<br>"; } if (count($parte->parts) > 0){ if ($parte->type == 1){ obter_partes($imap, $uid, $parte, $nparte.".".($n+1)); } else { foreach ($parte->parts as $idx => $prt){ obter_partes($imap, $uid, $prt, $nparte.".".($idx+1)); } } } } } } ?> --was-- I'm programing an webmail program and trying to make the less code possible, so I've made this function to get all mail parts Hope it helps someone or if you manage to improve this function please post me. $caixa_mail = @imap_open ("{localhost:143/notls}INBOX", $user, $password) or die ("It was not possible to establish the imap connection."); $uid_msg = 1; $partes_mensagem = obter_partes($caixa_mail, $uid_msg); function obter_partes($imap, $uid, $estrutura = false, $nparte = 1){ if (!$estrutura){ $estrutura = imap_fetchstructure($imap, $uid, FT_UID);} //This shows the headers part number (I need to work a little more on this part) if ($estrutura->parts > 0){ $decimas = explode(".", $nparte); $decimas[count($decimas)-1] -= 1; $np = implode(".", $decimas); } else { $np = $nparte; } //Its a possible message parte (plain or html) if ($estrutura->type == 0){ print "> mensagem: ";} print "$np - ".$estrutura->subtype."<br>"; if (count($estrutura->parts) > 0){ foreach ($estrutura->parts as $n => $parte){ if ($n >= 1){ $arr_decimas = explode(".", $nparte); $arr_decimas[count($arr_decimas)-1] += 1; $nparte = implode(".", $arr_decimas); } if ($parte->type != 1){ if ($parte->type == 0){ print "mensagem: ";} print "$nparte - ".$parte->subtype."<br>"; } if (count($parte->parts) > 0){ if ($parte->type == 1){ obter_partes($imap, $uid, $parte, $nparte.".".($n+1)); } else { foreach ($parte->parts as $idx => $prt){ obter_partes($imap, $uid, $prt, $nparte.".".($idx+1)); } } } } } } http://php.net/manual/en/function.imap-fetchstructure.php

« previous php.notes (#145955) next »