Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,10 @@ def imap_scan_results():
if not username:
return jsonify({"error": "Missing X-User-Username header"}), 401
limit = request.args.get("limit", default=100, type=int)
history = imap_store.get_scan_history(username, limit=limit)
return jsonify({"results": history})
page = request.args.get("page", default=1, type=int)
offset = max(0, (page - 1) * limit)
history = imap_store.get_scan_history(username, limit=limit, offset=offset)
return jsonify({"results": history, "page": page, "limit": limit})


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions backend/email_connectors/imap_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ def save_scan_results(username, scanned_emails):
conn.commit()


def get_scan_history(username, limit=100):
def get_scan_history(username, limit=100, offset=0):
with _connection() as conn:
rows = conn.execute(
"""
SELECT * FROM imap_scan_results
WHERE username = ?
ORDER BY scanned_at DESC
LIMIT ?
LIMIT ? OFFSET ?
""",
(username, limit),
(username, limit, offset),
).fetchall()
return [dict(row) for row in rows]
Loading