Skip to content

Commit

Permalink
Merge pull request #139 from modoboa/feature/sort_by_size
Browse files Browse the repository at this point in the history
Display message size and allow sorting.
  • Loading branch information
tonioo committed Jan 1, 2018
2 parents 8c3da5f + 9b67217 commit 6217463
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions modoboa_webmail/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
SORT_ORDERS = [
("date", _("Date")),
("from", _("Sender")),
("size", _("Size")),
("subject", _("Subject")),
]
31 changes: 17 additions & 14 deletions modoboa_webmail/lib/imaputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,28 +724,31 @@ def fetch(self, start, stop=None, mbox=None):
else:
submessages = [start]
mrange = start
headers = "DATE FROM TO CC SUBJECT"
query = (
"(FLAGS BODYSTRUCTURE BODY.PEEK[HEADER.FIELDS (DATE FROM TO CC "
"SUBJECT)])"
"(FLAGS BODYSTRUCTURE RFC822.SIZE BODY.PEEK[HEADER.FIELDS ({})])"
.format(headers)
)
data = self._cmd("FETCH", mrange, query)
result = []
for uid in submessages:
msg_data = data[int(uid)]
msg = email.message_from_string(
data[int(uid)]['BODY[HEADER.FIELDS (DATE FROM TO CC SUBJECT)]']
msg_data["BODY[HEADER.FIELDS ({})]".format(headers)]
)
msg['imapid'] = uid
if r'\Seen' not in data[int(uid)]['FLAGS']:
msg['style'] = 'unseen'
if r'\Answered' in data[int(uid)]['FLAGS']:
msg['answered'] = True
if r'$Forwarded' in data[int(uid)]['FLAGS']:
msg['forwarded'] = True
if r'\Flagged' in data[int(uid)]['FLAGS']:
msg['flagged'] = True
bstruct = BodyStructure(data[int(uid)]['BODYSTRUCTURE'])
msg["imapid"] = uid
msg["size"] = msg_data["RFC822.SIZE"]
if r"\Seen" not in msg_data["FLAGS"]:
msg["style"] = "unseen"
if r"\Answered" in msg_data["FLAGS"]:
msg["answered"] = True
if r"$Forwarded" in msg_data["FLAGS"]:
msg["forwarded"] = True
if r"\Flagged" in msg_data["FLAGS"]:
msg["flagged"] = True
bstruct = BodyStructure(msg_data["BODYSTRUCTURE"])
if bstruct.has_attachments():
msg['attachments'] = True
msg["attachments"] = True
result += [msg]
return result

Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/templates/modoboa_webmail/email_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
<div class="col-xs-3 col-sm-2 text-right">
{{ email.date|parse_imap_header:"date" }}
<p>{% if email.answered %}<span class="fa fa-mail-reply"></span>{% endif %}{% if email.forwarded %} <span class="fa fa-mail-forward"></span>{% endif %}{% if email.attachments %} <span class="fa fa-paperclip"></span>{% endif %}</p>
<p>{% if email.answered %}<span class="fa fa-mail-reply"></span>{% endif %}{% if email.forwarded %} <span class="fa fa-mail-forward"></span>{% endif %}{% if email.attachments %} <span class="fa fa-paperclip"></span>{% endif %} <span class="text-muted">{{ email.size|filesizeformat }}</span></p>
</div>
</div>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


BODYSTRUCTURE_SAMPLE_WITH_FLAGS = [
(b'19 (UID 19 FLAGS (\\Seen) BODYSTRUCTURE (("text" "plain" ("charset" "ISO-8859-1" "format" "flowed") NIL NIL "7bit" 2 1 NIL NIL NIL NIL)("message" "rfc822" ("name*" "ISO-8859-1\'\'%5B%49%4E%53%43%52%49%50%54%49%4F%4E%5D%20%52%E9%63%E9%70%74%69%6F%6E%20%64%65%20%76%6F%74%72%65%20%64%6F%73%73%69%65%72%20%64%27%69%6E%73%63%72%69%70%74%69%6F%6E%20%46%72%65%65%20%48%61%75%74%20%44%E9%62%69%74") NIL NIL "8bit" 3632 ("Wed, 13 Dec 2006 20:30:02 +0100" {70}', # noqa
(b'19 (UID 19 FLAGS (\\Seen) RFC822.SIZE 100000 BODYSTRUCTURE (("text" "plain" ("charset" "ISO-8859-1" "format" "flowed") NIL NIL "7bit" 2 1 NIL NIL NIL NIL)("message" "rfc822" ("name*" "ISO-8859-1\'\'%5B%49%4E%53%43%52%49%50%54%49%4F%4E%5D%20%52%E9%63%E9%70%74%69%6F%6E%20%64%65%20%76%6F%74%72%65%20%64%6F%73%73%69%65%72%20%64%27%69%6E%73%63%72%69%70%74%69%6F%6E%20%46%72%65%65%20%48%61%75%74%20%44%E9%62%69%74") NIL NIL "8bit" 3632 ("Wed, 13 Dec 2006 20:30:02 +0100" {70}', # noqa
b"[INSCRIPTION] R\xe9c\xe9ption de votre dossier d'inscription Free Haut D\xe9bit"), # noqa
(b' (("Free Haut Debit" NIL "inscription" "freetelecom.fr")) (("Free Haut Debit" NIL "inscription" "freetelecom.fr")) ((NIL NIL "hautdebit" "freetelecom.fr")) ((NIL NIL "nguyen.antoine" "wanadoo.fr")) NIL NIL NIL "<20061213193125.9DA0919AC@dgroup2-2.proxad.net>") ("text" "plain" ("charset" "iso-8859-1") NIL NIL "8bit" 1428 38 NIL ("inline" NIL) NIL NIL) 76 NIL ("inline" ("filename*" "ISO-8859-1\'\'%5B%49%4E%53%43%52%49%50%54%49%4F%4E%5D%20%52%E9%63%E9%70%74%69%6F%6E%20%64%65%20%76%6F%74%72%65%20%64%6F%73%73%69%65%72%20%64%27%69%6E%73%63%72%69%70%74%69%6F%6E%20%46%72%65%65%20%48%61%75%74%20%44%E9%62%69%74")) NIL NIL) "mixed" ("boundary" "------------040706080908000209030901") NIL NIL NIL) BODY[HEADER.FIELDS (DATE FROM TO CC SUBJECT)] {266}', # noqa
b'Date: Tue, 19 Dec 2006 19:50:13 +0100\r\nFrom: Antoine Nguyen <nguyen.antoine@wanadoo.fr>\r\nTo: Antoine Nguyen <tonio@koalabs.org>\r\nSubject: [Fwd: [INSCRIPTION] =?ISO-8859-1?Q?R=E9c=E9ption_de_votre_?=\r\n =?ISO-8859-1?Q?dossier_d=27inscription_Free_Haut_D=E9bit=5D?=\r\n\r\n'
Expand Down

0 comments on commit 6217463

Please sign in to comment.