Re: MIME files decoding
| From: | Justin Patrin | Date: | Thu, 15 Jul 2004 18:42:44 +0000 |
| Subject: | Re: MIME files decoding | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13713@lists.php.net to get a copy of this message | ||
Sorry, I don't really know anything about the POP3 class. I'd suggest
looking into the code and see how it's connecting. Make sure the
strings are right. See if it's encoding the user/pass in any way and
try changing it. Try the newest CVS version, check the bugs, contact
the package author.
;-)
----- Original Message -----
From: C.F. Scheidecker Antunes <nando@antunes.eti.br>
Date: Thu, 15 Jul 2004 12:34:39 -0600
Subject: Re: [PEAR] MIME files decoding
To: papercrane@reversefold.com, PEAR General <pear-general@lists.php.net>
Thanks Justin.
I now have a problem with pop3->login() which always return false
although I can use this user name and password with a java application
that I have created. Is there any way to debug it to understand why it
is not login in? I always get false after a $pop3->login() call. Am
I calling it wrong? Does it have to have the @ + the domain name for
the user parameter of this function?
here's the code:
#!/usr/bin/php -q
<?php
include_once('Net/POP3.php');
include_once('Mail/mimeDecode.php');
set_time_limit(0);
$pop3Server = 'pop.myserver.com';
$pop3Domain = 'myserver.com';
$pop3User = 'user3';
$pop3Pass = 'user3pass';
// Log in
$pop3 =& new Net_POP3();
if ($pop3->connect($pop3Server, 110)) {
if ($pop3->login($pop3User, $pop3Pass)) {
$mailbox = $pop3->getListing();
foreach($mailbox as $mail){ // read the Subject using Net_POP3
(could also be done in MAIL_MIME)
$headers = $pop3->getParsedHeaders($mail['msg_id']);
$subject = $headers['Subject']; // Extract the entire mail
message
$email = $pop3->getMsg($mail['msg_id']); // Set some
Mail_mime configuration parameters
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$decoder = new Mail_mimeDecode($email); // Decode the
message
$message = $decoder->decode($params); // Step through
the parts and extract text and html
foreach ($message->parts as $part){
if (strstr($part->headers['content-type'],
'text/html')){ $html = $part->body; }
if (strstr($part->headers['content-type'],
'text/plain')){ $text = $part->body; }
} // Output the subject, text and html
}
} // login
else {
echo "Error loging in \n";
}
$pop3->disconnect();
} // if
else {
echo "Error connecting to pop server \n";
}
?>
Justin Patrin wrote:
On Thu, 15 Jul 2004 11:29:51 -0600, C.F. Scheidecker Antunes
<nando@antunes.eti.br> wrote:
Hello all,
In order to use pear mimedecode.php I have a few questions that were not
answered by the documentation.
I have emails that have .zip, .pdf, .txt and .csv files.
Some emails have more than one attachment.
I would like to have a php script to fetch these emails and save only
those with .zip , .txt and .csv deleting everything else.
Can anyone point me how to use mimedecode so that I can keep the
original filename of the attachment. How can I obtain the file name?
(The following is untested, but should work)
//$mailObj is passed by ref as it could be big
function getFiles(&$mailObj, $fileTypes = array('.zip', '.txt',
'.csv')) {
if($mailObj->ctype_primary == 'multipart') {
//normally I'd do a foreach here, but the parts may be big (files)
for($i = 0; $i < count($mailObj->parts); ++$i) {
getFiles($mailObj->parts[$i], $fileTypes);
}
} else {
if(in_array(substr($mailObj->d_parameters['filename'], -4), $fileTypes)) {
$fd = fopen($mailObj->d_parameters['filename'], 'w');
fwrite($fd, $mailObj->body);
}
}
}
$mailSource = The full source text of the e-mail, including headers and body;
getFiles(Mail_mimeDecode::decode(array('decode_body' => true,
'include_body' => true, 'decode_headers' => true, 'input' =>
$mailSource)));
!DSPAM:40f6cd70243991864824043!
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--