looping is making my mind loop...
| From: | Remco Rijnders | Date: | Wed, 01 Nov 2000 13:44:05 +0000 |
| Subject: | looping is making my mind loop... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-23150@lists.php.net to get a copy of this message | ||
Hello all,
I am working on a script that allows a PHP script to scan a standard
mailbox format and display the individual messages to the user. At
first, when the user has not selected a particular email the scripts
present the subject lines of all emails as a link for them to click
on. When clicking this link the user is presented with the body of
said email, with the headers etc. snipped.
Now, the problem is I got this working for most situations, but
sometimes, the code display not just the selected email but also the
one following it. I am stumped as to why it would do this
(consistently) with some emails, but not with all of them.
The problem occurs in the following snippet of code:
--------------------------------------------------
$logbody = fopen("content/episodes/$episode", "r");
while (!feof ($logbody)) {
$buffer = fgets ($logbody, 9192);
if (ereg(quotemeta($log), $buffer)) { ## This is the log we want
while ($buffer != "\n") ## Skip past all headers
$buffer = fgets ($logbody, 9192);
print "<PRE>\n";
while ((!ereg('^From ', $buffer)) && (!feof ($logbody))) { ## Print the log
print $buffer;
$buffer = fgets ($logbody, 9192);
}
print "</PRE>\n";
}
}
fclose ($logbody);
--------------------------------------------------
When feeding it the following input it goes wrong:
--------------------------------------------------
From remmy@lissa.pair.com Mon Oct 2 18:28:35 2000
Return-Path: <remmy@lissa.pair.com>
Received: from pop3.cistron.nl
by localhost with POP3 (fetchmail-5.3.3)
for remmy@localhost (single-drop); Mon, 02 Oct 2000 18:28:34 +0200 (CEST)
Received: from lissa.pair.com (lissa.pair.com [209.68.1.153])
by janeway.cistron.net (8.9.3/8.9.3/Debian 8.9.3-6) with ESMTP id SAA01023
for <remmy@cistron.nl>; Mon, 2 Oct 2000 18:28:28 +0200
<snip lots of headers>
<snip lots of body of email #1, the one we want to display>
http://uss-centauris.org/
ICQ: 760542
From remmy@lissa.pair.com Tue Oct 3 03:37:00 2000
Return-Path: <remmy@lissa.pair.com>
Received: from pop3.cistron.nl
by localhost with POP3 (fetchmail-5.3.3)
for remmy@localhost (single-drop); Tue, 03 Oct 2000 03:36:59 +0200 (CEST)
Received: from lissa.pair.com (lissa.pair.com [209.68.1.153])
by janeway.cistron.net (8.9.3/8.9.3/Debian 8.9.3-6) with ESMTP id DAA31444
<snip rest of 2nd email headers and body>
--------------------------------------------------
If I understand my own ugly code correctly, it should exit the loop
and printing of the email as soon as it encounters the second email
which starts with the header with "From ". It doesn't. The odd thing
is, that it does stop displaying after this second email, even when
there is a multitude of other emails still remaining in the opened file.
I am puzzled, but perhaps one of you can offer me some insight as to
where it goes wrong?
Thanks!
--
Remco Rijnders, ICQ: 760542 | Linux adanidas 2.2.16 is up 26 days, 4:20
http://uss-centauris.org/ | Reporter: Mr Gandhi, what do
you think of
Phone: (+31) 70 3467809 | Western Civilization?
Cellular: (+31) 6 22091723 | Gandhi: I think it would be a good idea.