What exactly is the end goal after you have the message in an ".eml"
file?

If you just fetch the WHOLE damn thing with IMAP and dump it into a
file and name it "whatever.eml" then you're done, by the way.

So imap_fetchheader, find out how many body parts there are,
imap_fetchbody for each one, dump all that crap into a file and put a
fork in it.

On Fri, July 20, 2007 12:43 pm, bkozora wrote:
>
> Thanks for your help. How would I go about getting procmail to forward
> it?
>
> What I currently have is a script that connects to a free email
> address that
> collects bounces captured from newsletters the system has sent. I'm
> using
> IMAP to connect to the mailbox, then looping through and trying to
> create
> the eml files. I don't know if the procmail approach would work, as I
> can
> only access my email through IMAP (not even POP3).
>
> Last night while examining some eml files and cross referencing to the
> value
> imap_body returned, I was thinking I may be able to just dump that to
> a
> file. Do you think that would work? There's a class on phpclasses that
> handles bounces, but it requires eml files
> (http://www.phpclasses.org/browse/package/2691.html).
>
> Here is my code as it is now, don't know if that would help or not:
>
> ############### CODE ###############
>
> $imap = imap_open("{mail.messagingengine.com:143}INBOX", "**", "**");
>
> $message_count = imap_num_msg($imap);
>
> echo "<h3>$message_count Emails Returned</h3>";
>
>
> for ($i = 1; $i <= $message_count; ++$i)
> {
>       $header = imap_header($imap, $i);
>
>       if (isset($header->from[0]->personal))
>       {
>               $personal = $header->from[0]->personal;
>       }
>       else
>       {
>               $personal = $header->from[0]->mailbox;
>       }
>
>       $eml = "date : $header->Date \n";
>       $eml .= "from : $personal
> <{$header->from[0]->[EMAIL PROTECTED]>from[0]->host}> \n";
>       $eml .= "subject : $header->Subject \n";
>       $eml .= "to : $personal
> <{$header->to[0]->[EMAIL PROTECTED]>from[0]->host}> \n";
>
>       $eml .= imap_body($imap, $i, "FT_PEEK")."\n";
>
>       $messageID = imap_bodystruct($imap, $i, "message_id");
>
>       echo "<h3>header</h3><pre style=\"color:red;\">";
>       print_r($header);
>       echo "</pre>";
>
>         echo "<h3>Body</h3><pre style=\"color:red;\">";
>       print_r(imap_body($imap, $i, "FT_PEEK"));
>       echo "</pre>";
>
>       $file = "../eml/".rand(1111, 9999).".eml";
>       if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
>       if (!fwrite($file_handle, $eml)) { echo "Cannot write to file"; }
>       echo "<h4>You have successfully written data to $file</h4>";
>       fclose($file_handle);
>
> }
>
>
> imap_close($imap);
>
>
>
> Thanks,
> Bobby
>
>
> Handa Utsav wrote:
>>
>> Hi there,
>>
>> Well it can be easily done. Just input your mail (make 'procmail'
>> fwd
>> it) to your script & script would save it as .eml .
>>
>> Try to use the following code for script :
>>
>> ######## CODE #####################
>>
>> <?php
>>
>> $email = "";
>> ## Read
>> E-mail
>> $fd = fopen("php://stdin", "r");
>> while (!feof($fd)) {
>> $email .= fread($fd, 1024);
>> }
>> fclose($fd);
>>
>> # Save email
>> $handle = fopen("$path/$file_name.eml","a+");
>>  if (!$handle) {
>>    fwrite($log_handle," Failed ");
>>  }
>>  else {
>>    fwrite($handle,"$email");
>>    fclose($handle);
>>  }
>>
>>
>> ?>
>>
>> Hope this helps you out.
>>
>>
>> Greetings
>> Utsav Handa
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Save-email-as-.eml-file-tf4103444.html#a11712721
> Sent from the PHP - General mailing list archive at Nabble.com.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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

Reply via email to