Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14369 > unrolled thread

mail attachment

Started byJan Novak <repcom@gmail.com>
First post2014-10-21 15:14 +0200
Last post2014-10-23 06:07 -0400
Articles 14 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  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

#14369 — mail attachment

FromJan Novak <repcom@gmail.com>
Date2014-10-21 15:14 +0200
Subjectmail attachment
Message-ID<m25ma0$bmf$1@news.albasani.net>
Hi again,

i want to get mails from my mailbox and the attachments.
With pop3 and notls ist working, but with pop3 and SSL it doesent.
Also it does not work with imap and notls. With imap an tls i get 
everythin, but the attachment.
Before i post my (long) code: is there a special thing to know about that ?
I have try any combinations aith tls/notls, ssl .

jan

[toc] | [next] | [standalone]


#14370

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-10-22 20:42 +0200
Message-ID<10481010.O8SIMfjRTL@PointedEars.de>
In reply to#14369
Jan Novak wrote:

> i want to get mails from my mailbox and the attachments.

Use an existing MTA or a MUA; _not_ PHP.

> With pop3 and notls ist working, but with pop3 and SSL it doesent.

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.

> Also it does not work with imap and notls. With imap an tls i get
> everythin, but the attachment.
> Before i post my (long) code:

Either post only the relevant parts, or post the URI of the (remaining) 
code.

> is there a special thing to know about that ?

The host name of your e-mail server so that, hopefully, one can determine 
its capabilities.

> I have try any combinations aith tls/notls, ssl .

Make sure that your e-mail provider supports any of these protocols.


The pronoun ā€œIā€ is always spelled with a capital letter.  In English as well 
as in your native German, punctuation is usually _not_ preceded by 
whitespace.  (This is different, e.g., in French.)

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14373

FromJan Novak <repcom@gmail.com>
Date2014-10-23 08:43 +0200
Message-ID<m2a83a$u0o$1@news.albasani.net>
In reply to#14370
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.

> 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 !

> 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 !


> Make sure that your e-mail provider supports any of these protocols.

Absolutly right. This is an basic and i does it.

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



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);
	}
	if ($structure) {
		if ($mimetype == get_mime_type($structure)) {
			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);
}














[toc] | [prev] | [next] | [standalone]


#14389

FromChuck Anderson <cycletourist@invalid.invalid>
Date2014-10-23 23:59 -0600
Message-ID<m2cpr3$kom$1@dont-email.me>
In reply to#14373
Jan Novak wrote:
>
> 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
>
 
[code snipped]

I didn't read all of your code, but will toss out this bit of advice.

I wrote an IMAP email client using Php - and I borrowed (script and 
concepts) from a script posted on the php.net site to write the parser 
for message parts, including attachments.  It's been working flawlessly 
for over a year.

http://php.net/manual/en/function.imap-fetchstructure.php#85486

Also, when I connect I use port 993 and these option flags: 
/imap/ssl/novalidate-cert

I convert all text message parts to utf-8 and save them to a database. I 
decode (base64) attachments and save them as a file.

Maybe something in all of that will help you.

-- 
*****************************
 Chuck Anderson • Boulder, CO
  http://cycletourist.com
 Turn Off, Tune Out, Drop In
*****************************

[toc] | [prev] | [next] | [standalone]


#14395

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-10-24 11:21 -0400
Message-ID<m2dqot$477$1@dont-email.me>
In reply to#14373
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
==================

[toc] | [prev] | [next] | [standalone]


#14412

FromJan Novak <repcom@gmail.com>
Date2014-10-27 09:23 +0100
Message-ID<m2kvg0$3ts$1@news.albasani.net>
In reply to#14395
Am 24.10.2014 um 17:21 schrieb Jerry Stuckle:

> To start, on your development system, ensure you have in your php.ini file:
>
> error_reporting=E_ALL;
> display_errors=on;

yes, its there !

> 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.

It sounds interesting - i use eclipse too.

>
> But lacking a debugger, you can add some statements to For more
> diagnostic information, please see below.

>> 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;


Then i get this below from the Mailbox (and like you see: no attachment 
will be shown - but there is already one file attached when i look into 
my mailbox with a mailer).
The connection is with imap on port 993 with /ssl/novalidate-cert 
options (because it is a self signed cert).
If i make the connection with pop and /notls (and port110) i get 
everything, but - you know - i dont want to use unencrypted  protokoll.

object(stdClass)#14 (11) { ["type"]=> int(1) ["encoding"]=> int(0) 
["ifsubtype"]=> int(1) ["subtype"]=> string(5) "MIXED" 
["ifdescription"]=> int(0) ["ifid"]=> int(0) ["ifdisposition"]=> int(0) 
["ifdparameters"]=> int(0) ["ifparameters"]=> int(1) ["parameters"]=> 
array(1) { [0]=> object(stdClass)#15 (2) { ["attribute"]=> string(8) 
"boundary" ["value"]=> string(36) "------------090702060002040607040204" 
} } ["parts"]=> array(2) { [0]=> object(stdClass)#16 (12) { ["type"]=> 
int(0) ["encoding"]=> int(0) ["ifsubtype"]=> int(1) ["subtype"]=> 
string(5) "PLAIN" ["ifdescription"]=> int(0) ["ifid"]=> int(0) 
["lines"]=> int(4) ["bytes"]=> int(18) ["ifdisposition"]=> int(0) 
["ifdparameters"]=> int(0) ["ifparameters"]=> int(1) ["parameters"]=> 
array(2) { [0]=> object(stdClass)#17 (2) { ["attribute"]=> string(7) 
"charset" ["value"]=> string(12) "windows-1252" } [1]=> 
object(stdClass)#18 (2) { ["attribute"]=> string(6) "format" ["value"]=> 
string(6) "flowed" } } } [1]=> object(stdClass)#19 (13) { ["type"]=> 
int(3) ["encoding"]=> int(3) ["ifsubtype"]=> int(1) ["subtype"]=> 
string(3) "PDF" ["ifdescription"]=> int(0) ["ifid"]=> int(0) ["bytes"]=> 
int(121404) ["ifdisposition"]=> int(1) ["disposition"]=> string(10) 
"attachment" ["ifdparameters"]=> int(1) ["dparameters"]=> array(1) { 
[0]=> object(stdClass)#20 (2) { ["attribute"]=> string(8) "filename" 
["value"]=> string(27) "Dok 27. Okt. 2014 08:24.pdf" } } 
["ifparameters"]=> int(1) ["parameters"]=> array(1) { [0]=> 
object(stdClass)#21 (2) { ["attribute"]=> string(4) "name" ["value"]=> 
string(27) "Dok 27. Okt. 2014 08:24.pdf" } } } } } object(stdClass)#16 
(12) { ["type"]=> int(0) ["encoding"]=> int(0) ["ifsubtype"]=> int(1) 
["subtype"]=> string(5) "PLAIN" ["ifdescription"]=> int(0) ["ifid"]=> 
int(0) ["lines"]=> int(4) ["bytes"]=> int(18) ["ifdisposition"]=> int(0) 
["ifdparameters"]=> int(0) ["ifparameters"]=> int(1) ["parameters"]=> 
array(2) { [0]=> object(stdClass)#17 (2) { ["attribute"]=> string(7) 
"charset" ["value"]=> string(12) "windows-1252" } [1]=> 
object(stdClass)#18 (2) { ["attribute"]=> string(6) "format" ["value"]=> 
string(6) "flowed" } } } object(stdClass)#19 (13) { ["type"]=> int(3) 
["encoding"]=> int(3) ["ifsubtype"]=> int(1) ["subtype"]=> string(3) 
"PDF" ["ifdescription"]=> int(0) ["ifid"]=> int(0) ["bytes"]=> 
int(121404) ["ifdisposition"]=> int(1) ["disposition"]=> string(10) 
"attachment" ["ifdparameters"]=> int(1) ["dparameters"]=> array(1) { 
[0]=> object(stdClass)#20 (2) { ["attribute"]=> string(8) "filename" 
["value"]=> string(27) "Dok 27. Okt. 2014 08:24.pdf" } } 
["ifparameters"]=> int(1) ["parameters"]=> array(1) { [0]=> 
object(stdClass)#21 (2) { ["attribute"]=> string(4) "name" ["value"]=> 
string(27) "Dok 27. Okt. 2014 08:24.pdf" } } } object(stdClass)#19 (11) 
{ ["type"]=> int(1) ["encoding"]=> int(0) ["ifsubtype"]=> int(1) 
["subtype"]=> string(5) "MIXED" ["ifdescription"]=> int(0) ["ifid"]=> 
int(0) ["ifdisposition"]=> int(0) ["ifdparameters"]=> int(0) 
["ifparameters"]=> int(1) ["parameters"]=> array(1) { [0]=> 
object(stdClass)#21 (2) { ["attribute"]=> string(8) "boundary" 
["value"]=> string(36) "------------090702060002040607040204" } } 
["parts"]=> array(2) { [0]=> object(stdClass)#20 (12) { ["type"]=> 
int(0) ["encoding"]=> int(0) ["ifsubtype"]=> int(1) ["subtype"]=> 
string(5) "PLAIN" ["ifdescription"]=> int(0) ["ifid"]=> int(0) 
["lines"]=> int(4) ["bytes"]=> int(18) ["ifdisposition"]=> int(0) 
["ifdparameters"]=> int(0) ["ifparameters"]=> int(1) ["parameters"]=> 
array(2) { [0]=> object(stdClass)#14 (2) { ["attribute"]=> string(7) 
"charset" ["value"]=> string(12) "windows-1252" } [1]=> 
object(stdClass)#16 (2) { ["attribute"]=> string(6) "format" ["value"]=> 
string(6) "flowed" } } } [1]=> object(stdClass)#18 (13) { ["type"]=> 
int(3) ["encoding"]=> int(3) ["ifsubtype"]=> int(1) ["subtype"]=> 
string(3) "PDF" ["ifdescription"]=> int(0) ["ifid"]=> int(0) ["bytes"]=> 
int(121404) ["ifdisposition"]=> int(1) ["disposition"]=> string(10) 
"attachment" ["ifdparameters"]=> int(1) ["dparameters"]=> array(1) { 
[0]=> object(stdClass)#17 (2) { ["attribute"]=> string(8) "filename" 
["value"]=> string(27) "Dok 27. Okt. 2014 08:24.pdf" } } 
["ifparameters"]=> int(1) ["parameters"]=> array(1) { [0]=> 
object(stdClass)#15 (2) { ["attribute"]=> string(4) "name" ["value"]=> 
string(27) "Dok 27. Okt. 2014 08:24.pdf" } } } } } object(stdClass)#20 
(12) { ["type"]=> int(0) ["encoding"]=> int(0) ["ifsubtype"]=> int(1) 
["subtype"]=> string(5) "PLAIN" ["ifdescription"]=> int(0) ["ifid"]=> 
int(0) ["lines"]=> int(4) ["bytes"]=> int(18) ["ifdisposition"]=> int(0) 
["ifdparameters"]=> int(0) ["ifparameters"]=> int(1) ["parameters"]=> 
array(2) { [0]=> object(stdClass)#14 (2) { ["attribute"]=> string(7) 
"charset" ["value"]=> string(12) "windows-1252" } [1]=> 
object(stdClass)#16 (2) { ["attribute"]=> string(6) "format" ["value"]=> 
string(6) "flowed" } } }

mimetype=TEXT/PLAIN

[toc] | [prev] | [next] | [standalone]


#14416

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-10-27 14:16 -0400
Message-ID<m2m268$7p0$1@dont-email.me>
In reply to#14412
On 10/27/2014 4:23 AM, Jan Novak wrote:
<snip>

Hi, Jan,

I hate the way usenet reformats data :)  I'll need to reformat it into
something readable, then I'll get back to you.

Just wanted you to know I'm not ignoring you :)

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14418

FromJan Novak <repcom@gmail.com>
Date2014-10-28 11:58 +0100
Message-ID<m2nsuc$jt6$1@news.albasani.net>
In reply to#14416
Am 27.10.2014 um 19:16 schrieb Jerry Stuckle:
> On 10/27/2014 4:23 AM, Jan Novak wrote:
> <snip>
>
> Hi, Jan,
>
> I hate the way usenet reformats data :)  I'll need to reformat it into
> something readable, then I'll get back to you.
>
> Just wanted you to know I'm not ignoring you :)
>

Wow ... thank you very much ... no problem, this is a public forum - its 
not a support center, where you have sla's :-)))))

jan

[toc] | [prev] | [next] | [standalone]


#14419

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-10-28 08:21 -0400
Message-ID<m2o1n9$8ek$1@dont-email.me>
In reply to#14418
On 10/28/2014 6:58 AM, Jan Novak wrote:
> Am 27.10.2014 um 19:16 schrieb Jerry Stuckle:
>> On 10/27/2014 4:23 AM, Jan Novak wrote:
>> <snip>
>>
>> Hi, Jan,
>>
>> I hate the way usenet reformats data :)  I'll need to reformat it into
>> something readable, then I'll get back to you.
>>
>> Just wanted you to know I'm not ignoring you :)
>>
> 
> Wow ... thank you very much ... no problem, this is a public forum - its
> not a support center, where you have sla's :-)))))
> 
> jan

No, but most of us have been in your position in the past, and we try to
help each other.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14417

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-10-27 16:44 -0400
Message-ID<m2mare$ao1$1@dont-email.me>
In reply to#14373
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.
> 
>> 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 !
> 
>> 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 !
> 
> 
>> Make sure that your e-mail provider supports any of these protocols.
> 
> Absolutly right. This is an basic and i does it.
> 
> 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
> 
> 
> 
> 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);
>     }
>     if ($structure) {
>         if ($mimetype == get_mime_type($structure)) {
>             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);
> }
> 
> 

Jan, looking at your code it seems to be incomplete.  Where do you call
any of your attachment-related functions?  Is it somewhere else in your
code?

Also, it looks like your get_part() routine will only fetch parts that
have a mime_type of TEXT/PLAIN.  Again, is there more to your code than
this?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14420

FromJan Novak <repcom@gmail.com>
Date2014-10-28 14:16 +0100
Message-ID<m2o51s$4s4$1@news.albasani.net>
In reply to#14417
Am 27.10.2014 um 21:44 schrieb Jerry Stuckle:


 > Also, it looks like your get_part() routine will only fetch parts that
 > have a mime_type of TEXT/PLAIN.


>> function get_part($imap, $uid, $mimetype, $structure = false,
>> $partNumber = false) {
>>      if (!$structure) {
>>          $structure = imap_fetchstructure($imap, $uid, FT_UID);
>>      }

... the structure will get from the function below:

>> 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";
>> }

I get always "TEXT/PLAIN". And it never mind, if i use pop without ssl 
or imap with ssl. But - like i told it - with imap i dont get the 
attachment.

But the difference is that:
This is the var_dump with POP and notls:
object(stdClass)#6 (12) { ["type"]=> int(1) ["encoding"]=> int(0) 
["ifsubtype"]=> int(1) ["subtype"]=> string(5) "MIXED" 
["ifdescription"]=> int(0) ["ifid"]=> int(0) ["bytes"]=> int(121873) 
["ifdisposition"]=> int(0) ["ifdparameters"]=> int(0) ["ifparameters"]=> 
int(1) ["parameters"]=> array(1) { [0]=> object(stdClass)#7 (2) { 
["attribute"]=> string(8) "BOUNDARY" ["value"]=> string(36) 
"------------090702060002040607040204" } } ["parts"]=> array(2) { [0]=> 
object(stdClass)#8 (12) { ["type"]=> int(0) ["encoding"]=> int(0) 
["ifsubtype"]=> int(1) ["subtype"]=> string(5) "PLAIN" 
["ifdescription"]=> int(0) ["ifid"]=> int(0) ["lines"]=> int(4) 
["bytes"]=> int(18) ["ifdisposition"]=> int(0) ["ifdparameters"]=> 
int(0) ["ifparameters"]=> int(1) ["parameters"]=> array(2) { [0]=> 
object(stdClass)#9 (2) { ["attribute"]=> string(7) "CHARSET" ["value"]=> 
string(12) "windows-1252" } [1]=> object(stdClass)#10 (2) { 
["attribute"]=> string(6) "FORMAT" ["value"]=> string(6) "flowed" } } } 
[1]=> object(stdClass)#11 (13) { ["type"]=> int(3) ["encoding"]=> int(3) 
["ifsubtype"]=> int(1) ["subtype"]=> string(3) "PDF" ["ifdescription"]=> 
int(0) ["ifid"]=> int(0) ["bytes"]=> int(121404) ["ifdisposition"]=> 
int(1) ["disposition"]=> string(10) "ATTACHMENT" ["ifdparameters"]=> 
int(1) ["dparameters"]=> array(1) { [0]=> object(stdClass)#12 (2) { 
["attribute"]=> string(8) "FILENAME" ["value"]=> string(27) "Dok 27. 
Okt. 2014 08:24.pdf" } } ["ifparameters"]=> int(1) ["parameters"]=> 
array(1) { [0]=> object(stdClass)#13 (2) { ["attribute"]=> string(4) 
"NAME" ["value"]=> string(27) "Dok 27. Okt. 2014 08:24.pdf" } } } } }



and this is the var_dump with imap and ssl:

object(stdClass)#6 (11) { ["type"]=> int(1) ["encoding"]=> int(0) 
["ifsubtype"]=> int(1) ["subtype"]=> string(5) "MIXED" 
["ifdescription"]=> int(0) ["ifid"]=> int(0) ["ifdisposition"]=> int(0) 
["ifdparameters"]=> int(0) ["ifparameters"]=> int(1) ["parameters"]=> 
array(1) { [0]=> object(stdClass)#7 (2) { ["attribute"]=> string(8) 
"boundary" ["value"]=> string(36) "------------090702060002040607040204" 
} } ["parts"]=> array(2) { [0]=> object(stdClass)#8 (12) { ["type"]=> 
int(0) ["encoding"]=> int(0) ["ifsubtype"]=> int(1) ["subtype"]=> 
string(5) "PLAIN" ["ifdescription"]=> int(0) ["ifid"]=> int(0) 
["lines"]=> int(4) ["bytes"]=> int(18) ["ifdisposition"]=> int(0) 
["ifdparameters"]=> int(0) ["ifparameters"]=> int(1) ["parameters"]=> 
array(2) { [0]=> object(stdClass)#9 (2) { ["attribute"]=> string(7) 
"charset" ["value"]=> string(12) "windows-1252" } [1]=> 
object(stdClass)#10 (2) { ["attribute"]=> string(6) "format" ["value"]=> 
string(6) "flowed" } } } [1]=> object(stdClass)#11 (13) { ["type"]=> 
int(3) ["encoding"]=> int(3) ["ifsubtype"]=> int(1) ["subtype"]=> 
string(3) "PDF" ["ifdescription"]=> int(0) ["ifid"]=> int(0) ["bytes"]=> 
int(121404) ["ifdisposition"]=> int(1) ["disposition"]=> string(10) 
"attachment" ["ifdparameters"]=> int(1) ["dparameters"]=> array(1) { 
[0]=> object(stdClass)#12 (2) { ["attribute"]=> string(8) "filename" 
["value"]=> string(27) "Dok 27. Okt. 2014 08:24.pdf" } } 
["ifparameters"]=> int(1) ["parameters"]=> array(1) { [0]=> 
object(stdClass)#13 (2) { ["attribute"]=> string(4) "name" ["value"]=> 
string(27) "Dok 27. Okt. 2014 08:24.pdf" } } } } }



you see, that the attachment is not at the same place within the $part 
object.


Jan

[toc] | [prev] | [next] | [standalone]


#14421 — SOLVED: mail attachment

FromJan Novak <repcom@gmail.com>
Date2014-10-28 14:25 +0100
SubjectSOLVED: mail attachment
Message-ID<m2o5jc$5pk$1@news.albasani.net>
In reply to#14420
The problem was this:


in pop the part will be returned as lower case, in imap (whyever) in 
uppercase. So i change this

if ( $part->disposition == "ATTACHMENT") {

to

if ( strtoupper($part->disposition) == "ATTACHMENT") {


and it works !!!
Thanks Jerry, you got me on the right track!!!!

Jan

[toc] | [prev] | [next] | [standalone]


#14422 — Re: SOLVED: mail attachment

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-10-28 09:35 -0400
SubjectRe: SOLVED: mail attachment
Message-ID<m2o631$n72$1@dont-email.me>
In reply to#14421
On 10/28/2014 9:25 AM, Jan Novak wrote:
> The problem was this:
> 
> 
> in pop the part will be returned as lower case, in imap (whyever) in
> uppercase. So i change this
> 
> if ( $part->disposition == "ATTACHMENT") {
> 
> to
> 
> if ( strtoupper($part->disposition) == "ATTACHMENT") {
> 
> 
> and it works !!!
> Thanks Jerry, you got me on the right track!!!!
> 
> Jan
> 

Ah, glad you found it.  I hadn't gotten that far yet.  This is where a
debugger really comes in handy :)

BTW - it doesn't matter WHERE in the object the value "attachment"
appears - what counts is the member name, which is "disposition" in both
cases.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14376

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-10-23 06:07 -0400
Message-ID<m2ak02$n3n$1@dont-email.me>
In reply to#14369
On 10/21/2014 9:14 AM, Jan Novak wrote:
> Hi again,
> 
> i want to get mails from my mailbox and the attachments.
> With pop3 and notls ist working, but with pop3 and SSL it doesent.
> Also it does not work with imap and notls. With imap an tls i get
> everythin, but the attachment.
> Before i post my (long) code: is there a special thing to know about that ?
> I have try any combinations aith tls/notls, ssl .
> 
> jan

Sorry, I missed this one when it went by the first time.

OK, so what's the difference in your code?  I admit I don't use PHP to
receive mail very often (more often to send mail), but there shouldn't
be that much difference.

Do you get any messages from the MTA?  Is there anything in the MTA's log?

Please don't post long code - extract the appropriate parts and post
them.  People won't look at hundreds of lines of code.

And BTW - just ignore "Pointed Head".  He's one of the resident trolls,
and the only time he's right about something is when someone else posted
the correct solution a couple of days earlier.  A perfect case in point
- SSL is far from obsolete.  POODLE is a new vulnerability, but only for
SSL3.0 and normally requires the hacker to act as "Man-in-the-Middle".
Now that this vulnerability has been discovered, I expect it to be fixed
soon.  You don't just throw out a whole protocol because of a
vulnerability - you fix the vulnerability.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web