Re: display imap attached files?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fredrik Hampus wrote:
Hi!

Iam trying too make a page where the function is to display an attached .jpg file
from a imap mailbox. This is a small code i found and rewrote some...


<?php
include '/etc/labbuser';
$mbox = imap_open ("{localhost:993/imap/ssl/novalidate-cert}INBOX", "$imuser", "$impass");
$mno = "57";


$parttypes = array ("text", "multipart", "message", "application", "audio", "image", "video", "other");
function buildparts ($struct, $mno = "") {
global $parttypes;
switch ($struct->type):
case 1:
$r = array ();
$i = 1;
foreach ($struct->parts as $part)
$r[] = buildparts ($part, $mno.".".$i++);


       return implode (", ", $r);
     case 2:

       return "{".buildparts ($struct->parts[0], $mno)."}";
     default:
        echo "--Size--";
        echo $struct->bytes;
        echo " ";
        echo $struct->subtype;
        echo "<br>";
        if ($struct->subtype == "JPEG") {
        echo "MATCH";
        echo "<br>";
        }

return '<a href="?p='.substr ($mno, 1).'">'.$parttypes[$struct->type]."/".strtolower ($struct->subtype)."</a>";
endswitch;
}
$struct = imap_fetchstructure ($mbox, $mno);


  echo buildparts ($struct);
imap_close($mbox);
?>


This will display how many parts there is in the mail and the size of each one of them and what type they are.
but how do a display the image of an attached jpg file on a webpage?

I have never worked with the imap funcs but:

you probably need to create an image output script which the above scripts' output points to. so if a struct is/contains an then you spit out an image tag:

echo "<img src=\"/imap-img.php?mno=$mno&struct=$structId\">";

the imap-img.php script opens the request struct of the requested message and echos out the data contained (which would be the image data) - it also needs to echo out the correct headers so that the image data is recognized as an image.

needless to say both scripts should be checking that the user is logged in or something - unless we are all allowed to look in your inbox ;-)

hope that gives you an idea on how to continue.

good luck :-)


//Fredrik


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux