note 58008 added to function.imap-body
| From: | Ortreum at osu1 dot php dot net | Date: | Fri, 21 Oct 2005 11:55:36 +0000 |
| Subject: | note 58008 added to function.imap-body | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97348@lists.php.net to get a copy of this message | ||
This is a little script to create a query for all emails-addresses that are in your mails in this
folder. So you are able to flag unreachable/wrong emailaddresses if this folder has a filter for
daemon-addresses.
It's not checking or setting the flag for 'read'.
<?php
$rootfolder = 'Returned';
$imaphost = '{imap.domain.org:143}' . $rootfolder;
$mbox = imap_open($imaphost, $imap_user, $imap_password, OP_HALFOPEN) or die("can't
connect: " . imap_last_error());
$list = imap_getmailboxes ($mbox, $imaphost, "*");
$emaillist = array();
if (is_array ($list))
{
reset ($list);
while (list($key, $val) = each($list))
{
// get folder name without root folder
$name = substr(imap_utf7_decode($val->name), strlen($imaphost));
$status = imap_status ($mbox, $imaphost . $name, SA_ALL);
if($status) {
$ilen = $status->messages;
// get every message body
for ($i = 1; $i <= $ilen; $i++)
{
// don't touch the read-flag
$message = imap_body($mbox, $i, FT_PEEK);
// lower case
$message = strtolower($message);
// clear not needed characters
$message = str_replace( "\t", " ", $message);
$message = str_replace( "\n", " ", $message);
$message = str_replace( "\r", " ", $message);
$message = str_replace( ';', " ", $message);
$message = str_replace( '"', " ", $message);
$message = str_replace( "\\", " ", $message);
$message = str_replace( "/", " ", $message);
$message = str_replace("=3d", " ", $message);
$message = str_replace( "=", " ", $message);
$message = str_replace( ":", " ", $message);
$message = str_replace( "<", " ", $message);
$message = str_replace( ">", " ", $message);
$message = str_replace( "[", " ", $message);
$message = str_replace( "]", " ", $message);
$message = str_replace( "'", " ", $message);
// get a list of all single words
$wordlist = explode(" ", $message);
$ilenword = count($wordlist);
for ($iword = 0; $iword < $ilenword; $iword++)
{
$email = $wordlist[$iword];
// has this "email" exact 1 @ ?
if (("$email" != "") && ((strlen(str_replace("@",
"", $email)) + 1) == strlen($email)))
{
// is this email in list yet?
if (array_search($email, $emaillist) . "" == "")
{
// add email
$emaillist[count($emaillist)] = $email;
}
}
}
}
}
else
{
print "imap_status failed: " . imap_last_error() . "\n";
}
}
}
else
{
print "imap_getmailboxes failed: " . imap_last_error() . "\n";
}
// create a query
$query = "UPDATE tblUsers SET US_EmailFailed = 1 WHERE US_Email IN (''";
$ilen = count($emaillist);
for ($i = 0; $i < $ilen; $i++)
{
$query .= ",'" . $emaillist[$i] . "'";
}
$query .= ")";
imap_close($mbox);
?>
Gtz ...
----
Manual Page -- http://www.php.net/manual/en/function.imap-body.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58008
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58008&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58008&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58008&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58008&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58008&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58008&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58008&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58008&report=yes
Search -- http://master.php.net/manage/user-notes.php