Solved

IMAP get entire message

Posted on 2012-04-09
3
368 Views
Last Modified: 2012-04-11
Hi all,
Ive been struggling with this for a while, so hopefully someone can help.

This is a very simple script using PHP imap functions to read a mailbox. Is there a function I can use to get the entire source of the message (the same as I would see if I was viewing the source in outlook etc). So for a mime message I would get the entire thing, headers and everything?


<?php


    $imap = imap_open("{SERVER}", "email@domain.com", "password");
    $message_count = imap_num_msg($imap);



    for ($i = 1; $i <= $message_count; ++$i) {
        $header = imap_header($imap, $i);
        $body = imap_fetchbody($imap, $i,$partno);
        $prettydate = date("jS F Y", $header->udate);

        if (isset($header->from[0]->personal)) {
            $personal = $header->from[0]->personal;
        } else {
            $personal = $header->from[0]->mailbox;
        }
$body=imap_base64($body);
        $email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>";
        echo "On $prettydate, $email said \"$body\".\n";
    }

    imap_close($imap);

      
      
      
      ?>
0
Comment
Question by:fox_statton
  • 2
3 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37827042
Please see: http://php.net/manual/en/function.imap-fetchstructure.php

I've had some luck using an email "pipe" script to access all of the inbound messages for a given email address.  The server associates the pipe with an email address and instead of putting the messages into an inbox, the server starts the pipe script.  The pipe reads the email from STDIN.  Each line of the input looks exactly like what you would expect to see if you did "view source" and read the text a line at a time.
0
 

Author Closing Comment

by:fox_statton
ID: 37834890
Perfect thanks!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37834956
Thanks for the points!  Best of luck with your project, ~Ray
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now