Hello everyone! I’m building an app that connects to Google Apps. Users can link their Gmail accounts and view their emails through my application. Everything works perfectly when I use Google Apps email addresses, but regular Gmail accounts cause issues where the script just stops running.
Here’s the code I’m using:
$imap_client = new Zend_Mail_Storage_Imap($connection_settings);
$email_list = array();
$current_page = isset($_GET['p'])?$_GET['p']:1;
$per_page = isset($_GET['count'])?$_GET['count']:20;
$start_index = (($current_page-1)*$per_page)+1;
$final_index = ($current_page*$per_page)>$total?$total:($current_page*$per_page);
for ($x=$start_index;$x<=$final_index;$x++){
$converter = new html2text();
$converter->set_allowed_tags('<a>');
if(!$imap_client[$x])
break;
else{
$single_email = $imap_client->getMessage($x);
$single_email->id = $x;
$single_email->UID = $imap_client->getUniqueId($x);
$single_email->message_parts = array();
$single_email->content = '';
$part_counter = 1;
foreach (new RecursiveIteratorIterator($imap_client->getMessage($x)) as $index=>$message_part) {
try {
$temp_part = $message_part;
$single_email->message_parts[$part_counter] = $temp_part;
$part_counter++;
if (strtok($message_part->contentType, ';') == 'text/html') {
$html_content = $message_part->getContent();
if($message_part->contentTransferEncoding == 'quoted-printable')
$html_content = quoted_printable_decode($html_content);
$single_email->html_content = $html_content;
$converter->set_html($html_content);
$single_email->content = $converter->get_text();
}
if (strtok($message_part->contentType, ';') == 'text/plain') {
$plain_content = $message_part->getContent();
if($message_part->contentTransferEncoding == 'quoted-printable')
$plain_content = quoted_printable_decode($plain_content);
$single_email->plain_content = $plain_content;
$single_email->content = $plain_content;
}
} catch (Zend_Mail_Exception $e) {
continue;
}
}
$email_list[] = $single_email;
}
}
The weird thing is that it always stops after processing exactly 2 emails from Gmail accounts. Has anyone experienced this before?