tonioo/modoboa — pull request #6 by lddubeau (2013-08-10 23:25:14+00:00)
Title: Feature: spam score and sorting in quarantine.

This patch adds two things:

1. There is now a "Score" column in the quarantine table showing the spam score that spamassassin assigned to the message.

2. It is now possible for the user to sort on the various columns of the quarantine table. I've enabled it only for the "Date" and "Score" column but it could presumably be extended to all columns.

Regarding the changes to SQLconnector:

1. In the old implementation, the unit of measure by which `fetch()` determined its start and end was different from the unit of measure returned by `messages_count()`. For normal user, I believe the query used would make it so that the two units would correspond, but for an administrator looking at the entire quarantine it is possible for one item in what was `self.messages` would have a `qm.mail.msgrcpt_set` containing more than one item. I believe this would happen if the same spam item was sent to more than one user on the system being managed. (For instance, if the admin has set the default to 40 messages per page and it happens that in one page one message was sent to 10 users, I believe that for that page, the admin would see 9 messages over the 40 message preference.)

In the new implementation, the number returned by `messages_count()` is exactly the number of items that `fetch()` can return.

2. In the old implementation calling `fetch()` before `messages_count()` would have resulted in a crash. That's still true.

3. Although it would be possible to write a SQL query to get the data out of the database already sorted, I believe this would require bypassing Django's models (either that, or my Django-fu is lacking). I've opted to retrieve the entire data from the database in one shot and do a Python sort. I realize this may be a problem for large datasets.