Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

Email Retrieval: Status and speed issues

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
Figment060799
Asked:
Figment060799
  • 3
  • 2
1 Solution
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
Figment060799Author Commented:
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
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
Figment060799Author Commented:
I guess the question then is..  whats a UID?
0
 
Richard QuadlingSenior Software DeveloperCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now