473,480 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help: questions about query structure in imap_search

Hi,

I'm maintaing a website for a group and we have several email addresses
feeding into one inbox, so I want to find a way of finding all the
emails that were sent to a particular address either via "TO" or "CC"
(not interested in "BCC")

imap_search seems to be the solution, but there are several issues.
1. I can get imap_search($conn, "TO test_address"); to work, and
imap_search($conn, "CC test_address");, but not a combined 'OR' search
to grab the "TO" and "CC" together.
2. so using 2 searches and trying to merger the results, the issue is
that while the search returns false if no messages are found, the
returned arrays are not empty, and doing an "array_merge" results in an
array of size 2, even when no results found.
I've ended up with this rather unsatisfying piece of code, it works,
but it looks like a cludge.

<code snippet>
# now lets try searching for TO and CC emails! merge arrays,
$emailSearch1= imap_search($conn, "TO test_address");
$emailSearch2= imap_search($conn, "CC test_address");

# attempt to merge arrays
$emailSearch= array_merge ($emailSearch1, $emailSearch2);

# if one array is 'empty', just assign the other array to be the search
result
if($emailSearch1 == false) $emailSearch=$emailSearch2;
if($emailSearch2 == false) $emailSearch=$emailSearch1;

$numEmails = sizeof($emailSearch);
if($emailSearch == false) $numEmails=0;
Can any of you experts recommend a better way of performing the
imap_search and merging the results?

Thanks in advance.

Chris

Jan 20 '06 #1
2 2051
ch**************@hotmail.com wrote:


I've ended up with this rather unsatisfying piece of code, it works,
but it looks like a cludge.

I've seen worse.
<code snippet>
# now lets try searching for TO and CC emails! merge arrays,
$emailSearch1= imap_search($conn, "TO test_address");
$emailSearch2= imap_search($conn, "CC test_address");

# attempt to merge arrays
$emailSearch= array_merge ($emailSearch1, $emailSearch2);

# if one array is 'empty', just assign the other array to be the search
result
if($emailSearch1 == false) $emailSearch=$emailSearch2;
if($emailSearch2 == false) $emailSearch=$emailSearch1;

$results=array();
foreach(array('TO test_address','CC test address') as $iqry) {
if ($false !== ($sub = imap_search($conn, $iqry))) {
$results = array_merge($results, $sub);
}
}

....strikes me as more elegant - but less transparent. Also your code will
leave 'false' in the result when both queries fail, whereas my code returns
an empty array.

C.
Jan 20 '06 #2
Thank you,
that is a lot neater way of merging the arrays.

much appreciated.

Chris.

Jan 20 '06 #3

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

Similar topics

2
1640
by: Alexandre MELARD | last post by:
Hi, My name is alexandre, I am 4th year student at the Napier university of edinburgh. I am finishing my year and do a presentation of my honours project next wednesday (the 5th of May). I am...
9
2714
by: cwwilly | last post by:
Thank you for taking the time to look at my question. Any help would be much appreciated ! Database: Microsoft SQL Server 2000 Database Structure: 1. tblEmployee a. EmployeeID
6
2411
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
4
1766
by: Bob Alston | last post by:
Some more, rather specific Access performance questions. IN a split front-end & back-end Access/Jet ONLY LAN situation, and with all query criteria fields and join fields indexed: 1. Is is...
19
2045
by: Mark Richards | last post by:
I've been programming for many years, but have only recently taken a deep "C" dive (bad pun, i know) and need a lot of explanation from an expert. My questions center around those mysterious...
13
3682
by: Chua Wen Ching | last post by:
Hi there, I saw this article here in vb.net. http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/148992_Thread.aspx and ...
9
3057
by: Patrick.O.Ige | last post by:
I have a code below and its a PIE & BAR CHART. The values now are all static but I want to be able to pull the values from a database. Can you guys give me some ideas to do this? Thanks ...
2
2221
by: cryon.b | last post by:
Hi To All, I took up the IBM sample testfor Exam 700 today and I have the test tomorrow,I have some questions for which Iam not sure about the right answer,can anyone please guide me as to what is...
0
5517
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
7044
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,...
0
7045
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6944
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...
0
5341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4782
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...
0
4483
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...
0
2995
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...
0
182
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...

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.