Solved

Email Retrieval: Status and speed issues

Posted on 2002-06-10
5
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7069417
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
ID: 7109648
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:Richard Quadling
ID: 7110061
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
ID: 7188727
I guess the question then is..  whats a UID?
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 200 total points
ID: 7189110
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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