Skip to content

Commit

Permalink
Merge pull request #92 from modoboa/feature/flagged_messages
Browse files Browse the repository at this point in the history
Added support for flagged messages.
  • Loading branch information
tonioo committed Aug 18, 2017
2 parents a573ac1 + b78a526 commit 5a6261a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
33 changes: 30 additions & 3 deletions modoboa_webmail/lib/imaputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def getmboxes(
return md_mailboxes

def _add_flag(self, mbox, msgset, flag):
"""Add flag(s) to a messages set
"""Add flag to a messages set.
:param mbox: the mailbox containing the messages
:param msgset: messages set (uid)
Expand All @@ -564,14 +564,23 @@ def _add_flag(self, mbox, msgset, flag):
self.select_mailbox(mbox, False)
self._cmd("STORE", msgset, "+FLAGS", flag)

def _remove_flag(self, mbox, msgset, flag):
"""Remove flag from a message set.
:param mbox: the mailbox containing the messages
:param msgset: messages set (uid)
:param flag: the flag to remove
"""
self.select_mailbox(mbox, False)
self._cmd("STORE", msgset, "-FLAGS", flag)

def mark_messages_unread(self, mbox, msgset):
"""Mark a set of messages as unread
:param mbox: the mailbox containing the messages
:param msgset: messages set (uid)
"""
self.select_mailbox(mbox, False)
self._cmd("STORE", msgset, "-FLAGS", r'(\Seen)')
self._remove_flag(mbox, msgset, r'(\Seen)')

def mark_messages_read(self, mbox, msgset):
"""Mark a set of messages as unread
Expand All @@ -581,6 +590,22 @@ def mark_messages_read(self, mbox, msgset):
"""
self._add_flag(mbox, msgset, r'(\Seen)')

def mark_messages_flagged(self, mbox, msgset):
"""Mark a set of messages as flagged.
:param mbox: the mailbox containing the messages
:param msgset: messages set (uid)
"""
self._add_flag(mbox, msgset, r'(\Flagged)')

def mark_messages_unflagged(self, mbox, msgset):
"""Mark a set of messages as unflagged.
:param mbox: the mailbox containing the messages
:param msgset: messages set (uid)
"""
self._remove_flag(mbox, msgset, r'(\Flagged)')

def msg_forwarded(self, mailbox, mailid):
self._add_flag(mailbox, mailid, '($Forwarded)')

Expand Down Expand Up @@ -720,6 +745,8 @@ def fetch(self, start, stop=None, mbox=None):
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'])
if bstruct.has_attachments():
msg['attachments'] = True
Expand Down
5 changes: 5 additions & 0 deletions modoboa_webmail/static/modoboa_webmail/css/webmail.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@
padding-top: 10px;
}

.flag {
cursor: pointer;
margin-left: 10px;
}

div.email:hover {
background-color: #f5f5f5;
}
Expand Down
32 changes: 31 additions & 1 deletion modoboa_webmail/static/modoboa_webmail/js/webmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Webmail.prototype = {
$document.on("click", "a[name=removembox]", $.proxy(this.remove_mbox, this));

$document.on("click", "div.openable", $.proxy(this.viewmail_loader, this));
$document.on('click', 'span.flag', $.proxy(this.toggleFlaggedStatus, this));

$document.on("click", "a[name=reply]", $.proxy(this.reply_loader, this));
$document.on("click", "a[name=replyall]", $.proxy(this.reply_loader, this));
Expand Down Expand Up @@ -933,6 +934,29 @@ Webmail.prototype = {
}).done($.proxy(this.toggleJunkStateCallback, this));
},

toggleFlaggedStatus: function(evt) {
var $target = get_target(evt);
var url, status, oldClass, newClass;

if ($target.hasClass('fa-star-o')) {
url = $('a[name=mark-flagged').attr('href');
status = 'flagged';
newClass = 'fa-star';
oldClass = 'fa-star-o';
} else {
url = $('a[name=mark-unflagged').attr('href');
status = 'unflagged';
newClass = 'fa-star-o';
oldClass = 'fa-star';
}
$.ajax({
url: url,
data: 'ids=' + $target.parents('div.email').attr('id')
}).done($.proxy(function(data) {
$target.removeClass(oldClass).addClass(newClass);
}, this));
},

display_mode: function(e, value) {
e.preventDefault();
this.navobject.setparam("links", value).update();
Expand Down Expand Up @@ -1199,8 +1223,14 @@ Webmail.prototype = {
mark_callback: function(data) {
if (data.action === "read") {
this.htmltable.current_selection().removeClass("unseen");
} else {
} else if (data.action == "unread") {
this.htmltable.current_selection().addClass("unseen");
} else if (data.action == "flagged") {
this.htmltable.current_selection().find(".flag")
.removeClass("fa-star-o").addClass("fa-star");
} else {
this.htmltable.current_selection().find(".flag")
.removeClass("fa-star").addClass("fa-star-o");
}
if (data.unseen !== undefined && data.mbox) {
this.set_unseen_messages(data.mbox, data.unseen);
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 @@ -7,8 +7,8 @@
<div id="{{ email.imapid }}" class="row email{% if email.style %} {{ email.style }}{% endif %}" data-page="{{ page }}">
<div class="hidden-xs col-sm-1">
<img name="drag" src="{% static 'pics/grippy.png' %}" class="draggable" />

<input type="checkbox" />
<span class="flag fa fa-lg {% if email.flagged %}fa-star{% else %}fa-star-o{% endif %}"></span>
</div>
<div class="col-xs-9 col-sm-9 openable">
{{ email.subject|parse_imap_header:"subject" }}
Expand Down
10 changes: 10 additions & 0 deletions modoboa_webmail/templatetags/webmail_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ def listmailbox_menu(selection, folder, user):
"label": _("Mark as unread"),
"url": u"{0}?status=unread".format(
reverse("modoboa_webmail:mail_mark", args=[folder]))
}, {
"name": "mark-flagged",
"label": _("Mark as flagged"),
"url": u"{0}?status=flagged".format(
reverse("modoboa_webmail:mail_mark", args=[folder]))
}, {
"name": "mark-unflagged",
"label": _("Mark as unflagged"),
"url": u"{0}?status=unflagged".format(
reverse("modoboa_webmail:mail_mark", args=[folder]))
}]
}]
if folder == user.parameters.get_value("trash_folder"):
Expand Down

0 comments on commit 5a6261a

Please sign in to comment.