2018-08-07 08:14:14 +02:00
|
|
|
from helper_sql import *
|
|
|
|
|
|
|
|
|
2018-08-09 12:20:20 +02:00
|
|
|
def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, what=None, unreadOnly=False):
|
2018-08-07 08:14:14 +02:00
|
|
|
if what is not None and what != "":
|
|
|
|
what = "%" + what + "%"
|
|
|
|
else:
|
|
|
|
what = None
|
|
|
|
|
2018-08-09 12:20:20 +02:00
|
|
|
if folder == "sent":
|
|
|
|
sqlStatementBase = '''
|
|
|
|
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
|
|
|
|
FROM sent '''
|
|
|
|
else:
|
|
|
|
sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
|
|
|
|
FROM inbox '''
|
2018-08-07 08:14:14 +02:00
|
|
|
sqlStatementParts = []
|
|
|
|
sqlArguments = []
|
|
|
|
if account is not None:
|
|
|
|
if xAddress == 'both':
|
|
|
|
sqlStatementParts.append("(fromaddress = ? OR toaddress = ?)")
|
|
|
|
sqlArguments.append(account)
|
|
|
|
sqlArguments.append(account)
|
|
|
|
else:
|
|
|
|
sqlStatementParts.append(xAddress + " = ? ")
|
|
|
|
sqlArguments.append(account)
|
|
|
|
if folder is not None:
|
|
|
|
if folder == "new":
|
|
|
|
folder = "inbox"
|
|
|
|
unreadOnly = True
|
|
|
|
sqlStatementParts.append("folder = ? ")
|
|
|
|
sqlArguments.append(folder)
|
|
|
|
else:
|
|
|
|
sqlStatementParts.append("folder != ?")
|
|
|
|
sqlArguments.append("trash")
|
|
|
|
if what is not None:
|
|
|
|
sqlStatementParts.append("%s LIKE ?" % (where))
|
|
|
|
sqlArguments.append(what)
|
|
|
|
if unreadOnly:
|
|
|
|
sqlStatementParts.append("read = 0")
|
|
|
|
if len(sqlStatementParts) > 0:
|
|
|
|
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
|
|
|
|
if folder == "sent":
|
|
|
|
sqlStatementBase += " ORDER BY lastactiontime"
|
2018-08-09 12:20:20 +02:00
|
|
|
return sqlQuery(sqlStatementBase, sqlArguments)
|