Solved

Email Retrieval: Status and speed issues

Posted on 2002-06-10
5
348 Views
Last Modified: 2011-09-20
I have two questions:

1) I am currently using PHP's build in "imap" email functions.  Im specificaly trying to retrieve POP3 email.
The question here is, what is the fastest way, using PHP, to get POP3 Email.  Is it using the "imap" functions, or would opening a telnet be faster?  And is there anything faster than that?

2) As stated above, im using the "imap" function family to retrieve my POP3 Email, but for some reason the imap_header function returns an object which when digging through returns some elements which i can only guess are status.  but they never change, they are always the same.  And the 'Recent' field is always set to 'N'
Here is what I mean:
[Recent]: N
[Unseen]:
[Flagged]:
[Answered]:
[Deleted]:
[Draft]:

The above is typical no matter how recent, unviewed, etc.. the email seems to be.  Is there something I'm doing wrong?  Is checking the email headers marking the email as read?  Or am I just totaly misinterpeting what I'm seeing.  Could it be my imap_open?

:Figment
0
Comment
Question by:Figment060799
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
With a telnet session, you would have to do all the work yourself.

This is not too difficult, but some of the imap functions should make all of this a little easier.

Checking the email headers should not mark the email as read.

That could be done with imap_setflag_full

-----------------------------------------------------------
 

imap_setflag_full
(PHP 3>= 3.0.3, PHP 4 )

imap_setflag_full -- Sets flags on messages
Description
string imap_setflag_full ( int stream, string sequence, string flag, string options)


This function causes a store to add the specified flag to the flags set for the messages in the specified sequence.

The flags which you can set are "\\Seen", "\\Answered", "\\Flagged", "\\Deleted", "\\Draft", and "\\Recent" (as defined by RFC2060).

The options are a bit mask with one or more of the following:



ST_UID          The sequence argument contains UIDs instead of
                sequence numbers
     



Example 1. imap_setflag_full() example

$mbox = imap_open("{your.imap.host:143}","username","password")
     or die("can't connect: ".imap_last_error());
 
$status = imap_setflag_full($mbox,"2,5","\\Seen \\Flagged");
 
print gettype($status)."\n";
print $status."\n";
 
imap_close($mbox);
 
-----------------------------------------------------------

I've had a little look through the imap functions and they all seem to be fairly simple in what they do. So, getting headers only gets headers. To "read" an email means setting the "Seen" flag. Each function does not a lot.

So, to get the email and delete it is a fair number of steps.

I am not a POP expert, but I suspect that once you've connected to the mailbox, you need to see if there is any mail to read, then go through each message and fetch the message body. Once you've done with it what you want, you would need to mark the message for deletion and when you've finished with all of them, tell the system to delete all the marked messages (expunge).

There will be better explanations out there, as well as tools which probably do what you are looking for. Something called SquirrelMail is one that springs to mind (and only because I was ICQ'ing one of the developers a week ago!).

Regards,

Richard Quadling.
0
 

Author Comment

by:Figment060799
Comment Utility
That doesnt really answer my question though..

However im having troubles changing status on emails....

function draw_message($mailbox, $iMessageNo){
    //draw messagbe stuff up here//////
    $status = imap_setflag_full ($mailbox, imap_msgno($mailbox, $iMessageNo), "\\Seen")or die(imap_last_error());
    print gettype($status)."<br />\n";
    print $status."<br />\n";
}

it prints out:
boolean
1


but the status never changes from:
[Recent]: N
[Unseen]:
[Flagged]:
[Answered]:
[Deleted]:
[Draft]:

at least now i knwo what it means, but how do i change it!!  LOL

what am i doing wrong with this function?



0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
You are passing $iMessageNo.

The imap_msgno() function takes a imap_stream (which is your $mailbox) and an UID for the message.

Not a message no.

If you know the message number, try ...

$status = imap_setflag_full ($mailbox, $iMessageNo, "\\Seen")or die(imap_last_error());


Richard.
0
 

Author Comment

by:Figment060799
Comment Utility
I guess the question then is..  whats a UID?
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 200 total points
Comment Utility
A UID is the unique identifier for the message.

I think that is the funny string of letters (which is meaningless to a person) but is used to identify a specific message.

Try ...

$status = imap_setflag_full ($mailbox, imap_uid($mailbox, $iMessageNo), "\\Seen")or die(imap_last_error());

instead.

The imap_setflag_full requires a UID not a message number.

You know the message number, so imap_uid gets the UID which you can then pass to imap_setflag_full.

Richard.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…

772 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

14 Experts available now in Live!

Get 1:1 Help Now