summaryrefslogtreecommitdiff
path: root/src/jwebmail/webmail.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/jwebmail/webmail.py')
-rw-r--r--src/jwebmail/webmail.py105
1 files changed, 62 insertions, 43 deletions
diff --git a/src/jwebmail/webmail.py b/src/jwebmail/webmail.py
index 99cc542..1b14af0 100644
--- a/src/jwebmail/webmail.py
+++ b/src/jwebmail/webmail.py
@@ -14,7 +14,6 @@ from urllib.parse import urlparse
from flask import abort, current_app, flash, redirect, render_template, request, url_for
from flask_babel import gettext, lazy_gettext
from flask_login import current_user, logout_user
-from flask_paginate import Pagination, get_page_parameter, get_per_page_parameter
from flask_wtf import FlaskForm
from werkzeug.utils import secure_filename
from wtforms import (
@@ -80,14 +79,10 @@ def logout():
def about():
- view_model = {
- "scriptadmin": current_app.config["JWEBMAIL"]["ADMIN_MAIL"],
- "http_host": request.host,
- "request_uri": request.full_path,
- "remote_addr": request.remote_addr,
- "languages": current_app.extensions["babel"].instance.list_translations(),
- }
- return render_template("about.html", **view_model)
+ return render_template(
+ "about.html",
+ languages=current_app.extensions["babel"].instance.list_translations(),
+ )
def displayheaders(folder=""):
@@ -96,6 +91,9 @@ def displayheaders(folder=""):
if folder and folder not in folders:
return render_template("error", error="no_folder", links=folders), 404
+ page_bound = request.args.get("page_bound")
+ page_after = bool(request.args.get("page_after", type=int, default=True))
+ per_page = request.args.get("per_page", type=int, default=25)
sort = request.args.get("sort", "!date")
search = request.args.get("search")
@@ -105,41 +103,58 @@ def displayheaders(folder=""):
count = get_read_mails_logged_in().count(folder)
- page = request.args.get(get_page_parameter(), type=int, default=1)
- per_page = request.args.get(get_per_page_parameter(), type=int, default=25)
-
- pgn = Pagination(
- page=page,
- per_page=per_page,
- total=count["total_mails"],
- record_name="mails",
- css_framework="bulma",
- display_msg=gettext(
- "displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name}"
- ),
- inner_window=1,
- outer_window=0,
+ headers, first, last = get_read_mails_logged_in().list_search(
+ folder=folder,
+ bound=page_bound,
+ after=page_after,
+ limit=per_page,
+ sort=sort,
+ search=search,
)
- if search:
- headers = get_read_mails_logged_in().search(search, folder)
+ if headers:
+ match s:
+ case "date":
+ page_bound_after = (
+ headers[-1]["date_received"] + "_" + headers[-1]["message_handle"]
+ )
+ page_bound_before = (
+ headers[0]["date_received"] + "_" + headers[0]["message_handle"]
+ )
+ case "size":
+ page_bound_after = (
+ str(headers[-1]["byte_size"]) + "_" + headers[-1]["message_handle"]
+ )
+ page_bound_before = (
+ str(headers[0]["byte_size"]) + "_" + headers[0]["message_handle"]
+ )
+ case "sender":
+ page_bound_after = (
+ headers[-1]["head"]["from"][0]["address"]
+ + "_"
+ + headers[-1]["message_handle"]
+ )
+ page_bound_before = (
+ headers[0]["head"]["from"][0]["address"]
+ + "_"
+ + headers[0]["message_handle"]
+ )
else:
- headers = get_read_mails_logged_in().read_headers_for(
- folder=folder,
- start=(pgn.page - 1) * pgn.per_page,
- end=(pgn.page - 1) * pgn.per_page + pgn.per_page,
- sort=sort,
- )
-
- vals = {
- "folder": folder,
- "pgn": pgn,
- "msgs": headers,
- "mail_folders": folders,
- "total_size": count["byte_size"],
- "total_new_mails": count["unread_mails"],
- }
- return render_template("displayheaders.html", **vals)
+ page_bound_after = None
+ page_bound_before = None
+
+ return render_template(
+ "displayheaders.html",
+ first=first,
+ last=last,
+ page_bound_after=page_bound_after,
+ page_bound_before=page_bound_before,
+ msgs=headers,
+ mail_folders=folders,
+ total_mails=count["total_mails"],
+ total_size=count["byte_size"],
+ total_new_mails=count["unread_mails"],
+ )
def readmail(msgid, folder=""):
@@ -190,10 +205,14 @@ def _take_common_req_args(mapping):
res = dict()
if mapping.get("sort"):
res["sort"] = mapping["sort"]
+ if mapping.get("search"):
+ res["search"] = mapping["search"]
if mapping.get("per_page"):
res["per_page"] = mapping["per_page"]
- if mapping.get("page"):
- res["page"] = mapping["page"]
+ if mapping.get("page_bound"):
+ res["page_bound"] = mapping["page_bound"]
+ if mapping.get("after_page"):
+ res["after_page"] = mapping["after_page"]
return res