Searching PST for messages with PersonalStorageQueryBuilder Or() not defined

I’m trying to search for messages in a PST file and apply the Or() criterion to search for both messages “from” and “to” someone.

I’ve found snippets on how to do this here:

As well as a reference to the method here:

However, when I actually try and run this (using Python), it states: AttributeError: ‘aspose.email.storage.pst.PersonalStorageQueryBuild’ object has no attribute ‘Or’

Sample code:
def extractmsg(folder, searchname, startdate, enddate):
querybuilder = PersonalStorageQueryBuilder()
querybuilder.Or(querybuilder.from_address.contains(searchname, True), querybuilder.to.contains(searchname, True))
querybuilder.sent_date.since(startdate)
querybuilder.sent_date.before(enddate)
messages = folder.get_contents(querybuilder.get_query())
print("No. of Messages with specified criterion: ", str(len(messages)))
return messages

Error:
AttributeError Traceback (most recent call last)
in
6
7 for key, value in disclosure.items():
----> 8 messages = extractmsg(folder2, key, value[0], value[1])
9 print("No. of Messages with specified criterion: ", str(len(messages)), " For: ", key)
10

in extractmsg(folder, searchname, startdate, enddate)
1 def extractmsg(folder, searchname, startdate, enddate):
2 querybuilder = PersonalStorageQueryBuilder()
----> 3 querybuilder.Or(querybuilder.from_address.contains(searchname, True), querybuilder.to.contains(searchname, True))
4 querybuilder.sent_date.since(startdate)
5 querybuilder.sent_date.before(enddate)

AttributeError: ‘aspose.email.storage.pst.PersonalStorageQueryBuild’ object has no attribute ‘Or’

Where have I gone wrong?

@PawelSzpak,

I have observed the issue shared by you. Can you please share which version of Aspose.Email you are using on your end. Can you please try using latest version on your end. In case there is still an issue then please share a working sample code reproducing the issue on your end so that we may proceed further to help you out.

I’m using version 20.2.1 on python 3.7.6.
Uploaded a dummy .py that throws this error.PST Test.zip (556 Bytes)

Alternatively, here it is

from aspose.email.storage.pst import *
from aspose.email import License
from aspose.email.tools import *

import inspect
import datetime as dt
from datetime import timedelta
import pdb
import os

license = License()
license.set_license("Aspose.Email.lic")

def extractmsg(folder, searchname, startdate, enddate):
    querybuilder = PersonalStorageQueryBuilder()
    querybuilder.Or(querybuilder.from_address.contains(searchname, True), querybuilder.to.contains(searchname, True))     
    querybuilder.sent_date.since(startdate)
    querybuilder.sent_date.before(enddate)
    messages = folder.get_contents(querybuilder.get_query())
    return messages


dataDir = os.getcwd()
extract_pst = PersonalStorage.create(dataDir + "\\test.pst", FileFormatVersion.UNICODE)
extract_pst.root_folder.add_sub_folder("Extracted")

folder = extract_pst.root_folder.get_sub_folder("Extracted")

msgs = extractmsg(folder, "test", dt.date(2004,1,1), dt.date(2016,2,4))

@PawelSzpak,

I have observed the issue shared by you and have created an issue with ID EMAILNET-39774 in our issue tracking system to further investigate the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.