473,888 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IMAP PHP - Reading contents of 200+ emails

Hi There,

I am looping through and reading the body contents of a mail box with
over 200 emails in it. The script is running very slow and timing out
after 180 seconds, only getting through about 180 of these emails. Is
there anyway I can increase the speed of this script? Why is it taking
so long to loop through all these emails? Code is below:

if($mailbox= imap_open( "{###.###.#.### :143/imap}mail_box", $a, $b))
{
set_time_limit( 180);
$check = imap_check($mai lbox);
$message_count = imap_num_msg($m ailbox);

for ($i=1;$i<=10;$i ++)
{

$header = imap_header($ma ilbox,$i);
$body = imap_body($mail box,$i);
$message = imap_fetchbody( $mailbox,$i,1);

$strpos = strripos($messa ge,"textfield3" );
$prettydate = date("jS F Y", $header->udate);

echo $prettydate." - ".substr($messa ge, $strpos+13, 8)."<br/>";

}

imap_close($mai lbox);
}
else echo "no connection";

Jul 2 '07 #1
4 4280
On Jul 2, 6:28 pm, shmic...@gmail. com wrote:
Hi There,

I am looping through and reading the body contents of a mail box with
over 200 emails in it. The script is running very slow and timing out
after 180 seconds, only getting through about 180 of these emails. Is
there anyway I can increase the speed of this script? Why is it taking
so long to loop through all these emails? Code is below:
Probably most of the delay is network latency. How fast is your
connection?
>
if($mailbox= imap_open( "{###.###.#.### :143/imap}mail_box", $a, $b))
{
set_time_limit( 180);
$check = imap_check($mai lbox);
$message_count = imap_num_msg($m ailbox);

for ($i=1;$i<=10;$i ++)
{

$header = imap_header($ma ilbox,$i);
$body = imap_body($mail box,$i);
$message = imap_fetchbody( $mailbox,$i,1);

$strpos = strripos($messa ge,"textfield3" );
$prettydate = date("jS F Y", $header->udate);

echo $prettydate." - ".substr($messa ge, $strpos+13, 8)."<br/>";

}

imap_close($mai lbox);}

else echo "no connection";

Jul 3 '07 #2
On Jul 3, 11:43 am, Benjamin <musiccomposit. ..@gmail.comwro te:
On Jul 2, 6:28 pm, shmic...@gmail. com wrote:Hi There,
I am looping through and reading the body contents of a mail box with
over 200 emails in it. The script is running very slow and timing out
after 180 seconds, only getting through about 180 of these emails. Is
there anyway I can increase the speed of this script? Why is it taking
so long to loop through all these emails? Code is below:

Probably most of the delay is network latency. How fast is your
connection?
We have an internal gigabit connection, so I don't think that will be
a problem...

Jul 3 '07 #3

<sh******@gmail .comwrote in message
news:11******** *************@o 11g2000prd.goog legroups.com...
Hi There,

I am looping through and reading the body contents of a mail box with
over 200 emails in it. The script is running very slow and timing out
after 180 seconds, only getting through about 180 of these emails. Is
there anyway I can increase the speed of this script? Why is it taking
so long to loop through all these emails? Code is below:

if($mailbox= imap_open( "{###.###.#.### :143/imap}mail_box", $a, $b))
{
set_time_limit( 180);
$check = imap_check($mai lbox);
$message_count = imap_num_msg($m ailbox);

for ($i=1;$i<=10;$i ++)
{

$header = imap_header($ma ilbox,$i);
$body = imap_body($mail box,$i);
$message = imap_fetchbody( $mailbox,$i,1);

$strpos = strripos($messa ge,"textfield3" );
$prettydate = date("jS F Y", $header->udate);

echo $prettydate." - ".substr($messa ge, $strpos+13, 8)."<br/>";

}

imap_close($mai lbox);
}
else echo "no connection";
Hi NoName,

I would open the connection, read all needed info, close the connection and
only then do the processing.

Other things:
How long does the script take if you only read headers and nothing else?
(Try to simplify the script to narrow down the problem)
Why are you reading the message body twice? (First the full body, and then
the first body section?)
How big are the messages?
This is not the real script, is it? (Or is there some reason you do only 10
messages that I dont see?)

Richard.
Jul 3 '07 #4
On Jul 4, 8:54 am, "Richard" <root@localhost wrote:
<shmic...@gmail .comwrote in message

news:11******** *************@o 11g2000prd.goog legroups.com...


Hi There,
I am looping through and reading the body contents of a mail box with
over 200 emails in it. The script is running very slow and timing out
after 180 seconds, only getting through about 180 of these emails. Is
there anyway I can increase the speed of this script? Why is it taking
so long to loop through all these emails? Code is below:
if($mailbox= imap_open( "{###.###.#.### :143/imap}mail_box", $a, $b))
{
set_time_limit( 180);
$check = imap_check($mai lbox);
$message_count = imap_num_msg($m ailbox);
for ($i=1;$i<=10;$i ++)
{
$header = imap_header($ma ilbox,$i);
$body = imap_body($mail box,$i);
$message = imap_fetchbody( $mailbox,$i,1);
$strpos = strripos($messa ge,"textfield3" );
$prettydate = date("jS F Y", $header->udate);
echo $prettydate." - ".substr($messa ge, $strpos+13, 8)."<br/>";
}
imap_close($mai lbox);
}
else echo "no connection";

Hi NoName,

I would open the connection, read all needed info, close the connection and
only then do the processing.

Other things:
How long does the script take if you only read headers and nothing else?
(Try to simplify the script to narrow down the problem)
Why are you reading the message body twice? (First the full body, and then
the first body section?)
How big are the messages?
This is not the real script, is it? (Or is there some reason you do only 10
messages that I dont see?)

Richard.- Hide quoted text -

- Show quoted text -
The real script does the whole $message_count which is up to over 300
now. We are expecting about 500. The emails are about 20k each and
just have user submitted form data. I am reading out a userid value so
we have a collection of all people which have entered a survey.

Ahh, forgot to comment out the previous body line. I found I could
access specific body information with only imap_fetchbody. I will run
some more tests and see how I go.

Jul 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4404
by: Joachim Smit | last post by:
Is it possible to extract the email-body from a IMAP-mail-file ? The function 'imap_body()' expects that I'm connected to an IMAP-server, but I'm not. I just have the file. So I'm looking for a possiblity to use imap_body and give the name of the file as a parameter. Thanks in advance.
0
1390
by: gj | last post by:
If anyone has worked with this I would be interested to find out. I have successfully put send/receive emails into an application using SMTP/POP server but would like to do something more professional with IMAP. I basically want a full email client in Access that can connect to an IMAP server. I have played with a few ActiveX controls but would like others experiences. TIA
2
2112
by: Thief_ | last post by:
I need to monitor POP3 & IMAP servers for new emails. Ideally my app needs to sit in the system tray. Has anyone done this before? -- | +-- Thief_ | VB.NET 2003
5
4532
by: Kun | last post by:
Hey guys, I would like to have a code in python (as simple as possible) to scan a specific folder in my mailbox and if the subject is equal to, say, 'BIKES', I would like to have the code automatically send the SENDER an email saying something like "We have received your Email". Furthermore, I would also like to somehow save the sender's email into a list which would be compiled by another python program into an html file that would show a...
0
1339
by: Stephen G | last post by:
Hi there. I have been receiving MemoryErrors using the Windows version of Python 2.5. The script I have written times the sending and the reception of emails with various attachments. I get many exceptions when using the IMAP downloads. This happens randomly; sometimes the file downloads OK, and other times no. Using an exception and traceback function, I can see the following... MemoryError <no args> File "C:\Documents and...
0
833
by: ppp86 | last post by:
Hey, I am writing small library to IMAP protocol. I wonder how to receive e-mails without attachments? I was reading it http://www.bobpeers.com/technical/telnet_imap and chapter in RFC about FETCH Command. But I can receive emails only with attachments or only with plain text. I have seen packages from thunderbird. They receive BODYSTRUCTURE and then they fetch useful part with part specifiers(1.1.MIME etc). Unfortunatelly I dont...
1
2229
by: nitinpatel1117 | last post by:
Hi, i'm using php's imap extension to read emails from a mailbox. My php script has been working fine and i'm pretty sure that there is nothing wrong with it. here is extracts from my code $mbox = imap_open ($host, $login, $password) or die("can't connect: " . imap_last_error()); $message_count = imap_num_msg($mbox);
1
6201
by: redbrad0 | last post by:
I have some emails that I connect into IMAP that I need to forward. I have searched the internet and can not find any examples of how to do this. Can someone help me with code on how to forward a email using IMAP? Below is some code that I tried imap_mail('no@email.com', 'Forward Message', imap_body($mailbox, $emailIndex), 'From: no@email.com'); Info taken from http://us3.php.net/manual/en/function.imap-mail.php
1
1279
by: kathiresan | last post by:
Hi I'm trying a windows service that fetches the contents of the mails from my inbox and saves them in a database using IMAP protocol. I've fetched the contents of the mail body using the IMAP command "1 UID FETCH 756 BODY\r\n", where 756 is message UID. How can I fetch the attachments so that i can save the attachments in a specific location and i can use them later. I've tried a lot to find this but i couldn't get. Few articles gave me...
0
9957
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10772
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10434
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7988
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7143
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5810
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4635
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.