Case insensitive email searching

Hello,
I built some email searching routine, and I would like to know if it’s possible to implement a case insensitive email subject search.
Thanks

@kelberuc1

Can you please elaborate your requirements in detail. As far as I have understood your requirements, if you have all emails fetched locally and then you have control over that to search for particular email subject either via upper case or lower case.

Hi @mudassir.fayyaz,

I would like to search for the word ‘door’ in email subject from a PST file, and get the following results:

  • mails with subject ‘door’;
  • mails with subject ‘Door’;
  • mails with subject ‘DOOR’.

This is what I mean with case-insensitive search.

Thanks for your help

@kelberuc1

In case of PST file search, I suggest you to please visit this documentation link for your kind reference. You can set the criteria as per your convenience.

@mudassir.fayyaz,
Thanks for your reply, but I forgot to mention that I’m using a query string like the code below:

MailQuery query = new MailQuery("‘Subject’ Contains ‘test’");
MessageInfoCollection messages = targetFolder.getContents(query);

How can add the ignore case parameter in this routine?

Thanks

@kelberuc1

We are checking on our end and will share the feedback with you as soon as possible.

@kelberuc1

I suggest you to please visit this documentation link where we have shared the example for case insensitive search. You have to set the bool value True for case insensitive search.

@mudassir.fayyaz,

I didn’t know if I made myself clear on last messages, but let me try again…
I’m not using PersonalStorageQueryBuilder() function to do the search, and I can’t use it. How can I do a case insensitive search using the procedure below:

MailQuery query = new MailQuery("‘Subject’ Contains ‘test’");
// need a way to set ignore case parameter on query
// …
MessageInfoCollection messages = targetFolder.getContents(query);

Thanks

@kelberuc1

Please use the following example on your end that performs case insensitive parameter.

	public static void TestQuery()
    {
		File.Delete("CaseSensitivity.pst");
		using (PersonalStorage personalStorage = PersonalStorage.Create("CaseSensitivity.pst", FileFormatVersion.Unicode))
		{
			FolderInfo folderinfo = personalStorage.CreatePredefinedFolder("Inbox", StandardIpmFolder.Inbox);
			folderinfo.AddMessage(MapiMessage.FromMailMessage(MailMessage.Load("Sample.eml")));
			PersonalStorageQueryBuilder builder = new PersonalStorageQueryBuilder();
			// IgnoreCase is True
			builder.From.Contains("AutoMated", true);
			builder.Bcc.Contains("AutoMated", true);
			builder.Body.Contains("AutoMated", true);
			builder.Subject.Contains("AutoMated", true);

			MailQuery query = builder.GetQuery();
			MessageInfoCollection coll = folderinfo.GetContents(query);
			Console.WriteLine(coll.Count);
		}
	}

@mudassir.fayyaz,

Using your code, where can I put the query string input into the query?
"'Subject' contains 'Test'";

Please remember that I can’t do this:
builder.Subject.Contains("Test");

I need to input the query string because it is generated on the fly for my application, I don’t have any predefined field for the query in order to use PersonalQueryString().

Thanks

@kelberuc1

Can you please consider using following. If this is some thing, you are looking the API to serve you.

MailQuery query = new MailQuery("‘Subject’ Contains[IgnoreCase=True] ‘test’");

1 Like

Hi @mudassir.fayyaz,

This is the solution I have been searching for.
It worked perfectly now.
Thanks for you help!

@kelberuc1

It’s good to know that suggested option worked on your end.