Filter in attachment

Hi,

I wanted to search in attachment like name, body or extension.

Is there any function or class by which i will search in attachment because i already tried MailQueryBuilder in which there is no method for attachment.

@StellarDeveloper,

Could you please elaborate your requirements a little more? Please give us an example for what you want to achieve using the API. If you have some sample message file for reference, please share that with us as well.

@kashif.iqbal

I wanted to filter mails according to the attachment fields.

Like when i am using MAPI function for filter it gives option to search for mails having attachment name “Sample.txt” or mails having attachment extension “.pdf” or mails having attachment size greater than 10KB.
Here is the sample code in MAPI

For Extension
IRestrictionSub Restr =resor.Add(RES_SUBRESTRICTION);
Restr.SetUlSubObject(PR_MESSAGE_ATTACHMENTS);

RestrAtt =Restr.SetKind(RES_CONTENT);
RestrAtt.SetUlFuzzyLevel(FL_SUBSTRING | FL_IGNORECASE);
RestrAtt.SetUlPropTag (PR_ATTACH_EXTENSION);
RestrAtt.SetLpProp(varattachExt);

for attchment name
RestrAtt.SetUlPropTag (PR_ATTACH_FILENAME);

for attachment size
Restr =resor.Add(RES_SUBRESTRICTION);
Restr.SetUlSubObject(PR_MESSAGE_ATTACHMENTS);
ressize=Restr.SetKind(RES_SIZE);
ressize.SetUlPropTag(PR_ATTACH_DATA_BIN);
ressize.SetRelop(condition);
ressize.SetCb(value*1024);

By this we can filter mail according to the attachment name, extension and size but there is not such kind of option in your API.
Check this link for more : MAPITable Redemption Object

Also, filter in body of a mail is not working properly. Every time i apply filter on body it gives result 0.
Here is the sample code i used in my code

ExchangeQueryBuilder exchQuery = new ExchangeQueryBuilder();
MailQuery queryBody = null;
exchQuery.Body.Contains(strBody,true);
queryBody = exchQuery.GetQuery();
ExchangeMessageInfoCollection exchMsgInfoCol = exchClientBase.ListMessages(exchClientBase.MailboxInfo.RootUri, queryBody);

My another query is,
GetMailboxSize() is not working properly. It gives us wrong size of mailbox.

IEWSClient exchClientBase;
ExchangeMailboxInfo exchMailboxInfo = exchClientBase.GetMailboxInfo();
long iMailboxSize = exchClientBase.GetMailboxSize();

@StellarDeveloper,

The follwoing code sample seems to be what you want w.r.t Attachment file name, extension or size. However, we couldn’t find a working version of it. We’re looking into it and will update you with our findings once we are able to figure out the issue.

IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/EWS/Exchange.asmx", "UserTwo@Aspose2018.onmicrosoft.com", "Aspose1234");

var queryBuilder = new ExchangeQueryBuilder();
queryBuilder.ExtendedProperties[KnownPropertyList.AttachExtension].AsString.Contains("jpg", true);
var query = queryBuilder.GetQuery();
string[] uriList = client.ListItems(client.MailboxInfo.InboxUri, query);
Console.WriteLine(uriList.Count());

For your queries related to searching by message body, please change this line of code:

exchClientBase.ListMessages(exchClientBase.MailboxInfo.RootUri, queryBody);

to

exchClientBase.ListMessages(exchClientBase.MailboxInfo.InboxUri, queryBody);

The GetMailboxSize() is working fine with the above shared account and you can test it at your end as well.

3 posts were split to a new topic: Issues while taking backup of folders from account on exchange

@kashif.iqbal

Any update on applying filter in attachment?

@StellarDeveloper,

We won’t be able to provide such functionality as the same is not available in the EWS itself.