Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #14395
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: mail attachment |
| Date | 2014-10-24 11:21 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <m2dqot$477$1@dont-email.me> (permalink) |
| References | <m25ma0$bmf$1@news.albasani.net> <10481010.O8SIMfjRTL@PointedEars.de> <m2a83a$u0o$1@news.albasani.net> |
On 10/23/2014 2:43 AM, Jan Novak wrote:
> Am 22.10.2014 um 20:42 schrieb Thomas 'PointedEars' Lahn:
>> Jan Novak wrote:
>>
>>> i want to get mails from my mailbox and the attachments.
>>
>> Use an existing MTA or a MUA; _not_ PHP.
>
>
> ??? So what ?
> For example: If i ask for PHP questions, you answer with - use Java !?
> How can i use in an PHP Code other then PHP ?
> I can not Install an MTA to get some E-Mails from somewhere.
>
Don't mind Pointed Head. He's just one of our resident trolls.
>> SSL is obsolete. Your provider would be wise to have disabled it by now,
>> and you would be wise not to use it anymore; see POODLE.
>
> Yes, but with tls it is the same problem !
>
See above. He has no pertinent answer, but his personality doesn't
allow him to NOT respond.
>> The host name of your e-mail server so that, hopefully, one can determine
>> its capabilities.
>
> This is not relevant, because it does not work on any servers, what i
> have try, so its an (my) PHP problem and thats the reason, why i ask it
> here !
>
But it's Pointed Head - he has to ask something!
>
>> Make sure that your e-mail provider supports any of these protocols.
>
> Absolutly right. This is an basic and i does it.
>
Again, an irrelevant response because he doesn't understand the problem.
> So now i am at the same point as before, therefore below is my code.
> Rmember - for me is important, to get and save the attachment.
>
> Jan
>
OK, as to your problem. I can see some potential problems here, but
rather than just shotgunning your problem, it's time for some diagnosis.
To start, on your development system, ensure you have in your php.ini file:
error_reporting=E_ALL;
display_errors=on;
This may show messages indicating a problem and make things easier.
Look at all of the messages (if any), and understand the reason for each
one. They might not all be problems, but each one can indicate a
possible problem in your code.
Also, this is a great time for using a debugger (I prefer xdebug with
Eclipse IDE). You can step through your code, looking at variables and
function call results. I greatly speeds up troubleshooting on problems
like this.
But lacking a debugger, you can add some statements to For more
diagnostic information, please see below.
>
>
> function getBody($uid, $imap) {
> $body = get_part($imap, $uid, "TEXT/HTML");
> if ($body == "") {
> $body = get_part($imap, $uid, "TEXT/PLAIN");
> }
> return $body;
> }
>
> function get_part($imap, $uid, $mimetype, $structure = false,
> $partNumber = false) {
> if (!$structure) {
> $structure = imap_fetchstructure($imap, $uid, FT_UID);
> }
Everything in the imap_fetch functions depends on the contents of this
structure. So, let's start here. What do you get if you add:
var_dump($structure);
> if ($structure) {
> if ($mimetype == get_mime_type($structure)) {
Also, what is in $mimetype at this point? So does it match the mime
type in $structure?
echo "mimetype=$mimetype\n";
> if (!$partNumber) {
> $partNumber = 1;
> }
> $text = imap_fetchbody($imap, $uid, $partNumber, FT_UID);
> switch ($structure->encoding) {
> case 3: return imap_base64($text);
> case 4: return imap_qprint($text);
> default: return $text;
> }
> }
>
> // multipart
> if ($structure->type == 1) {
> foreach ($structure->parts as $index => $subStruct) {
> $prefix = "";
> if ($partNumber) {
> $prefix = $partNumber . ".";
> }
> $data = get_part($imap, $uid, $mimetype, $subStruct,
> $prefix . ($index + 1));
> if ($data) {
> return $data;
> }
> }
> }
> }
> return false;
> }
>
> function get_mime_type($structure) {
> $primaryMimetype = array("TEXT", "MULTIPART", "MESSAGE",
> "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER");
>
> if ($structure->subtype) {
> return $primaryMimetype[(int)$structure->type] . "/" .
> $structure->subtype;
> }
> return "TEXT/PLAIN";
> }
>
> function downloadAttachment($imap, $uid, $partNum, $encoding, $path) {
> $partStruct = imap_bodystruct($imap, imap_msgno($imap, $uid),
> $partNum);
> $filename = $partStruct->dparameters[0]->value;
> $message = imap_fetchbody($imap, $uid, $partNum, FT_UID);
>
> switch ($encoding) {
> case 0:
> case 1:
> $message = imap_8bit($message);
> break;
> case 2:
> $message = imap_binary($message);
> break;
> case 3:
> $message = imap_base64($message);
> break;
> case 4:
> $message = quoted_printable_decode($message);
> break;
> }
>
> header("Content-Description: File Transfer");
> header("Content-Type: application/octet-stream");
> header("Content-Disposition: attachment; filename=" . $filename);
> header("Content-Transfer-Encoding: binary");
> header("Expires: 0");
> header("Cache-Control: must-revalidate");
> header("Pragma: public");
> echo $message;
>
> }
>
> function saveAttachment($imap, $uid, $partNum, $encoding, $path,
> $attachmentName) {
> $partStruct = imap_bodystruct($imap, imap_msgno($imap, $uid),
> $partNum);
> $filename = $partStruct->dparameters[0]->value;
> $message = imap_fetchbody($imap, $uid, $partNum, FT_UID);
>
> switch ($encoding) {
> case 0:
> case 1:
> $message = imap_8bit($message);
> break;
> case 2:
> $message = imap_binary($message);
> break;
> case 3:
> $message = imap_base64($message);
> break;
> case 4:
> $message = quoted_printable_decode($message);
> break;
> }
>
> $fdw = fopen($path ."/". $attachmentName, "w+");
> fwrite($fdw, $message);
> fclose($fdw);
>
> }
>
>
> function getAttachments($imap, $mailNum, $part, $partNum) {
>
> $attachments = array();
> if (isset($part->parts)) {
> foreach ($part->parts as $key => $subpart) {
> if($partNum != "") {
> $newPartNum = $partNum . "." . ($key + 1);
> }
> else {
> $newPartNum = ($key+1);
> }
> $result = getAttachments($imap, $mailNum, $subpart,
> $newPartNum);
> if (count($result) != 0) {
> array_push($attachments, $result);
> }
> }
> }
> else if (isset($part->disposition)) {
> if ($part->disposition == "ATTACHMENT") {
> $partStruct = imap_bodystruct($imap, $mailNum,
> $partNum);
> $attachmentDetails = array(
> "name" => $part->dparameters[0]->value,
> "partNum" => $partNum,
> "enc" => $partStruct->encoding
> );
> return $attachmentDetails;
> }
> }
>
> return $attachments;
> }
>
> function openimap(){
> global $cfg;
>
> if (extension_loaded("imap")) {
> $mailbox =
> "{".$cfg["FETCH_MAILSERVER"].":".$cfg["FETCH_PORT"]."/".$cfg["FETCH_PROTO"].$cfg["FETCH_PROTOOPTS"]."}INBOX";
>
> $user = $cfg["FETCH_USER"];
> $pass = $cfg["FETCH_PASSWD"];
> $imap = imap_open($mailbox, $user, $pass) or die('Error : ' .
> imap_last_error());;
> $error="";
> } else {
> $error="php5-imap not loaded";
> $imap="";
> }
>
> return array($imap, $error);
> }
>
>
>
Let's start here and see what we come up with.
Sorry I don't have a quicker answer - but as I said, I normally don't
use PHP to fetch email.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
mail attachment Jan Novak <repcom@gmail.com> - 2014-10-21 15:14 +0200
Re: mail attachment Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-22 20:42 +0200
Re: mail attachment Jan Novak <repcom@gmail.com> - 2014-10-23 08:43 +0200
Re: mail attachment Chuck Anderson <cycletourist@invalid.invalid> - 2014-10-23 23:59 -0600
Re: mail attachment Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-24 11:21 -0400
Re: mail attachment Jan Novak <repcom@gmail.com> - 2014-10-27 09:23 +0100
Re: mail attachment Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-27 14:16 -0400
Re: mail attachment Jan Novak <repcom@gmail.com> - 2014-10-28 11:58 +0100
Re: mail attachment Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-28 08:21 -0400
Re: mail attachment Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-27 16:44 -0400
Re: mail attachment Jan Novak <repcom@gmail.com> - 2014-10-28 14:16 +0100
SOLVED: mail attachment Jan Novak <repcom@gmail.com> - 2014-10-28 14:25 +0100
Re: SOLVED: mail attachment Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-28 09:35 -0400
Re: mail attachment Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-23 06:07 -0400
csiph-web