+1 vote

Hi,

I want to search multiple email address like this

Dim arr() As String = {"email@test.com", "email2@test.com", "email3@test.com"}
Dim uids As List(Of Long) = imap.Search().Where(Expression.[And](Expression.To(arr), Expression.HasFlag(Flag.All)))

the address in the array is dynamic not fixed no. of emails

could you please help me with the code

by

1 Answer

+1 vote

You need to use Expression.And -or- Expression.Or.

For Expresion.And you can use following code:

List<string> addresses = new List<string> {
    "one@example", 
    "other@example.com"
};

ICriterion expresion = Expression.And(
    addresses.ConvertAll(Expression.From).ToArray());

For Expresion.Or you can use following code:

List<string> addresses = new List<string> {
    "one@example", 
    "other@example.com",
    "and.another@example.com"
};

ICriterion expresion = Expression.Or(
    Expression.From(addresses[0]), 
    Expression.From(addresses[1])); 

for (int i = 2; i < addresses.Count; i++)
{
    expresion = Expression.Or(
        expresion, 
        Expression.From(addresses[i]));
}

... and regular Imap.Search method:

List<long> uids = client.Search(expresion);
by (297k points)
but if i use the above code it throwing error in VB.NET

 Dim expresion As ICriterion = Expression.And(addresses.ConvertAll(Expression.From).ToArray)

BC30455: Argument not specified for parameter 'from' of 'Public Shared Function From(from As String) As Limilabs.Client.IMAP.ICriterion'.

if possible please provide vb.net code and the last one i need to search these list of emails in all FROM, TO, CC

Thanks
This is the VB compiler error, your VB code is invalid.

Use AddressOf:
addresses.ConvertAll(AddressOf Expression.From)
...