Solved

Email Retrieval: Status and speed issues

Posted on 2002-06-10
5
349 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
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:RQuadling
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:
RQuadling 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

932 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

10 Experts available now in Live!

Get 1:1 Help Now